5
5
import parsing
6
6
from typing import AbstractSet
7
7
8
- WHITELIST = (
8
+ NON_ESCAPING_FUNCTIONS = (
9
9
"Py_INCREF" ,
10
10
"_PyDictOrValues_IsValues" ,
11
11
"_PyObject_DictOrValuesPointer" ,
39
39
"Py_NewRef" ,
40
40
"_PyList_ITEMS" ,
41
41
"_PyTuple_ITEMS" ,
42
+ "_PyList_AppendTakeRef" ,
43
+ "_Py_atomic_load_uintptr_relaxed" ,
44
+ "_PyFrame_GetCode" ,
42
45
)
43
46
47
+ ESCAPING_FUNCTIONS = (
48
+ "import_name" ,
49
+ "import_from" ,
50
+ )
51
+
52
+
44
53
def makes_escaping_api_call (instr : parsing .Node ) -> bool :
54
+ if "CALL_INTRINSIC" in instr .name :
55
+ return True ;
45
56
tkns = iter (instr .tokens )
46
57
for tkn in tkns :
47
58
if tkn .kind != lx .IDENTIFIER :
@@ -52,6 +63,8 @@ def makes_escaping_api_call(instr: parsing.Node) -> bool:
52
63
return False
53
64
if next_tkn .kind != lx .LPAREN :
54
65
continue
66
+ if tkn .text in ESCAPING_FUNCTIONS :
67
+ return True
55
68
if not tkn .text .startswith ("Py" ) and not tkn .text .startswith ("_Py" ):
56
69
continue
57
70
if tkn .text .endswith ("Check" ):
@@ -60,7 +73,7 @@ def makes_escaping_api_call(instr: parsing.Node) -> bool:
60
73
continue
61
74
if tkn .text .endswith ("CheckExact" ):
62
75
continue
63
- if tkn .text in WHITELIST :
76
+ if tkn .text in NON_ESCAPING_FUNCTIONS :
64
77
continue
65
78
return True
66
79
return False
@@ -111,8 +124,7 @@ def fromInstruction(instr: parsing.Node) -> "InstructionFlags":
111
124
or variable_used (instr , "resume_with_error" )
112
125
),
113
126
HAS_ESCAPES_FLAG = (
114
- variable_used (instr , "tstate" )
115
- or makes_escaping_api_call (instr )
127
+ makes_escaping_api_call (instr )
116
128
),
117
129
)
118
130
0 commit comments