From 8a29b982f0f2de02a37f0d7bdb4a46f009995bd1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 17 Oct 2023 10:59:24 +0200 Subject: [PATCH 1/2] gh-110968: Py_MOD_PER_INTERPRETER_GIL_SUPPORTED new in 3.13. * Only add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED to limited C API version 3.13. * errno, xxlimited and _ctypes_test extensions now need the limited C API version 3.13 to get Py_MOD_PER_INTERPRETER_GIL_SUPPORTED. They now include standard header files explicitly: , and . * xxlimited_35: Remove Py_mod_multiple_interpreters slot, incompatible with limited C API version 3.5. --- Include/moduleobject.h | 6 ++++-- Modules/_ctypes/_ctypes_test.c | 5 ++++- Modules/errnomodule.c | 5 +++-- Modules/xxlimited.c | 2 +- Modules/xxlimited_35.c | 1 - 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Include/moduleobject.h b/Include/moduleobject.h index ea08145381cee6..2f7dc254466c46 100644 --- a/Include/moduleobject.h +++ b/Include/moduleobject.h @@ -79,12 +79,14 @@ struct PyModuleDef_Slot { #define _Py_mod_LAST_SLOT 3 #endif +#endif /* New in 3.5 */ + /* for Py_mod_multiple_interpreters: */ +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000 #define Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED ((void *)0) #define Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED ((void *)1) #define Py_MOD_PER_INTERPRETER_GIL_SUPPORTED ((void *)2) - -#endif /* New in 3.5 */ +#endif struct PyModuleDef { PyModuleDef_Base m_base; diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c index 11c7a6b8926214..5473310ded0734 100644 --- a/Modules/_ctypes/_ctypes_test.c +++ b/Modules/_ctypes/_ctypes_test.c @@ -1,8 +1,11 @@ -#define Py_LIMITED_API 0x03060000 +// Need limited C API version 3.13 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED +#define Py_LIMITED_API 0x030d0000 #include +#include // printf() #include // qsort() +#include // memset() #ifdef MS_WIN32 # include #endif diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c index 25cd7e9ae0e122..e4fd3b47762702 100644 --- a/Modules/errnomodule.c +++ b/Modules/errnomodule.c @@ -1,9 +1,10 @@ /* Errno module */ -// Need PyModuleDef_Slot added to limited C API version 3.5 -#define Py_LIMITED_API 0x03050000 +// Need limited C API version 3.13 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED +#define Py_LIMITED_API 0x030d0000 #include "Python.h" +#include // EPIPE /* Windows socket errors (WSA*) */ #ifdef MS_WINDOWS diff --git a/Modules/xxlimited.c b/Modules/xxlimited.c index 3935c00fc26530..6d1ced8fb4a664 100644 --- a/Modules/xxlimited.c +++ b/Modules/xxlimited.c @@ -62,7 +62,7 @@ pass */ -#define Py_LIMITED_API 0x030b0000 +#define Py_LIMITED_API 0x030d0000 #include "Python.h" #include diff --git a/Modules/xxlimited_35.c b/Modules/xxlimited_35.c index 1ff3ef1cb6f296..361c7e76d77f50 100644 --- a/Modules/xxlimited_35.c +++ b/Modules/xxlimited_35.c @@ -293,7 +293,6 @@ xx_modexec(PyObject *m) static PyModuleDef_Slot xx_slots[] = { {Py_mod_exec, xx_modexec}, - {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, {0, NULL} }; From 89b61592d7700f0eb7adc451739d79fc78296c15 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 17 Oct 2023 11:47:59 +0200 Subject: [PATCH 2/2] Add comment --- Modules/xxlimited.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/xxlimited.c b/Modules/xxlimited.c index 6d1ced8fb4a664..df6e593b320e52 100644 --- a/Modules/xxlimited.c +++ b/Modules/xxlimited.c @@ -62,6 +62,7 @@ pass */ +// Need limited C API version 3.13 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED #define Py_LIMITED_API 0x030d0000 #include "Python.h"