Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix test when the JIT is enabled only with the interpreter
  • Loading branch information
diegorusso committed Jan 25, 2026
commit 5d53a15795ebef0801e909cd36b4e9cac0d90bc4
23 changes: 18 additions & 5 deletions Lib/test/test_frame_pointer_unwind.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def _classify_stack(stack, jit_enabled):
def _annotate_unwind():
stack = _build_stack_and_unwind()
jit_enabled = hasattr(sys, "_jit") and sys._jit.is_enabled()
jit_backend = _testinternalcapi.get_jit_backend()
ranges = _testinternalcapi.get_jit_code_ranges() if jit_enabled else []
jit_code_ranges = len(ranges)
Comment thread
diegorusso marked this conversation as resolved.
Outdated
if jit_enabled and ranges:
print("JIT ranges:")
for start, end in ranges:
Expand All @@ -101,6 +103,8 @@ def _annotate_unwind():
"python_frames": python_frames,
"jit_frames": jit_frames,
"other_frames": other_frames,
"jit_code_ranges": jit_code_ranges,
"jit_backend": jit_backend,
})


Expand Down Expand Up @@ -163,18 +167,27 @@ def test_manual_unwind_respects_frame_pointers(self):
result = _manual_unwind_length(**env)
jit_frames = result["jit_frames"]
python_frames = result.get("python_frames", 0)
jit_backend = result.get("jit_backend")
if self.frame_pointers_expected:
self.assertGreater(
python_frames,
0,
f"expected to find Python frames on {self.machine} with env {env}",
)
if using_jit:
self.assertGreater(
jit_frames,
0,
f"expected to find JIT frames on {self.machine} with env {env}",
)
if jit_backend == "jit":
self.assertGreater(
jit_frames,
0,
f"expected to find JIT frames on {self.machine} with env {env}",
)
else:
# jit_backend is "interpreter" or not present
self.assertEqual(
jit_frames,
0,
f"unexpected JIT frames counted on {self.machine} with env {env}",
)
else:
self.assertEqual(
jit_frames,
Expand Down
13 changes: 13 additions & 0 deletions Modules/_testinternalcapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@ get_jit_code_ranges(PyObject *self, PyObject *Py_UNUSED(args))
return ranges;
}

static PyObject *
get_jit_backend(PyObject *self, PyObject *Py_UNUSED(args))
{
#ifdef _Py_JIT
return PyUnicode_FromString("jit");
#elif defined(_Py_TIER2)
return PyUnicode_FromString("interpreter");
#else
Py_RETURN_NONE;
#endif
}
Comment thread
diegorusso marked this conversation as resolved.

static PyObject *
manual_unwind_from_fp(uintptr_t *frame_pointer)
{
Expand Down Expand Up @@ -2828,6 +2840,7 @@ static PyMethodDef module_functions[] = {
{"get_stack_margin", get_stack_margin, METH_NOARGS},
{"classify_stack_addresses", classify_stack_addresses, METH_VARARGS},
{"get_jit_code_ranges", get_jit_code_ranges, METH_NOARGS},
{"get_jit_backend", get_jit_backend, METH_NOARGS},
{"manual_frame_pointer_unwind", manual_frame_pointer_unwind, METH_NOARGS},
{"test_bswap", test_bswap, METH_NOARGS},
{"test_popcount", test_popcount, METH_NOARGS},
Expand Down
Loading