Skip to content

Commit 7e1a0db

Browse files
authored
[3.13] pythongh-141579: Fix perf_jit backend in sys.activate_stack_trampoline() (pythonGH-141580) (python#141582)
1 parent fb7ae3f commit 7e1a0db

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

Lib/test/test_perf_profiler.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,24 @@ def test_sys_api_get_status(self):
225225
"""
226226
assert_python_ok("-c", code)
227227

228+
def test_sys_api_perf_jit_backend(self):
229+
code = """if 1:
230+
import sys
231+
sys.activate_stack_trampoline("perf_jit")
232+
assert sys.is_stack_trampoline_active() is True
233+
sys.deactivate_stack_trampoline()
234+
assert sys.is_stack_trampoline_active() is False
235+
"""
236+
assert_python_ok("-c", code, PYTHON_JIT="0")
237+
238+
def test_sys_api_with_existing_perf_jit_trampoline(self):
239+
code = """if 1:
240+
import sys
241+
sys.activate_stack_trampoline("perf_jit")
242+
sys.activate_stack_trampoline("perf_jit")
243+
"""
244+
assert_python_ok("-c", code, PYTHON_JIT="0")
245+
228246

229247
def is_unwinding_reliable_with_frame_pointers():
230248
cflags = sysconfig.get_config_var("PY_CORE_CFLAGS")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :func:`sys.activate_stack_trampoline` to properly support the
2+
``perf_jit`` backend. Patch by Pablo Galindo.

Python/sysmodule.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,14 +2381,14 @@ sys_activate_stack_trampoline_impl(PyObject *module, const char *backend)
23812381
return NULL;
23822382
}
23832383
}
2384-
else if (strcmp(backend, "perf_jit") == 0) {
2385-
_PyPerf_Callbacks cur_cb;
2386-
_PyPerfTrampoline_GetCallbacks(&cur_cb);
2387-
if (cur_cb.write_state != _Py_perfmap_jit_callbacks.write_state) {
2388-
if (_PyPerfTrampoline_SetCallbacks(&_Py_perfmap_jit_callbacks) < 0 ) {
2389-
PyErr_SetString(PyExc_ValueError, "can't activate perf jit trampoline");
2390-
return NULL;
2391-
}
2384+
}
2385+
else if (strcmp(backend, "perf_jit") == 0) {
2386+
_PyPerf_Callbacks cur_cb;
2387+
_PyPerfTrampoline_GetCallbacks(&cur_cb);
2388+
if (cur_cb.write_state != _Py_perfmap_jit_callbacks.write_state) {
2389+
if (_PyPerfTrampoline_SetCallbacks(&_Py_perfmap_jit_callbacks) < 0 ) {
2390+
PyErr_SetString(PyExc_ValueError, "can't activate perf jit trampoline");
2391+
return NULL;
23922392
}
23932393
}
23942394
}

0 commit comments

Comments
 (0)