From 4c0c4440af553c2a5b5ccf7a9b53776b8ee14787 Mon Sep 17 00:00:00 2001 From: cocolato Date: Sun, 22 Feb 2026 15:36:40 +0800 Subject: [PATCH 1/2] fix jit crash --- Lib/test/test_capi/test_opt.py | 49 ++++++++++++++++++++++++++++++++++ Python/optimizer.c | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py index 7ac71fbfab1fe0..fe1b45608841a2 100644 --- a/Lib/test/test_capi/test_opt.py +++ b/Lib/test/test_capi/test_opt.py @@ -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 diff --git a/Python/optimizer.c b/Python/optimizer.c index f075e28d71e0f8..3f64785fafeabd 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -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); From 92a5cf5a194ff4b5917ac03c18abf3a328ed2ecd Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 22 Feb 2026 07:51:11 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-02-22-07-51-10.gh-issue-145064.iIMGKA.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-02-22-07-51-10.gh-issue-145064.iIMGKA.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-02-22-07-51-10.gh-issue-145064.iIMGKA.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-02-22-07-51-10.gh-issue-145064.iIMGKA.rst new file mode 100644 index 00000000000000..1f298e164f4488 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-02-22-07-51-10.gh-issue-145064.iIMGKA.rst @@ -0,0 +1 @@ +Fix JIT optimizer assertion failure during ``CALL_ALLOC_AND_ENTER_INIT`` side exit.