Skip to content

Commit 0a093fd

Browse files
committed
Add more functions to whitelist
1 parent 6c61feb commit 0a093fd

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/cases_generator/flags.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import parsing
66
from typing import AbstractSet
77

8-
WHITELIST = (
8+
NON_ESCAPING_FUNCTIONS = (
99
"Py_INCREF",
1010
"_PyDictOrValues_IsValues",
1111
"_PyObject_DictOrValuesPointer",
@@ -39,9 +39,20 @@
3939
"Py_NewRef",
4040
"_PyList_ITEMS",
4141
"_PyTuple_ITEMS",
42+
"_PyList_AppendTakeRef",
43+
"_Py_atomic_load_uintptr_relaxed",
44+
"_PyFrame_GetCode",
4245
)
4346

47+
ESCAPING_FUNCTIONS = (
48+
"import_name",
49+
"import_from",
50+
)
51+
52+
4453
def makes_escaping_api_call(instr: parsing.Node) -> bool:
54+
if "CALL_INTRINSIC" in instr.name:
55+
return True;
4556
tkns = iter(instr.tokens)
4657
for tkn in tkns:
4758
if tkn.kind != lx.IDENTIFIER:
@@ -52,6 +63,8 @@ def makes_escaping_api_call(instr: parsing.Node) -> bool:
5263
return False
5364
if next_tkn.kind != lx.LPAREN:
5465
continue
66+
if tkn.text in ESCAPING_FUNCTIONS:
67+
return True
5568
if not tkn.text.startswith("Py") and not tkn.text.startswith("_Py"):
5669
continue
5770
if tkn.text.endswith("Check"):
@@ -60,7 +73,7 @@ def makes_escaping_api_call(instr: parsing.Node) -> bool:
6073
continue
6174
if tkn.text.endswith("CheckExact"):
6275
continue
63-
if tkn.text in WHITELIST:
76+
if tkn.text in NON_ESCAPING_FUNCTIONS:
6477
continue
6578
return True
6679
return False
@@ -111,8 +124,7 @@ def fromInstruction(instr: parsing.Node) -> "InstructionFlags":
111124
or variable_used(instr, "resume_with_error")
112125
),
113126
HAS_ESCAPES_FLAG=(
114-
variable_used(instr, "tstate")
115-
or makes_escaping_api_call(instr)
127+
makes_escaping_api_call(instr)
116128
),
117129
)
118130

0 commit comments

Comments
 (0)