Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4065,6 +4065,55 @@ def hot_loop():
self.assertNotIn('_PyJit_TryInitializeTracing', stderr,
f"JIT tracer memory leak detected:\n{stderr}")

def test_cold_exit_on_init_cleanup_frame(self):

result = script_helper.run_python_until_end('-c', textwrap.dedent("""
class A:
__slots__ = ('x', 'y', 'z', 'w')
def __init__(self):
self.x = self.y = -1
self.z = self.w = None
class B(A):
__slots__ = ('a', 'b', 'c', 'd', 'e')
def __init__(self):
super().__init__()
self.a = self.b = None
self.c = ""
self.d = self.e = False
class C(B):
__slots__ = ('name', 'flag')
def __init__(self, name):
super().__init__()
self.name = name
self.flag = False
funcs = []
for n in range(20, 80):
lines = [f"def f{n}(names, info):"]
for j in range(n):
lines.append(f" v{j} = names[{j % 3}]")
if j % 3 == 0:
lines.append(f" if v{j} in info:")
lines.append(f" v{j} = info[v{j}]")
elif j % 5 == 0:
lines.append(f" v{j} = len(v{j}) if isinstance(v{j}, str) else 0")
lines.append(" return C(names[0])")
ns = {'C': C}
exec("\\n".join(lines), ns)
funcs.append(ns[f"f{n}"])
names = ['alpha', 'beta', 'gamma']
info = {'alpha': 'x', 'beta': 'y', 'gamma': 'z'}
for f in funcs:
for _ in range(10):
f(names, info)
"""), PYTHON_JIT="1", PYTHON_JIT_STRESS="1",
PYTHON_JIT_SIDE_EXIT_INITIAL_VALUE="1")
self.assertEqual(result[0].rc, 0, result)

def global_identity(x):
return x

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix JIT optimizer assertion failure during ``CALL_ALLOC_AND_ENTER_INIT`` side exit.
2 changes: 1 addition & 1 deletion Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ _PyJit_TryInitializeTracing(
return 0;
}
PyObject *func = PyStackRef_AsPyObjectBorrow(frame->f_funcobj);
if (func == NULL) {
if (func == NULL || !PyFunction_Check(func)) {
return 0;
}
PyCodeObject *code = _PyFrame_GetCode(frame);
Expand Down
Loading