From 8d80f449584f1ec5e83e0d7dbc7fa52ae515a06f Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Fri, 1 Nov 2024 19:56:26 +0200 Subject: [PATCH] Necessary changes made by Pablo and Ken Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Pablo Galindo --- Lib/test/test_perf_profiler.py | 6 +++--- Python/pylifecycle.c | 5 ++++- Python/sysmodule.c | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_perf_profiler.py b/Lib/test/test_perf_profiler.py index b55d441759eb69..1e74990878007a 100644 --- a/Lib/test/test_perf_profiler.py +++ b/Lib/test/test_perf_profiler.py @@ -210,14 +210,14 @@ def test_sys_api_with_existing_trampoline(self): sys.activate_stack_trampoline("perf") sys.activate_stack_trampoline("perf") """ - assert_python_ok("-c", code) + assert_python_ok("-c", code, PYTHON_JIT="0") def test_sys_api_with_invalid_trampoline(self): code = """if 1: import sys sys.activate_stack_trampoline("invalid") """ - rc, out, err = assert_python_failure("-c", code) + rc, out, err = assert_python_failure("-c", code, PYTHON_JIT="0") self.assertIn("invalid backend: invalid", err.decode()) def test_sys_api_get_status(self): @@ -228,7 +228,7 @@ def test_sys_api_get_status(self): sys.deactivate_stack_trampoline() assert sys.is_stack_trampoline_active() is False """ - assert_python_ok("-c", code) + assert_python_ok("-c", code, PYTHON_JIT="0") def is_unwinding_reliable_with_frame_pointers(): diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 2efaa9db7d7d58..4d1eeafb6ddc94 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1310,12 +1310,15 @@ init_interp_main(PyThreadState *tstate) enabled = *env != '0'; } if (enabled) { +#ifdef _Py_JIT if (config->perf_profiling > 0) { (void)PyErr_WarnEx( PyExc_RuntimeWarning, "JIT deactivated as perf profiling support is active", 0); - } else { + } else +#endif + { PyObject *opt = _PyOptimizer_NewUOpOptimizer(); if (opt == NULL) { return _PyStatus_ERR("can't initialize optimizer"); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index cbb73977e1aae6..a4abd7c3c45709 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2290,6 +2290,7 @@ sys_activate_stack_trampoline_impl(PyObject *module, const char *backend) #ifdef _Py_JIT _PyOptimizerObject* optimizer = _Py_GetOptimizer(); if (optimizer != NULL) { + Py_DECREF(optimizer); PyErr_SetString(PyExc_ValueError, "Cannot activate the perf trampoline if the JIT is active"); return NULL; }