From 43740f7dbbcf962c432189209573c94ff961ac37 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 14:28:18 +0200 Subject: [PATCH 01/31] Add `Py_JIT_ENABLED` variable to `pyconfig.h` --- PCbuild/_freeze_module.vcxproj | 6 ++++++ PCbuild/pythoncore.vcxproj | 6 ++++++ configure | 35 +++++++++++++++++++++++++++++----- configure.ac | 25 +++++++++++++++++++----- pyconfig.h.in | 4 ++++ 5 files changed, 66 insertions(+), 10 deletions(-) diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj index a3c2d32c454e04..6e568c24e62911 100644 --- a/PCbuild/_freeze_module.vcxproj +++ b/PCbuild/_freeze_module.vcxproj @@ -449,6 +449,12 @@ $(PyConfigHText.Replace('#undef Py_GIL_DISABLED', '#define Py_GIL_DISABLED 1')) + + $(PyConfigHText.Replace('#undef Py_JIT_ENABLED', '#define Py_JIT_ENABLED 1')) + + + $(PyConfigHText.Replace('#undef Py_JIT_ENABLED', '#define Py_JIT_ENABLED "interpreter"')) + $(PyConfigHText.Replace('/* #define Py_GIL_DISABLED 1 */', '#define Py_GIL_DISABLED 1')) + + $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 1')) + + + $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED "interpreter" */', '#define Py_JIT_ENABLED "interpreter"')) + >confdefs.h + ;; + yes) + jit_flags="-D_Py_JIT"; + tier2_flags="-D_Py_TIER2=1"; + +printf "%s\n" "#define Py_JIT_ENABLED 1" >>confdefs.h + ;; + yes-off) + jit_flags="-D_Py_JIT"; + tier2_flags="-D_Py_TIER2=3"; + +printf "%s\n" "#define Py_JIT_ENABLED 1" >>confdefs.h + ;; + interpreter) + jit_flags=""; + tier2_flags="-D_Py_TIER2=4"; + +printf "%s\n" "#define Py_JIT_ENABLED \"interpreter\"" >>confdefs.h + ;; + interpreter-off) + jit_flags=""; + tier2_flags="-D_Py_TIER2=6"; + +printf "%s\n" "#define Py_JIT_ENABLED \"interpreter\"" >>confdefs.h + ;; # Secret option *) as_fn_error $? "invalid argument: --enable-experimental-jit=$enable_experimental_jit; expected no|yes|yes-off|interpreter" "$LINENO" 5 ;; esac if ${tier2_flags:+false} : diff --git a/configure.ac b/configure.ac index caf0244cc7b54b..7892f7a6570a71 100644 --- a/configure.ac +++ b/configure.ac @@ -1820,11 +1820,26 @@ AC_ARG_ENABLE([experimental-jit], [], [enable_experimental_jit=no]) case $enable_experimental_jit in - no) jit_flags=""; tier2_flags="" ;; - yes) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=1" ;; - yes-off) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=3" ;; - interpreter) jit_flags=""; tier2_flags="-D_Py_TIER2=4" ;; - interpreter-off) jit_flags=""; tier2_flags="-D_Py_TIER2=6" ;; # Secret option + no) + jit_flags=""; + tier2_flags=""; + AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) ;; + yes) + jit_flags="-D_Py_JIT"; + tier2_flags="-D_Py_TIER2=1"; + AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) ;; + yes-off) + jit_flags="-D_Py_JIT"; + tier2_flags="-D_Py_TIER2=3"; + AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) ;; + interpreter) + jit_flags=""; + tier2_flags="-D_Py_TIER2=4"; + AC_DEFINE([Py_JIT_ENABLED], ["interpreter"], [Define to interpreter if you want to build an interpreter with enabled tier 2 interpreter]) ;; + interpreter-off) + jit_flags=""; + tier2_flags="-D_Py_TIER2=6"; + AC_DEFINE([Py_JIT_ENABLED], ["interpreter"], [Define to interpreter if you want to build an interpreter with enabled tier 2 interpreter]) ;; # Secret option *) AC_MSG_ERROR( [invalid argument: --enable-experimental-jit=$enable_experimental_jit; expected no|yes|yes-off|interpreter]) ;; esac diff --git a/pyconfig.h.in b/pyconfig.h.in index fcb8a965b1e476..ef4cf71b28102e 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1695,6 +1695,10 @@ /* Defined if _Complex C type is available. */ #undef Py_HAVE_C_COMPLEX +/* Define to interpreter if you want to build an interpreter with enabled tier + 2 interpreter */ +#undef Py_JIT_ENABLED + /* Define if year with century should be normalized for strftime. */ #undef Py_NORMALIZE_CENTURY From 65e6cfa04c1a6f39765f9e50c82feeb81e74cc0f Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 14:43:00 +0200 Subject: [PATCH 02/31] Changes for Windows build --- PC/pyconfig.h.in | 6 ++++++ PCbuild/pythoncore.vcxproj | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/PC/pyconfig.h.in b/PC/pyconfig.h.in index 010f5fe5646630..e0cd37170daabb 100644 --- a/PC/pyconfig.h.in +++ b/PC/pyconfig.h.in @@ -102,6 +102,12 @@ WIN32 is still required for the locale module. /* #define Py_GIL_DISABLED 1 */ #endif +/* Define to 1 if you want to enable the JIT */ +/* Define to "interpreter" if you want to enable tier 2 interpreter */ +#ifndef Py_JIT_ENABLED +/* #define Py_JIT_ENABLED 1*/ +#endif + /* Compiler specific defines */ /* ------------------------------------------------------------------------*/ diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 867ccd0d47679a..df14bb12b30a0e 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -709,7 +709,7 @@ $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 1')) - $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED "interpreter" */', '#define Py_JIT_ENABLED "interpreter"')) + $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED "interpreter"')) Date: Thu, 31 Oct 2024 14:46:50 +0200 Subject: [PATCH 03/31] fix typo --- PC/pyconfig.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PC/pyconfig.h.in b/PC/pyconfig.h.in index e0cd37170daabb..c757944048377e 100644 --- a/PC/pyconfig.h.in +++ b/PC/pyconfig.h.in @@ -105,7 +105,7 @@ WIN32 is still required for the locale module. /* Define to 1 if you want to enable the JIT */ /* Define to "interpreter" if you want to enable tier 2 interpreter */ #ifndef Py_JIT_ENABLED -/* #define Py_JIT_ENABLED 1*/ +/* #define Py_JIT_ENABLED 1 */ #endif /* Compiler specific defines */ From f4f1748da81a4df889522c7eada78eb6f5589071 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 15:00:04 +0200 Subject: [PATCH 04/31] Another changes for Windows build --- PCbuild/_freeze_module.vcxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj index 6e568c24e62911..71f7420172aab9 100644 --- a/PCbuild/_freeze_module.vcxproj +++ b/PCbuild/_freeze_module.vcxproj @@ -450,10 +450,10 @@ $(PyConfigHText.Replace('#undef Py_GIL_DISABLED', '#define Py_GIL_DISABLED 1')) - $(PyConfigHText.Replace('#undef Py_JIT_ENABLED', '#define Py_JIT_ENABLED 1')) + $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 1')) - $(PyConfigHText.Replace('#undef Py_JIT_ENABLED', '#define Py_JIT_ENABLED "interpreter"')) + $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED "interpreter"')) Date: Thu, 31 Oct 2024 15:22:25 +0200 Subject: [PATCH 05/31] Update _sysconfig.c --- Modules/_sysconfig.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Modules/_sysconfig.c b/Modules/_sysconfig.c index c50c5cfabc2f1f..dc6abcc07bff8f 100644 --- a/Modules/_sysconfig.c +++ b/Modules/_sysconfig.c @@ -66,7 +66,23 @@ _sysconfig_config_vars_impl(PyObject *module) Py_DECREF(config); return NULL; } - +#ifdef Py_JIT_ENABLED + if (Py_JIT_ENABLED == 1) { + PyObject *py_jit_enabled = _PyLong_GetOne(); + } else { + PyObject *py_jit_enabled = PyUnicode_FromString("interpreter"); + if (py_jit_enabled == NULL) { + Py_DECREF(config); + return NULL; + } + } +#else + PyObject *py_jit_enabled = _PyLong_GetZero(); +#endif + if (PyDict_SetItemString(config, "Py_JIT_ENABLED", py_jit_enabled) < 0) { + Py_DECREF(config); + return NULL; + } return config; } From a3e6ddaa157eb03704f74b346d3744a15df17bb0 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 16:54:05 +0200 Subject: [PATCH 06/31] Don't set Py_JIT_ENABLED to 1 if --enable-experimental-jit=no --- Modules/_sysconfig.c | 5 +++-- configure | 20 +++++++++++--------- configure.ac | 18 +++++++++++------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Modules/_sysconfig.c b/Modules/_sysconfig.c index dc6abcc07bff8f..e124bafd7d105e 100644 --- a/Modules/_sysconfig.c +++ b/Modules/_sysconfig.c @@ -67,10 +67,11 @@ _sysconfig_config_vars_impl(PyObject *module) return NULL; } #ifdef Py_JIT_ENABLED + PyObject *py_jit_enabled; if (Py_JIT_ENABLED == 1) { - PyObject *py_jit_enabled = _PyLong_GetOne(); + py_jit_enabled = _PyLong_GetOne(); } else { - PyObject *py_jit_enabled = PyUnicode_FromString("interpreter"); + py_jit_enabled = PyUnicode_FromString("interpreter"); if (py_jit_enabled == NULL) { Py_DECREF(config); return NULL; diff --git a/configure b/configure index 534fd8d16c7204..72630292569f79 100755 --- a/configure +++ b/configure @@ -8277,33 +8277,35 @@ case $enable_experimental_jit in no) jit_flags=""; tier2_flags=""; - -printf "%s\n" "#define Py_JIT_ENABLED 1" >>confdefs.h - ;; + ;; yes) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=1"; printf "%s\n" "#define Py_JIT_ENABLED 1" >>confdefs.h - ;; + + ;; yes-off) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=3"; printf "%s\n" "#define Py_JIT_ENABLED 1" >>confdefs.h - ;; + + ;; interpreter) jit_flags=""; tier2_flags="-D_Py_TIER2=4"; printf "%s\n" "#define Py_JIT_ENABLED \"interpreter\"" >>confdefs.h - ;; + + ;; interpreter-off) - jit_flags=""; - tier2_flags="-D_Py_TIER2=6"; + jit_flags=""; + tier2_flags="-D_Py_TIER2=6"; printf "%s\n" "#define Py_JIT_ENABLED \"interpreter\"" >>confdefs.h - ;; # Secret option + # Secret option + ;; *) as_fn_error $? "invalid argument: --enable-experimental-jit=$enable_experimental_jit; expected no|yes|yes-off|interpreter" "$LINENO" 5 ;; esac if ${tier2_flags:+false} : diff --git a/configure.ac b/configure.ac index 7892f7a6570a71..e44ebcc9cf22a7 100644 --- a/configure.ac +++ b/configure.ac @@ -1823,23 +1823,27 @@ case $enable_experimental_jit in no) jit_flags=""; tier2_flags=""; - AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) ;; + ;; yes) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=1"; - AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) ;; + AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) + ;; yes-off) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=3"; - AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) ;; + AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) + ;; interpreter) jit_flags=""; tier2_flags="-D_Py_TIER2=4"; - AC_DEFINE([Py_JIT_ENABLED], ["interpreter"], [Define to interpreter if you want to build an interpreter with enabled tier 2 interpreter]) ;; + AC_DEFINE([Py_JIT_ENABLED], ["interpreter"], [Define to interpreter if you want to build an interpreter with enabled tier 2 interpreter]) + ;; interpreter-off) - jit_flags=""; - tier2_flags="-D_Py_TIER2=6"; - AC_DEFINE([Py_JIT_ENABLED], ["interpreter"], [Define to interpreter if you want to build an interpreter with enabled tier 2 interpreter]) ;; # Secret option + jit_flags=""; + tier2_flags="-D_Py_TIER2=6"; + AC_DEFINE([Py_JIT_ENABLED], ["interpreter"], [Define to interpreter if you want to build an interpreter with enabled tier 2 interpreter]) # Secret option + ;; *) AC_MSG_ERROR( [invalid argument: --enable-experimental-jit=$enable_experimental_jit; expected no|yes|yes-off|interpreter]) ;; esac From 40c001c73f84d0190bd152896ec83f6487b9cdc6 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 17:13:57 +0200 Subject: [PATCH 07/31] Fixes for Windows build.. --- PCbuild/_freeze_module.vcxproj | 2 +- PCbuild/pythoncore.vcxproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj index 71f7420172aab9..3d3eadd710f538 100644 --- a/PCbuild/_freeze_module.vcxproj +++ b/PCbuild/_freeze_module.vcxproj @@ -452,7 +452,7 @@ $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 1')) - + $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED "interpreter"')) diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index df14bb12b30a0e..e178759376f6b6 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -708,7 +708,7 @@ $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 1')) - + $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED "interpreter"')) From 81994a92a1cf2ddab2314a14b767e6239a3e28d6 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 17:27:33 +0200 Subject: [PATCH 08/31] Set Py_JIT_ENABLED to 2 insetad of 'interpreter' --- Modules/_sysconfig.c | 6 +----- PC/pyconfig.h.in | 4 ++-- PCbuild/_freeze_module.vcxproj | 2 +- PCbuild/pythoncore.vcxproj | 2 +- configure | 4 ++-- configure.ac | 4 ++-- pyconfig.h.in | 4 ++-- 7 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Modules/_sysconfig.c b/Modules/_sysconfig.c index e124bafd7d105e..79c07fc859aaaf 100644 --- a/Modules/_sysconfig.c +++ b/Modules/_sysconfig.c @@ -71,11 +71,7 @@ _sysconfig_config_vars_impl(PyObject *module) if (Py_JIT_ENABLED == 1) { py_jit_enabled = _PyLong_GetOne(); } else { - py_jit_enabled = PyUnicode_FromString("interpreter"); - if (py_jit_enabled == NULL) { - Py_DECREF(config); - return NULL; - } + py_jit_enabled = PyLong_FromInt(2); } #else PyObject *py_jit_enabled = _PyLong_GetZero(); diff --git a/PC/pyconfig.h.in b/PC/pyconfig.h.in index c757944048377e..fe3f8003a91167 100644 --- a/PC/pyconfig.h.in +++ b/PC/pyconfig.h.in @@ -102,8 +102,8 @@ WIN32 is still required for the locale module. /* #define Py_GIL_DISABLED 1 */ #endif -/* Define to 1 if you want to enable the JIT */ -/* Define to "interpreter" if you want to enable tier 2 interpreter */ +/* Define to 1 if you want to build an interpreter with JIT, or define to 2 +if you want to enable tier 2 interpreter /* #ifndef Py_JIT_ENABLED /* #define Py_JIT_ENABLED 1 */ #endif diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj index 3d3eadd710f538..3e5a03b697f71e 100644 --- a/PCbuild/_freeze_module.vcxproj +++ b/PCbuild/_freeze_module.vcxproj @@ -453,7 +453,7 @@ $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 1')) - $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED "interpreter"')) + $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 2')) $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 1')) - $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED "interpreter"')) + $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 2')) >confdefs.h jit_flags=""; tier2_flags="-D_Py_TIER2=4"; -printf "%s\n" "#define Py_JIT_ENABLED \"interpreter\"" >>confdefs.h +printf "%s\n" "#define Py_JIT_ENABLED 2" >>confdefs.h ;; interpreter-off) jit_flags=""; tier2_flags="-D_Py_TIER2=6"; -printf "%s\n" "#define Py_JIT_ENABLED \"interpreter\"" >>confdefs.h +printf "%s\n" "#define Py_JIT_ENABLED 2" >>confdefs.h # Secret option ;; *) as_fn_error $? "invalid argument: --enable-experimental-jit=$enable_experimental_jit; expected no|yes|yes-off|interpreter" "$LINENO" 5 ;; diff --git a/configure.ac b/configure.ac index e44ebcc9cf22a7..0cedb476345570 100644 --- a/configure.ac +++ b/configure.ac @@ -1837,12 +1837,12 @@ case $enable_experimental_jit in interpreter) jit_flags=""; tier2_flags="-D_Py_TIER2=4"; - AC_DEFINE([Py_JIT_ENABLED], ["interpreter"], [Define to interpreter if you want to build an interpreter with enabled tier 2 interpreter]) + AC_DEFINE([Py_JIT_ENABLED], [2], [Define to 2 if you want to build an interpreter with enabled tier 2 interpreter]) ;; interpreter-off) jit_flags=""; tier2_flags="-D_Py_TIER2=6"; - AC_DEFINE([Py_JIT_ENABLED], ["interpreter"], [Define to interpreter if you want to build an interpreter with enabled tier 2 interpreter]) # Secret option + AC_DEFINE([Py_JIT_ENABLED], [2], [Define to 2 if you want to build an interpreter with enabled tier 2 interpreter]) # Secret option ;; *) AC_MSG_ERROR( [invalid argument: --enable-experimental-jit=$enable_experimental_jit; expected no|yes|yes-off|interpreter]) ;; diff --git a/pyconfig.h.in b/pyconfig.h.in index ef4cf71b28102e..4929c030c16ef3 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1695,8 +1695,8 @@ /* Defined if _Complex C type is available. */ #undef Py_HAVE_C_COMPLEX -/* Define to interpreter if you want to build an interpreter with enabled tier - 2 interpreter */ +/* Define to 2 if you want to build an interpreter with enabled tier 2 + interpreter */ #undef Py_JIT_ENABLED /* Define if year with century should be normalized for strftime. */ From 1618433774bf645bac1792b38f96afccd4be0b0c Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 17:29:06 +0200 Subject: [PATCH 09/31] PyLong_FromInt -> PyLong_FromLong --- Modules/_sysconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_sysconfig.c b/Modules/_sysconfig.c index 79c07fc859aaaf..5c4d58f935a075 100644 --- a/Modules/_sysconfig.c +++ b/Modules/_sysconfig.c @@ -71,7 +71,7 @@ _sysconfig_config_vars_impl(PyObject *module) if (Py_JIT_ENABLED == 1) { py_jit_enabled = _PyLong_GetOne(); } else { - py_jit_enabled = PyLong_FromInt(2); + py_jit_enabled = PyLong_FromLong(2); } #else PyObject *py_jit_enabled = _PyLong_GetZero(); From 1773d9e51e30c74d0e073866ad30b7f238a944ea Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 17:34:15 +0200 Subject: [PATCH 10/31] Fix typo in pyconfigs --- PC/pyconfig.h.in | 2 +- pyconfig.h.in | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PC/pyconfig.h.in b/PC/pyconfig.h.in index fe3f8003a91167..aeb326b28fe013 100644 --- a/PC/pyconfig.h.in +++ b/PC/pyconfig.h.in @@ -103,7 +103,7 @@ WIN32 is still required for the locale module. #endif /* Define to 1 if you want to build an interpreter with JIT, or define to 2 -if you want to enable tier 2 interpreter /* + * if you want to enable tier 2 interpreter */ #ifndef Py_JIT_ENABLED /* #define Py_JIT_ENABLED 1 */ #endif diff --git a/pyconfig.h.in b/pyconfig.h.in index 4929c030c16ef3..26372eff01163a 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1695,8 +1695,8 @@ /* Defined if _Complex C type is available. */ #undef Py_HAVE_C_COMPLEX -/* Define to 2 if you want to build an interpreter with enabled tier 2 - interpreter */ +/* Define to 2 if you want to build an interpreter without JIT, but + * with enabled tier 2 interpreter */ #undef Py_JIT_ENABLED /* Define if year with century should be normalized for strftime. */ From 9a50db73ea2e48d8e4cc59aae09a25846ec83197 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 17:47:27 +0200 Subject: [PATCH 11/31] Add a NEWS entry --- .../2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst b/Misc/NEWS.d/next/Core and Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst new file mode 100644 index 00000000000000..cdd832d16a29ff --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst @@ -0,0 +1,2 @@ +Add a ``Py_JIT_ENABLED`` variable to ``pyconfig.h`` to help determine if CPython was built +with JIT or not. From 4b4e212bd553730cd71d021ed9d3de4ed8c22382 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 17:57:20 +0200 Subject: [PATCH 12/31] Update documentation --- Doc/using/configure.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst index 83994af795e3fc..858cd95b2fc797 100644 --- a/Doc/using/configure.rst +++ b/Doc/using/configure.rst @@ -297,6 +297,23 @@ General Options .. versionadded:: 3.13 +.. option:: --enable-experimental-jit + Enables :ref:`JIT compiler `. + Possible values: + * ``no`` - build interpreter without JIT. + * ``yes`` - build interpreter with JIT. + * ``yes-off`` - build interpreter with JIT but disable it by default. + * ``interpreter`` - build interpreter without JIT, but with enabled tier 2 interpreter. + + Defines the ``Py_JIT_ENABLED`` macro, with possible values: + * ``0`` - interpreter was built without JIT. + * ``1`` - interpreter was built with JIT. + * ``2`` - interpreter was built without JIT, but with enabled tier 2 interpreter. + + .. versionadded:: next + + .. versionadded:: 3.13 + .. option:: PKG_CONFIG Path to ``pkg-config`` utility. From 19ddff24b0670b899858782bc5f375fcf072633a Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 18:00:31 +0200 Subject: [PATCH 13/31] Fix typo --- pyconfig.h.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyconfig.h.in b/pyconfig.h.in index 26372eff01163a..eb06161a5cb536 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1695,8 +1695,8 @@ /* Defined if _Complex C type is available. */ #undef Py_HAVE_C_COMPLEX -/* Define to 2 if you want to build an interpreter without JIT, but - * with enabled tier 2 interpreter */ +/* Define to 1 if you want to build an interpreter with JIT, or define to 2 + * if you want to enable tier 2 interpreter */ #undef Py_JIT_ENABLED /* Define if year with century should be normalized for strftime. */ From 91b7a786df31a04e5980d5f56f33e7ccf14f7df0 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 18:06:38 +0200 Subject: [PATCH 14/31] Move NEWS entry --- .../2024-10-31-17-44-32.gh.issue-126204.ASJLDK.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Misc/NEWS.d/next/{Core and Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst => Core_and_Builtins/2024-10-31-17-44-32.gh.issue-126204.ASJLDK.rst} (100%) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-31-17-44-32.gh.issue-126204.ASJLDK.rst similarity index 100% rename from Misc/NEWS.d/next/Core and Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst rename to Misc/NEWS.d/next/Core_and_Builtins/2024-10-31-17-44-32.gh.issue-126204.ASJLDK.rst From e79e0df7a1cfa3d85954f6eb2b5ae21fa4744da1 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 18:09:03 +0200 Subject: [PATCH 15/31] Fix typo in path --- ....ASJLDK.rst => 2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Misc/NEWS.d/next/Core_and_Builtins/{2024-10-31-17-44-32.gh.issue-126204.ASJLDK.rst => 2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst} (100%) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-10-31-17-44-32.gh.issue-126204.ASJLDK.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst similarity index 100% rename from Misc/NEWS.d/next/Core_and_Builtins/2024-10-31-17-44-32.gh.issue-126204.ASJLDK.rst rename to Misc/NEWS.d/next/Core_and_Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst From 759321bb48a93443b7ea6cd8c53e6702b6756505 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 18:10:55 +0200 Subject: [PATCH 16/31] Fix doc formatting --- Doc/using/configure.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst index 858cd95b2fc797..14878534c5acac 100644 --- a/Doc/using/configure.rst +++ b/Doc/using/configure.rst @@ -298,7 +298,9 @@ General Options .. versionadded:: 3.13 .. option:: --enable-experimental-jit + Enables :ref:`JIT compiler `. + Possible values: * ``no`` - build interpreter without JIT. * ``yes`` - build interpreter with JIT. From 49e4fdcd8ae29bb183d62c3aaea8d4bb97813f98 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Thu, 31 Oct 2024 18:24:53 +0200 Subject: [PATCH 17/31] Fix configure --- PC/pyconfig.h.in | 4 ++-- configure.ac | 8 ++++---- pyconfig.h.in | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/PC/pyconfig.h.in b/PC/pyconfig.h.in index aeb326b28fe013..882293540e8e3f 100644 --- a/PC/pyconfig.h.in +++ b/PC/pyconfig.h.in @@ -102,8 +102,8 @@ WIN32 is still required for the locale module. /* #define Py_GIL_DISABLED 1 */ #endif -/* Define to 1 if you want to build an interpreter with JIT, or define to 2 - * if you want to enable tier 2 interpreter */ +/* Define to 1 if you want to build an interpreter with JIT, or define to 2 if + you want to enable tier 2 interpreter */ #ifndef Py_JIT_ENABLED /* #define Py_JIT_ENABLED 1 */ #endif diff --git a/configure.ac b/configure.ac index 0cedb476345570..fe2c64fefc8f84 100644 --- a/configure.ac +++ b/configure.ac @@ -1827,22 +1827,22 @@ case $enable_experimental_jit in yes) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=1"; - AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) + AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT, or define to 2 if you want to enable tier 2 interpreter]) ;; yes-off) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=3"; - AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) + AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT, or define to 2 if you want to enable tier 2 interpreter]) ;; interpreter) jit_flags=""; tier2_flags="-D_Py_TIER2=4"; - AC_DEFINE([Py_JIT_ENABLED], [2], [Define to 2 if you want to build an interpreter with enabled tier 2 interpreter]) + AC_DEFINE([Py_JIT_ENABLED], [2], [Define to 1 if you want to build an interpreter with JIT, or define to 2 if you want to enable tier 2 interpreter]) ;; interpreter-off) jit_flags=""; tier2_flags="-D_Py_TIER2=6"; - AC_DEFINE([Py_JIT_ENABLED], [2], [Define to 2 if you want to build an interpreter with enabled tier 2 interpreter]) # Secret option + AC_DEFINE([Py_JIT_ENABLED], [2], [Define to 1 if you want to build an interpreter with JIT, or define to 2 if you want to enable tier 2 interpreter]) # Secret option ;; *) AC_MSG_ERROR( [invalid argument: --enable-experimental-jit=$enable_experimental_jit; expected no|yes|yes-off|interpreter]) ;; diff --git a/pyconfig.h.in b/pyconfig.h.in index eb06161a5cb536..8b00553f201860 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1695,8 +1695,8 @@ /* Defined if _Complex C type is available. */ #undef Py_HAVE_C_COMPLEX -/* Define to 1 if you want to build an interpreter with JIT, or define to 2 - * if you want to enable tier 2 interpreter */ +/* Define to 1 if you want to build an interpreter with JIT, or define to 2 if + you want to enable tier 2 interpreter */ #undef Py_JIT_ENABLED /* Define if year with century should be normalized for strftime. */ From 169831e3cfdf389d47505518938693c3564bc317 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Tue, 5 Nov 2024 05:02:44 +0200 Subject: [PATCH 18/31] Revert previous changes --- Doc/using/configure.rst | 19 --------------- ...-10-31-17-44-32.gh-issue-126204.ASJLDK.rst | 2 -- Modules/_sysconfig.c | 15 +----------- PC/pyconfig.h.in | 6 ----- PCbuild/_freeze_module.vcxproj | 6 ++--- PCbuild/pythoncore.vcxproj | 4 ++-- configure | 24 +++++++++---------- configure.ac | 18 ++++++-------- pyconfig.h.in | 4 ++-- 9 files changed, 26 insertions(+), 72 deletions(-) delete mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst index 14878534c5acac..83994af795e3fc 100644 --- a/Doc/using/configure.rst +++ b/Doc/using/configure.rst @@ -297,25 +297,6 @@ General Options .. versionadded:: 3.13 -.. option:: --enable-experimental-jit - - Enables :ref:`JIT compiler `. - - Possible values: - * ``no`` - build interpreter without JIT. - * ``yes`` - build interpreter with JIT. - * ``yes-off`` - build interpreter with JIT but disable it by default. - * ``interpreter`` - build interpreter without JIT, but with enabled tier 2 interpreter. - - Defines the ``Py_JIT_ENABLED`` macro, with possible values: - * ``0`` - interpreter was built without JIT. - * ``1`` - interpreter was built with JIT. - * ``2`` - interpreter was built without JIT, but with enabled tier 2 interpreter. - - .. versionadded:: next - - .. versionadded:: 3.13 - .. option:: PKG_CONFIG Path to ``pkg-config`` utility. diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst deleted file mode 100644 index cdd832d16a29ff..00000000000000 --- a/Misc/NEWS.d/next/Core_and_Builtins/2024-10-31-17-44-32.gh-issue-126204.ASJLDK.rst +++ /dev/null @@ -1,2 +0,0 @@ -Add a ``Py_JIT_ENABLED`` variable to ``pyconfig.h`` to help determine if CPython was built -with JIT or not. diff --git a/Modules/_sysconfig.c b/Modules/_sysconfig.c index 5c4d58f935a075..c50c5cfabc2f1f 100644 --- a/Modules/_sysconfig.c +++ b/Modules/_sysconfig.c @@ -66,20 +66,7 @@ _sysconfig_config_vars_impl(PyObject *module) Py_DECREF(config); return NULL; } -#ifdef Py_JIT_ENABLED - PyObject *py_jit_enabled; - if (Py_JIT_ENABLED == 1) { - py_jit_enabled = _PyLong_GetOne(); - } else { - py_jit_enabled = PyLong_FromLong(2); - } -#else - PyObject *py_jit_enabled = _PyLong_GetZero(); -#endif - if (PyDict_SetItemString(config, "Py_JIT_ENABLED", py_jit_enabled) < 0) { - Py_DECREF(config); - return NULL; - } + return config; } diff --git a/PC/pyconfig.h.in b/PC/pyconfig.h.in index 882293540e8e3f..010f5fe5646630 100644 --- a/PC/pyconfig.h.in +++ b/PC/pyconfig.h.in @@ -102,12 +102,6 @@ WIN32 is still required for the locale module. /* #define Py_GIL_DISABLED 1 */ #endif -/* Define to 1 if you want to build an interpreter with JIT, or define to 2 if - you want to enable tier 2 interpreter */ -#ifndef Py_JIT_ENABLED -/* #define Py_JIT_ENABLED 1 */ -#endif - /* Compiler specific defines */ /* ------------------------------------------------------------------------*/ diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj index 3e5a03b697f71e..6e568c24e62911 100644 --- a/PCbuild/_freeze_module.vcxproj +++ b/PCbuild/_freeze_module.vcxproj @@ -450,10 +450,10 @@ $(PyConfigHText.Replace('#undef Py_GIL_DISABLED', '#define Py_GIL_DISABLED 1')) - $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 1')) + $(PyConfigHText.Replace('#undef Py_JIT_ENABLED', '#define Py_JIT_ENABLED 1')) - - $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 2')) + + $(PyConfigHText.Replace('#undef Py_JIT_ENABLED', '#define Py_JIT_ENABLED "interpreter"')) $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 1')) - - $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 2')) + + $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED "interpreter" */', '#define Py_JIT_ENABLED "interpreter"')) >confdefs.h + ;; yes) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=1"; printf "%s\n" "#define Py_JIT_ENABLED 1" >>confdefs.h - - ;; + ;; yes-off) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=3"; printf "%s\n" "#define Py_JIT_ENABLED 1" >>confdefs.h - - ;; + ;; interpreter) jit_flags=""; tier2_flags="-D_Py_TIER2=4"; -printf "%s\n" "#define Py_JIT_ENABLED 2" >>confdefs.h - - ;; +printf "%s\n" "#define Py_JIT_ENABLED \"interpreter\"" >>confdefs.h + ;; interpreter-off) - jit_flags=""; - tier2_flags="-D_Py_TIER2=6"; + jit_flags=""; + tier2_flags="-D_Py_TIER2=6"; -printf "%s\n" "#define Py_JIT_ENABLED 2" >>confdefs.h - # Secret option - ;; +printf "%s\n" "#define Py_JIT_ENABLED \"interpreter\"" >>confdefs.h + ;; # Secret option *) as_fn_error $? "invalid argument: --enable-experimental-jit=$enable_experimental_jit; expected no|yes|yes-off|interpreter" "$LINENO" 5 ;; esac if ${tier2_flags:+false} : diff --git a/configure.ac b/configure.ac index fe2c64fefc8f84..7892f7a6570a71 100644 --- a/configure.ac +++ b/configure.ac @@ -1823,27 +1823,23 @@ case $enable_experimental_jit in no) jit_flags=""; tier2_flags=""; - ;; + AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) ;; yes) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=1"; - AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT, or define to 2 if you want to enable tier 2 interpreter]) - ;; + AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) ;; yes-off) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=3"; - AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT, or define to 2 if you want to enable tier 2 interpreter]) - ;; + AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) ;; interpreter) jit_flags=""; tier2_flags="-D_Py_TIER2=4"; - AC_DEFINE([Py_JIT_ENABLED], [2], [Define to 1 if you want to build an interpreter with JIT, or define to 2 if you want to enable tier 2 interpreter]) - ;; + AC_DEFINE([Py_JIT_ENABLED], ["interpreter"], [Define to interpreter if you want to build an interpreter with enabled tier 2 interpreter]) ;; interpreter-off) - jit_flags=""; - tier2_flags="-D_Py_TIER2=6"; - AC_DEFINE([Py_JIT_ENABLED], [2], [Define to 1 if you want to build an interpreter with JIT, or define to 2 if you want to enable tier 2 interpreter]) # Secret option - ;; + jit_flags=""; + tier2_flags="-D_Py_TIER2=6"; + AC_DEFINE([Py_JIT_ENABLED], ["interpreter"], [Define to interpreter if you want to build an interpreter with enabled tier 2 interpreter]) ;; # Secret option *) AC_MSG_ERROR( [invalid argument: --enable-experimental-jit=$enable_experimental_jit; expected no|yes|yes-off|interpreter]) ;; esac diff --git a/pyconfig.h.in b/pyconfig.h.in index 8b00553f201860..ef4cf71b28102e 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1695,8 +1695,8 @@ /* Defined if _Complex C type is available. */ #undef Py_HAVE_C_COMPLEX -/* Define to 1 if you want to build an interpreter with JIT, or define to 2 if - you want to enable tier 2 interpreter */ +/* Define to interpreter if you want to build an interpreter with enabled tier + 2 interpreter */ #undef Py_JIT_ENABLED /* Define if year with century should be normalized for strftime. */ From c83ea490435e9a83fb3e76fc7eaef83ef50a6cd6 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Tue, 5 Nov 2024 05:09:12 +0200 Subject: [PATCH 19/31] Revert other part of previous changes --- PCbuild/_freeze_module.vcxproj | 6 ------ PCbuild/pythoncore.vcxproj | 6 ------ configure | 35 +++++----------------------------- configure.ac | 25 +++++------------------- pyconfig.h.in | 4 ---- 5 files changed, 10 insertions(+), 66 deletions(-) diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj index 6e568c24e62911..a3c2d32c454e04 100644 --- a/PCbuild/_freeze_module.vcxproj +++ b/PCbuild/_freeze_module.vcxproj @@ -449,12 +449,6 @@ $(PyConfigHText.Replace('#undef Py_GIL_DISABLED', '#define Py_GIL_DISABLED 1')) - - $(PyConfigHText.Replace('#undef Py_JIT_ENABLED', '#define Py_JIT_ENABLED 1')) - - - $(PyConfigHText.Replace('#undef Py_JIT_ENABLED', '#define Py_JIT_ENABLED "interpreter"')) - $(PyConfigHText.Replace('/* #define Py_GIL_DISABLED 1 */', '#define Py_GIL_DISABLED 1')) - - $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED 1 */', '#define Py_JIT_ENABLED 1')) - - - $(PyConfigHText.Replace('/* #define Py_JIT_ENABLED "interpreter" */', '#define Py_JIT_ENABLED "interpreter"')) - >confdefs.h - ;; - yes) - jit_flags="-D_Py_JIT"; - tier2_flags="-D_Py_TIER2=1"; - -printf "%s\n" "#define Py_JIT_ENABLED 1" >>confdefs.h - ;; - yes-off) - jit_flags="-D_Py_JIT"; - tier2_flags="-D_Py_TIER2=3"; - -printf "%s\n" "#define Py_JIT_ENABLED 1" >>confdefs.h - ;; - interpreter) - jit_flags=""; - tier2_flags="-D_Py_TIER2=4"; - -printf "%s\n" "#define Py_JIT_ENABLED \"interpreter\"" >>confdefs.h - ;; - interpreter-off) - jit_flags=""; - tier2_flags="-D_Py_TIER2=6"; - -printf "%s\n" "#define Py_JIT_ENABLED \"interpreter\"" >>confdefs.h - ;; # Secret option + no) jit_flags=""; tier2_flags="" ;; + yes) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=1" ;; + yes-off) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=3" ;; + interpreter) jit_flags=""; tier2_flags="-D_Py_TIER2=4" ;; + interpreter-off) jit_flags=""; tier2_flags="-D_Py_TIER2=6" ;; # Secret option *) as_fn_error $? "invalid argument: --enable-experimental-jit=$enable_experimental_jit; expected no|yes|yes-off|interpreter" "$LINENO" 5 ;; esac if ${tier2_flags:+false} : diff --git a/configure.ac b/configure.ac index 7892f7a6570a71..caf0244cc7b54b 100644 --- a/configure.ac +++ b/configure.ac @@ -1820,26 +1820,11 @@ AC_ARG_ENABLE([experimental-jit], [], [enable_experimental_jit=no]) case $enable_experimental_jit in - no) - jit_flags=""; - tier2_flags=""; - AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) ;; - yes) - jit_flags="-D_Py_JIT"; - tier2_flags="-D_Py_TIER2=1"; - AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) ;; - yes-off) - jit_flags="-D_Py_JIT"; - tier2_flags="-D_Py_TIER2=3"; - AC_DEFINE([Py_JIT_ENABLED], [1], [Define to 1 if you want to build an interpreter with JIT]) ;; - interpreter) - jit_flags=""; - tier2_flags="-D_Py_TIER2=4"; - AC_DEFINE([Py_JIT_ENABLED], ["interpreter"], [Define to interpreter if you want to build an interpreter with enabled tier 2 interpreter]) ;; - interpreter-off) - jit_flags=""; - tier2_flags="-D_Py_TIER2=6"; - AC_DEFINE([Py_JIT_ENABLED], ["interpreter"], [Define to interpreter if you want to build an interpreter with enabled tier 2 interpreter]) ;; # Secret option + no) jit_flags=""; tier2_flags="" ;; + yes) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=1" ;; + yes-off) jit_flags="-D_Py_JIT"; tier2_flags="-D_Py_TIER2=3" ;; + interpreter) jit_flags=""; tier2_flags="-D_Py_TIER2=4" ;; + interpreter-off) jit_flags=""; tier2_flags="-D_Py_TIER2=6" ;; # Secret option *) AC_MSG_ERROR( [invalid argument: --enable-experimental-jit=$enable_experimental_jit; expected no|yes|yes-off|interpreter]) ;; esac diff --git a/pyconfig.h.in b/pyconfig.h.in index ef4cf71b28102e..fcb8a965b1e476 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1695,10 +1695,6 @@ /* Defined if _Complex C type is available. */ #undef Py_HAVE_C_COMPLEX -/* Define to interpreter if you want to build an interpreter with enabled tier - 2 interpreter */ -#undef Py_JIT_ENABLED - /* Define if year with century should be normalized for strftime. */ #undef Py_NORMALIZE_CENTURY From 02d1f6049fb07ee10c784ee6837c0f2b8652761b Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 10 Nov 2024 05:03:07 +0200 Subject: [PATCH 20/31] Add ``sys._jit_enabled`` --- Include/internal/pycore_sysmodule.h | 4 ++ Lib/test/test_embed.py | 4 +- Python/clinic/sysmodule.c.h | 38 ++++++++++++++++++- Python/pylifecycle.c | 53 +++++++++++---------------- Python/sysmodule.c | 57 ++++++++++++++++++++++++++--- 5 files changed, 115 insertions(+), 41 deletions(-) diff --git a/Include/internal/pycore_sysmodule.h b/Include/internal/pycore_sysmodule.h index 99968df54a45f6..f5760a7d8079dc 100644 --- a/Include/internal/pycore_sysmodule.h +++ b/Include/internal/pycore_sysmodule.h @@ -22,6 +22,10 @@ extern int _PySys_ClearAttrString(PyInterpreterState *interp, extern int _PySys_SetFlagObj(Py_ssize_t pos, PyObject *new_value); extern int _PySys_SetIntMaxStrDigits(int maxdigits); +#if defined(_Py_TIER2) && (_Py_TIER2 % 2 != 0) +extern int _PySys_JITEnabled(void); +#endif + #ifdef __cplusplus } #endif diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index bf861ef06ee2d3..be3b45ee4fcecd 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1782,10 +1782,8 @@ def test_initconfig_api(self): 'perf_profiling': 2, } config_dev_mode(preconfig, config) - # Temporarily enable ignore_stderr=True to ignore warnings on JIT builds - # See gh-126255 for more information self.check_all_configs("test_initconfig_api", config, preconfig, - api=API_ISOLATED, ignore_stderr=True) + api=API_ISOLATED, env={'PYTHON_JIT': '0'}) def test_initconfig_get_api(self): self.run_embedded_interpreter("test_initconfig_get_api") diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h index 86c42ceffc5e31..37f62e5f9eca4c 100644 --- a/Python/clinic/sysmodule.c.h +++ b/Python/clinic/sysmodule.c.h @@ -1625,6 +1625,38 @@ sys__is_gil_enabled(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } +#if defined(_Py_TIER2) && (_Py_TIER2 % 2 != 0) + +PyDoc_STRVAR(sys__jit_enabled__doc__, +"_jit_enabled($module, /)\n" +"--\n" +"\n" +"Returns True if JIT is enabled, False otherwise."); + +#define SYS__JIT_ENABLED_METHODDEF \ + {"_jit_enabled", (PyCFunction)sys__jit_enabled, METH_NOARGS, sys__jit_enabled__doc__}, + +static int +sys__jit_enabled_impl(PyObject *module); + +static PyObject * +sys__jit_enabled(PyObject *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + int _return_value; + + _return_value = sys__jit_enabled_impl(module); + if ((_return_value == -1) && PyErr_Occurred()) { + goto exit; + } + return_value = PyBool_FromLong((long)_return_value); + +exit: + return return_value; +} + +#endif /* defined(_Py_TIER2) && (_Py_TIER2 % 2 != 0) */ + #ifndef SYS_GETWINDOWSVERSION_METHODDEF #define SYS_GETWINDOWSVERSION_METHODDEF #endif /* !defined(SYS_GETWINDOWSVERSION_METHODDEF) */ @@ -1668,4 +1700,8 @@ sys__is_gil_enabled(PyObject *module, PyObject *Py_UNUSED(ignored)) #ifndef SYS_GETANDROIDAPILEVEL_METHODDEF #define SYS_GETANDROIDAPILEVEL_METHODDEF #endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */ -/*[clinic end generated code: output=6d4f6cd20419b675 input=a9049054013a1b77]*/ + +#ifndef SYS__JIT_ENABLED_METHODDEF + #define SYS__JIT_ENABLED_METHODDEF +#endif /* !defined(SYS__JIT_ENABLED_METHODDEF) */ +/*[clinic end generated code: output=ddccb4b54c4d3e0e input=a9049054013a1b77]*/ diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 23882d083844ac..ad30a8d2d4d597 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1296,43 +1296,34 @@ init_interp_main(PyThreadState *tstate) #endif } - // Turn on experimental tier 2 (uops-based) optimizer - // This is also needed when the JIT is enabled +// Turn on experimental tier 2 (uops-based) optimizer +// This is also needed when the JIT is enabled #ifdef _Py_TIER2 if (is_main_interp) { - int enabled = 1; -#if _Py_TIER2 & 2 - enabled = 0; +// perf profiler works fine with tier 2 interpreter, so +// only checking for a "real JIT". +#if _Py_TIER % 2 != 0 + int enabled = _PySys_JITEnabled(); + printf("enabled = %d\n", enabled); + if (enabled && config->perf_profiling > 0) { + (void)PyErr_WarnEx( + PyExc_RuntimeWarning, + "JIT deactivated as perf profiling support is active", + 0); + } else #endif - char *env = Py_GETENV("PYTHON_JIT"); - if (env && *env != '\0') { - // PYTHON_JIT=0|1 overrides the default - enabled = *env != '0'; + { + PyObject *opt = _PyOptimizer_NewUOpOptimizer(); + if (opt == NULL) { + return _PyStatus_ERR("can't initialize optimizer"); } - if (enabled) { -#ifdef _Py_JIT - // perf profiler works fine with tier 2 interpreter, so - // only checking for a "real JIT". - if (config->perf_profiling > 0) { - (void)PyErr_WarnEx( - PyExc_RuntimeWarning, - "JIT deactivated as perf profiling support is active", - 0); - } else -#endif - { - PyObject *opt = _PyOptimizer_NewUOpOptimizer(); - if (opt == NULL) { - return _PyStatus_ERR("can't initialize optimizer"); - } - if (_Py_SetTier2Optimizer((_PyOptimizerObject *)opt)) { - return _PyStatus_ERR("can't install optimizer"); - } - Py_DECREF(opt); - } + if (_Py_SetTier2Optimizer((_PyOptimizerObject *)opt)) { + return _PyStatus_ERR("can't install optimizer"); } + Py_DECREF(opt); } -#endif +} +#endif // Py_TIER2 if (!is_main_interp) { // The main interpreter is handled in Py_Main(), for now. diff --git a/Python/sysmodule.c b/Python/sysmodule.c index aaef5aa532412b..340b8dd4602e7f 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2264,12 +2264,14 @@ sys_activate_stack_trampoline_impl(PyObject *module, const char *backend) /*[clinic end generated code: output=5783cdeb51874b43 input=a12df928758a82b4]*/ { #ifdef PY_HAVE_PERF_TRAMPOLINE -#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; +#if defined(_Py_TIER2) && (_Py_TIER2 % 2 != 0) + if (_PySys_JITEnabled()) { + _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; + } } #endif @@ -2533,6 +2535,46 @@ PyAPI_FUNC(int) PyUnstable_CopyPerfMapFile(const char* parent_filename) { } +#ifdef _Py_TIER2 +// _Py_TIER2 is set to 4 or 6 in tier 2 builds. +#if _Py_TIER2 % 2 != 0 +int +_PySys_JITEnabled(void) +{ + char *env = Py_GETENV("PYTHON_JIT"); + if (_Py_TIER2 == 1) { + // Interpreter was built with enabled jit, but it can be disabled via PYTHON_JIT=0 + if (env && *env != '\0') { + return *env != '0'; + } + return 1; + } + else if (_Py_TIER2 == 3) { + // Interpreter was built with disabled jit, but it can be enabled via PYTHON_JIT=1 + if (env && *env != '\0') { + return *env == '1'; + } + return 0; + } + Py_UNREACHABLE(); +} + +/*[clinic input] +sys._jit_enabled -> bool + +Returns True if JIT is enabled, False otherwise. +[clinic start generated code]*/ + +static int +sys__jit_enabled_impl(PyObject *module) +/*[clinic end generated code: output=e8adca3fa5011880 input=f2bdfa820c11f65b]*/ +{ + return _PySys_JITEnabled(); +} +#endif +#endif // _Py_TIER2 + + static PyMethodDef sys_methods[] = { /* Might as well keep this in alphabetic order */ SYS_ADDAUDITHOOK_METHODDEF @@ -2603,6 +2645,9 @@ static PyMethodDef sys_methods[] = { #endif SYS__GET_CPU_COUNT_CONFIG_METHODDEF SYS__IS_GIL_ENABLED_METHODDEF +#ifdef _Py_TIER2 + SYS__JIT_ENABLED_METHODDEF +#endif {NULL, NULL} // sentinel }; From a9c5b418fc10b4d5a02fe03fb822a7d3d8f55016 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 10 Nov 2024 05:04:02 +0200 Subject: [PATCH 21/31] Add a ``NEWS`` entry --- .../2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst new file mode 100644 index 00000000000000..def261ff8ea55b --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst @@ -0,0 +1 @@ +Add a :func:`!sys._jit_enabled` helper to determine in runtime if JIT is enabled or not. From 5423c71d8a05fc6934be22180b616fd053bcb9f9 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 10 Nov 2024 05:05:33 +0200 Subject: [PATCH 22/31] Fix typo --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 340b8dd4602e7f..70e57b890e9501 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2645,7 +2645,7 @@ static PyMethodDef sys_methods[] = { #endif SYS__GET_CPU_COUNT_CONFIG_METHODDEF SYS__IS_GIL_ENABLED_METHODDEF -#ifdef _Py_TIER2 +#if defined(_Py_TIER2) && (_Py_TIER2 % 2 != 0) SYS__JIT_ENABLED_METHODDEF #endif {NULL, NULL} // sentinel From 49336ab89cde97502ea2deb4503f8b5f6e346b3b Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 10 Nov 2024 17:26:56 +0200 Subject: [PATCH 23/31] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- .../2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst | 2 +- Python/pylifecycle.c | 13 ++++++------- Python/sysmodule.c | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst index def261ff8ea55b..a180de5cfa8b4c 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst @@ -1 +1 @@ -Add a :func:`!sys._jit_enabled` helper to determine in runtime if JIT is enabled or not. +Allow to determine whether the JIT is enabled at runtime via :func:`!sys._jit_enabled`. diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index ad30a8d2d4d597..1b2c1962cc1392 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1303,14 +1303,13 @@ init_interp_main(PyThreadState *tstate) // perf profiler works fine with tier 2 interpreter, so // only checking for a "real JIT". #if _Py_TIER % 2 != 0 - int enabled = _PySys_JITEnabled(); - printf("enabled = %d\n", enabled); - if (enabled && config->perf_profiling > 0) { + if (_PySys_JITEnabled() && config->perf_profiling > 0) { (void)PyErr_WarnEx( - PyExc_RuntimeWarning, - "JIT deactivated as perf profiling support is active", - 0); - } else + PyExc_RuntimeWarning, + "JIT deactivated as perf profiling support is active", + 0); + } + else #endif { PyObject *opt = _PyOptimizer_NewUOpOptimizer(); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 70e57b890e9501..d36844ebfd3eec 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2541,7 +2541,7 @@ PyAPI_FUNC(int) PyUnstable_CopyPerfMapFile(const char* parent_filename) { int _PySys_JITEnabled(void) { - char *env = Py_GETENV("PYTHON_JIT"); + const char *env = Py_GETENV("PYTHON_JIT"); if (_Py_TIER2 == 1) { // Interpreter was built with enabled jit, but it can be disabled via PYTHON_JIT=0 if (env && *env != '\0') { From 67123ee9ef36080935eca17b538130b7f9cd3a36 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 10 Nov 2024 17:34:25 +0200 Subject: [PATCH 24/31] Add documentation for sys._jit_enabled and what's new entry. --- Doc/library/sys.rst | 7 +++++++ Doc/whatsnew/3.14.rst | 3 +++ .../2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index d83816ec1502ca..2939d163f97521 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1235,6 +1235,13 @@ always available. .. versionadded:: 3.13 +.. function:: _jit_enabled() + Return :const:`True` if :ref:`JIT compiler ` is active. + Return :const:`False` otherwise. + + .. availability:: JIT builds, tier 2 interpreter doesn't count here. + + .. versionadded:: next .. function:: is_finalizing() diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index b9d2c27eb9a321..240cc7615ba5f1 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -443,6 +443,9 @@ sys which only exists in specialized builds of Python, may now return objects from other interpreters than the one it's called in. +* Add a :func:`sys._jit_enabled` which helps to determine in runtime if + :ref:`JIT compiler ` is active. + unicodedata ----------- diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst index a180de5cfa8b4c..07e3f4f2f9aca5 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-10-04-59-43.gh-issue-126204.ASKDL1.rst @@ -1 +1 @@ -Allow to determine whether the JIT is enabled at runtime via :func:`!sys._jit_enabled`. +Allow to determine whether the JIT is enabled at runtime via :func:`sys._jit_enabled`. From 4ddcd62fc47fef8a2e9773ed9ca47a30f31666fa Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 10 Nov 2024 17:40:35 +0200 Subject: [PATCH 25/31] ``availability`` only works for platforms :( --- Doc/library/sys.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 2939d163f97521..3b7675bc092383 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1239,7 +1239,7 @@ always available. Return :const:`True` if :ref:`JIT compiler ` is active. Return :const:`False` otherwise. - .. availability:: JIT builds, tier 2 interpreter doesn't count here. + Available only in JIT builds, tier 2 interpreter doesn't count here. .. versionadded:: next From aa8f5bb6f6c2942452ca57c6e7b6261b5ebf06cb Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 10 Nov 2024 18:20:28 +0200 Subject: [PATCH 26/31] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/sys.rst | 9 ++++++--- Doc/whatsnew/3.14.rst | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 3b7675bc092383..20f6074e13fedd 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1235,14 +1235,17 @@ always available. .. versionadded:: 3.13 + .. function:: _jit_enabled() - Return :const:`True` if :ref:`JIT compiler ` is active. - Return :const:`False` otherwise. - Available only in JIT builds, tier 2 interpreter doesn't count here. + Return :const:`True` if the :ref:`JIT compiler ` is active, + and :const:`False` otherwise. + + Available only in JIT builds; tier 2 interpreter does not count here. .. versionadded:: next + .. function:: is_finalizing() Return :const:`True` if the main Python interpreter is diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 240cc7615ba5f1..f74d5a49dfaf47 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -443,7 +443,7 @@ sys which only exists in specialized builds of Python, may now return objects from other interpreters than the one it's called in. -* Add a :func:`sys._jit_enabled` which helps to determine in runtime if +* Add :func:`sys._jit_enabled` to determine at runtime if the :ref:`JIT compiler ` is active. From 0b5bce8ad35f27a78c69a9e2e8a2c4a9f5d96395 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 10 Nov 2024 18:22:59 +0200 Subject: [PATCH 27/31] Align indentation --- Python/pylifecycle.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 1b2c1962cc1392..2437287bf0a118 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1311,16 +1311,16 @@ init_interp_main(PyThreadState *tstate) } else #endif - { - PyObject *opt = _PyOptimizer_NewUOpOptimizer(); - if (opt == NULL) { - return _PyStatus_ERR("can't initialize optimizer"); - } - if (_Py_SetTier2Optimizer((_PyOptimizerObject *)opt)) { - return _PyStatus_ERR("can't install optimizer"); + { + PyObject *opt = _PyOptimizer_NewUOpOptimizer(); + if (opt == NULL) { + return _PyStatus_ERR("can't initialize optimizer"); + } + if (_Py_SetTier2Optimizer((_PyOptimizerObject *)opt)) { + return _PyStatus_ERR("can't install optimizer"); + } + Py_DECREF(opt); } - Py_DECREF(opt); - } } #endif // Py_TIER2 From 0ffcd9f9ad68479e89aeebc545e62ed787b3f46a Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 10 Nov 2024 18:25:02 +0200 Subject: [PATCH 28/31] Remove unnecessary check --- Python/sysmodule.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index d36844ebfd3eec..92aff74eceb669 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2645,9 +2645,7 @@ static PyMethodDef sys_methods[] = { #endif SYS__GET_CPU_COUNT_CONFIG_METHODDEF SYS__IS_GIL_ENABLED_METHODDEF -#if defined(_Py_TIER2) && (_Py_TIER2 % 2 != 0) SYS__JIT_ENABLED_METHODDEF -#endif {NULL, NULL} // sentinel }; From b6c097b1419bbf96c725e723a9a27d29846f14ed Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sun, 10 Nov 2024 19:05:11 +0200 Subject: [PATCH 29/31] Update Python/pylifecycle.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Python/pylifecycle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 2437287bf0a118..10c6131a00e77e 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1321,7 +1321,7 @@ init_interp_main(PyThreadState *tstate) } Py_DECREF(opt); } -} + } #endif // Py_TIER2 if (!is_main_interp) { From b4dc9dc3ce1b5b6c3a230fb72d8af06366882c70 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Mon, 11 Nov 2024 07:57:35 +0200 Subject: [PATCH 30/31] Update Python/sysmodule.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 92aff74eceb669..0589d1a24ca93f 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2266,7 +2266,7 @@ sys_activate_stack_trampoline_impl(PyObject *module, const char *backend) #ifdef PY_HAVE_PERF_TRAMPOLINE #if defined(_Py_TIER2) && (_Py_TIER2 % 2 != 0) if (_PySys_JITEnabled()) { - _PyOptimizerObject* optimizer = _Py_GetOptimizer(); + _PyOptimizerObject *optimizer = _Py_GetOptimizer(); if (optimizer != NULL) { Py_DECREF(optimizer); PyErr_SetString(PyExc_ValueError, "Cannot activate the perf trampoline if the JIT is active"); From 46a4a7f30097e232c26621c9cf684b7e66cd4305 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Mon, 11 Nov 2024 23:25:02 +0200 Subject: [PATCH 31/31] Fix reference leak in error path --- Python/pylifecycle.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 10c6131a00e77e..f4090dba20cb3c 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1317,6 +1317,7 @@ init_interp_main(PyThreadState *tstate) return _PyStatus_ERR("can't initialize optimizer"); } if (_Py_SetTier2Optimizer((_PyOptimizerObject *)opt)) { + Py_DECREF(opt); return _PyStatus_ERR("can't install optimizer"); } Py_DECREF(opt);