| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -328,6 +328,27 @@ def test_sys_api_with_existing_perf_jit_trampoline(self): | |||
| 328 | 328 | """ | |
| 329 | 329 | assert_python_ok("-c", code, PYTHON_JIT="0") | |
| 330 | 330 | ||
| 331 | + @unittest.skipUnless( | ||
| 332 | + "-D_Py_JIT" in (sysconfig.get_config_var("PY_CORE_CFLAGS") or "").split(), | ||
| 333 | + "requires a real JIT (_Py_JIT)", | ||
| 334 | + ) | ||
| 335 | + def test_sys_api_perf_jit_backend_in_subinterpreter(self): | ||
| 336 | + # gh-157247: a subinterpreter must not bypass the JIT/perf exclusion. | ||
| 337 | + code = """if 1: | ||
| 338 | + import sys | ||
| 339 | + from contextlib import closing | ||
| 340 | + from concurrent import interpreters | ||
| 341 | + | ||
| 342 | + assert sys._jit.is_enabled(), "expected the JIT to be enabled" | ||
| 343 | + | ||
| 344 | + with closing(interpreters.create()) as interp: | ||
| 345 | + interp.exec( | ||
| 346 | + "import sys; sys.activate_stack_trampoline('perf_jit')") | ||
| 347 | + """ | ||
| 348 | + rc, out, err = assert_python_failure("-c", code, PYTHON_JIT="1") | ||
| 349 | + self.assertIn( | ||
| 350 | + b"Cannot activate the perf trampoline if the JIT is active", err) | ||
| 351 | + | ||
| 331 | 352 | ||
| 332 | 353 | def is_unwinding_reliable_with_frame_pointers(): | |
| 333 | 354 | cflags = sysconfig.get_config_var("PY_CORE_CFLAGS") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fix :func:`sys.activate_stack_trampoline` allowing activation from a | ||
| 2 | + subinterpreter while the JIT is enabled in the main interpreter. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2370,7 +2370,9 @@ sys_activate_stack_trampoline_impl(PyObject *module, const char *backend) | |||
| 2370 | 2370 | { | |
| 2371 | 2371 | #ifdef PY_HAVE_PERF_TRAMPOLINE | |
| 2372 | 2372 | #ifdef _Py_JIT | |
| 2373 | - if (_PyInterpreterState_GET()->jit) { | ||
| 2373 | + // Perf state is process-wide, and only the main interpreter can enable | ||
| 2374 | + // the JIT. Check it even when called from a subinterpreter (gh-157247). | ||
| 2375 | + if (_PyInterpreterState_Main()->jit) { | ||
| 2374 | 2376 | PyErr_SetString(PyExc_ValueError, "Cannot activate the perf trampoline if the JIT is active"); | |
| 2375 | 2377 | return NULL; | |
| 2376 | 2378 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments