Skip to content

Commit 675f725

Browse files
committed
Fix segfaults under cpython in test_pythonrun
1 parent c7f798b commit 675f725

File tree

1 file changed

+51
-26
lines changed

1 file changed

+51
-26
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_pythonrun.py

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,46 +38,51 @@
3838
# SOFTWARE.
3939

4040
import sys
41-
from . import CPyExtTestCase, CPyExtFunction, CPyExtFunctionOutVars, unhandled_error_compare, GRAALPYTHON
41+
42+
from . import CPyExtTestCase, CPyExtFunction, unhandled_error_compare
43+
4244
__dir__ = __file__.rpartition("/")[0]
43-
44-
#python_run_test_result = None
4545

46-
def _reference_run_string(args):
46+
47+
# python_run_test_result = None
48+
49+
def _reference_run_string(args):
4750
if not isinstance(args[2], dict):
4851
if sys.version_info.minor >= 6:
4952
raise SystemError
5053
else:
5154
raise TypeError
52-
if not isinstance(args[3], dict):
55+
if not isinstance(args[3], dict):
5356
raise TypeError
5457
return None
5558

59+
5660
def _run_string_compare(x, y):
5761
res = unhandled_error_compare(x, y)
58-
if(isinstance(x, Exception)):
62+
if (isinstance(x, Exception)):
5963
return res
60-
64+
6165
global python_run_test_result
6266
pr = python_run_test_result
6367
res = res and pr == 42
6468
python_run_test_result = None
6569
if not res:
6670
assert False, "python_run_test_result is %s" % pr
6771
return res
68-
72+
73+
6974
class TestPythonRun(CPyExtTestCase):
70-
75+
7176
def compile_module(self, name):
7277
type(self).mro()[1].__dict__["test_%s" % name].create_module(name)
7378
super(TestPythonRun, self).compile_module(name)
74-
79+
7580
test_PyRun_StringFlags = CPyExtFunction(
7681
_reference_run_string,
7782
lambda: (
7883
("globals().update({'python_run_test_result':42})", 256, globals(), locals(), 0),
79-
("globals().update({'python_run_test_result':42})", 256, 'globals()', locals(), 0),
80-
("globals().update({'python_run_test_result':42})", 256, globals(), 'locals()', 0),
84+
("globals().update({'python_run_test_result':42})", 256, 'globals()', locals(), 0),
85+
("globals().update({'python_run_test_result':42})", 256, globals(), 'locals()', 0),
8186
),
8287
resultspec="O",
8388
argspec='siOOk',
@@ -117,17 +122,27 @@ def compile_module(self, name):
117122
258: "eval"
118123
}[args[2]],
119124
flags=args[3],
120-
optimize=args[4],
125+
_feature_version=args[4],
126+
optimize=args[5],
121127
),
122128
lambda: (
123-
("1 + 2", "foo.py", 256, 0, -1),
124-
("1 + 2", "foo.py", 257, 0, 1),
125-
("1 + 2", "foo.py", 258, 0, 2),
126-
("x = 2", "foo.py", 258, 0, 0),
129+
("1 + 2", "foo.py", 256, 0, 0, -1),
130+
("1 + 2", "foo.py", 257, 0, 0, 1),
131+
("1 + 2", "foo.py", 258, 0, 0, 2),
132+
("x = 2", "foo.py", 258, 0, 0, 0),
127133
),
134+
code="""
135+
PyObject* wrap_Py_CompileStringExFlags(const char *str, const char *filename_str, int start, int cf_flags,
136+
int cf_feature_version, int optimize) {
137+
PyCompilerFlags flags = {cf_flags, cf_feature_version};
138+
return Py_CompileStringExFlags(str, filename_str, start, &flags, optimize);
139+
}
140+
""",
141+
callfunction='wrap_Py_CompileStringExFlags',
128142
resultspec="O",
129-
argspec='ssiii',
130-
arguments=["char* source", "char* filename", "int type", "PyCompilerFlags* flags", "int optimize"],
143+
argspec='ssiiii',
144+
arguments=["char* source", "char* filename", "int type", "int cf_flags", "int cf_feature_version",
145+
"int optimize"],
131146
cmpfunc=unhandled_error_compare
132147
)
133148

@@ -141,16 +156,26 @@ def compile_module(self, name):
141156
258: "eval"
142157
}[args[2]],
143158
flags=args[3],
144-
optimize=args[4],
159+
_feature_version=args[4],
160+
optimize=args[5],
145161
),
146162
lambda: (
147-
("1 + 2", "foo.py", 256, 0, -1),
148-
("1 + 2", "foo.py", 257, 0, 1),
149-
("1 + 2", "foo.py", 258, 0, 2),
150-
("x = 2", "foo.py", 258, 0, 0),
163+
("1 + 2", "foo.py", 256, 0, 0, -1),
164+
("1 + 2", "foo.py", 257, 0, 0, 1),
165+
("1 + 2", "foo.py", 258, 0, 0, 2),
166+
("x = 2", "foo.py", 258, 0, 0, 0),
151167
),
168+
code="""
169+
PyObject* wrap_Py_CompileStringObject(const char *str, PyObject *filename, int start, int cf_flags,
170+
int cf_feature_version, int optimize) {
171+
PyCompilerFlags flags = {cf_flags, cf_feature_version};
172+
return Py_CompileStringObject(str, filename, start, &flags, optimize);
173+
}
174+
""",
175+
callfunction='wrap_Py_CompileStringObject',
152176
resultspec="O",
153-
argspec='sOiii',
154-
arguments=["char* source", "PyObject* filename", "int type", "PyCompilerFlags* flags", "int optimize"],
177+
argspec='sOiiii',
178+
arguments=["char* source", "PyObject* filename", "int type", "int cf_flags", "int cf_feature_version",
179+
"int optimize"],
155180
cmpfunc=unhandled_error_compare
156181
)

0 commit comments

Comments
 (0)