]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-141579: Fix perf_jit backend in sys.activate_stack_trampoline() (GH-141580...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 15 Nov 2025 02:49:54 +0000 (03:49 +0100)
committerGitHub <noreply@github.com>
Sat, 15 Nov 2025 02:49:54 +0000 (02:49 +0000)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Lib/test/test_perf_profiler.py
Misc/NEWS.d/next/Core_and_Builtins/2025-11-15-01-21-00.gh-issue-141579.aB7cD9.rst [new file with mode: 0644]
Python/sysmodule.c

index 0207843cc0e8f7dd6ac29549b99fe71267d7388a..9f2e5899334df4ef529583fa369f6f785698725c 100644 (file)
@@ -231,6 +231,24 @@ class TestPerfTrampoline(unittest.TestCase):
                 """
         assert_python_ok("-c", code, PYTHON_JIT="0")
 
+    def test_sys_api_perf_jit_backend(self):
+        code = """if 1:
+                import sys
+                sys.activate_stack_trampoline("perf_jit")
+                assert sys.is_stack_trampoline_active() is True
+                sys.deactivate_stack_trampoline()
+                assert sys.is_stack_trampoline_active() is False
+                """
+        assert_python_ok("-c", code, PYTHON_JIT="0")
+
+    def test_sys_api_with_existing_perf_jit_trampoline(self):
+        code = """if 1:
+                import sys
+                sys.activate_stack_trampoline("perf_jit")
+                sys.activate_stack_trampoline("perf_jit")
+                """
+        assert_python_ok("-c", code, PYTHON_JIT="0")
+
 
 def is_unwinding_reliable_with_frame_pointers():
     cflags = sysconfig.get_config_var("PY_CORE_CFLAGS")
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-11-15-01-21-00.gh-issue-141579.aB7cD9.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-15-01-21-00.gh-issue-141579.aB7cD9.rst
new file mode 100644 (file)
index 0000000..8ab9979
--- /dev/null
@@ -0,0 +1,2 @@
+Fix :func:`sys.activate_stack_trampoline` to properly support the
+``perf_jit`` backend. Patch by Pablo Galindo.
index 1bb3dcaea9e6340eb3b8948103be138c1a59e6c1..a7280c0da2e87c047baf28dc231e0e2b1b1469de 100644 (file)
@@ -2373,14 +2373,14 @@ sys_activate_stack_trampoline_impl(PyObject *module, const char *backend)
                 return NULL;
             }
         }
-        else if (strcmp(backend, "perf_jit") == 0) {
-            _PyPerf_Callbacks cur_cb;
-            _PyPerfTrampoline_GetCallbacks(&cur_cb);
-            if (cur_cb.write_state != _Py_perfmap_jit_callbacks.write_state) {
-                if (_PyPerfTrampoline_SetCallbacks(&_Py_perfmap_jit_callbacks) < 0 ) {
-                    PyErr_SetString(PyExc_ValueError, "can't activate perf jit trampoline");
-                    return NULL;
-                }
+    }
+    else if (strcmp(backend, "perf_jit") == 0) {
+        _PyPerf_Callbacks cur_cb;
+        _PyPerfTrampoline_GetCallbacks(&cur_cb);
+        if (cur_cb.write_state != _Py_perfmap_jit_callbacks.write_state) {
+            if (_PyPerfTrampoline_SetCallbacks(&_Py_perfmap_jit_callbacks) < 0 ) {
+                PyErr_SetString(PyExc_ValueError, "can't activate perf jit trampoline");
+                return NULL;
             }
         }
     }