]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-116322: Add Py_mod_gil module slot (#116882)
authorBrett Simmers <swtaarrs@users.noreply.github.com>
Fri, 3 May 2024 15:30:55 +0000 (08:30 -0700)
committerGitHub <noreply@github.com>
Fri, 3 May 2024 15:30:55 +0000 (11:30 -0400)
This PR adds the ability to enable the GIL if it was disabled at
interpreter startup, and modifies the multi-phase module initialization
path to enable the GIL when loading a module, unless that module's spec
includes a slot indicating it can run safely without the GIL.

PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went
with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148.

A warning will be issued up to once per interpreter for the first
GIL-using module that is loaded. If `-v` is given, a shorter message
will be printed to stderr every time a GIL-using module is loaded
(including the first one that issues a warning).

123 files changed:
Doc/c-api/module.rst
Include/internal/pycore_moduleobject.h
Include/moduleobject.h
Lib/test/test_importlib/extension/_test_nonmodule_cases.py [new file with mode: 0644]
Lib/test/test_importlib/extension/test_loader.py
Lib/test/test_sys.py
Misc/NEWS.d/next/Core and Builtins/2024-03-12-13-51-09.gh-issue-116322.q8TcDQ.rst [new file with mode: 0644]
Modules/_abc.c
Modules/_asynciomodule.c
Modules/_bisectmodule.c
Modules/_blake2/blake2module.c
Modules/_bz2module.c
Modules/_codecsmodule.c
Modules/_collectionsmodule.c
Modules/_contextvarsmodule.c
Modules/_csv.c
Modules/_ctypes/_ctypes.c
Modules/_ctypes/_ctypes_test.c
Modules/_curses_panel.c
Modules/_cursesmodule.c
Modules/_datetimemodule.c
Modules/_dbmmodule.c
Modules/_decimal/_decimal.c
Modules/_elementtree.c
Modules/_functoolsmodule.c
Modules/_gdbmmodule.c
Modules/_hashopenssl.c
Modules/_heapqmodule.c
Modules/_interpchannelsmodule.c
Modules/_interpqueuesmodule.c
Modules/_interpretersmodule.c
Modules/_io/_iomodule.c
Modules/_json.c
Modules/_localemodule.c
Modules/_lsprof.c
Modules/_lzmamodule.c
Modules/_multiprocessing/multiprocessing.c
Modules/_multiprocessing/posixshmem.c
Modules/_opcode.c
Modules/_operator.c
Modules/_pickle.c
Modules/_posixsubprocess.c
Modules/_queuemodule.c
Modules/_randommodule.c
Modules/_scproxy.c
Modules/_sqlite/module.c
Modules/_sre/sre.c
Modules/_ssl.c
Modules/_stat.c
Modules/_statisticsmodule.c
Modules/_struct.c
Modules/_suggestions.c
Modules/_sysconfig.c
Modules/_testbuffer.c
Modules/_testcapimodule.c
Modules/_testclinic.c
Modules/_testclinic_limited.c
Modules/_testexternalinspection.c
Modules/_testimportmultiple.c
Modules/_testinternalcapi.c
Modules/_testlimitedcapi.c
Modules/_testmultiphase.c
Modules/_testsinglephase.c
Modules/_threadmodule.c
Modules/_tkinter.c
Modules/_tracemalloc.c
Modules/_typingmodule.c
Modules/_uuidmodule.c
Modules/_weakref.c
Modules/_winapi.c
Modules/_xxtestfuzz/_xxtestfuzz.c
Modules/_zoneinfo.c
Modules/arraymodule.c
Modules/atexitmodule.c
Modules/binascii.c
Modules/cjkcodecs/cjkcodecs.h
Modules/cjkcodecs/multibytecodec.c
Modules/cmathmodule.c
Modules/errnomodule.c
Modules/faulthandler.c
Modules/fcntlmodule.c
Modules/gcmodule.c
Modules/grpmodule.c
Modules/itertoolsmodule.c
Modules/mathmodule.c
Modules/md5module.c
Modules/mmapmodule.c
Modules/overlapped.c
Modules/posixmodule.c
Modules/pwdmodule.c
Modules/pyexpat.c
Modules/readline.c
Modules/resource.c
Modules/selectmodule.c
Modules/sha1module.c
Modules/sha2module.c
Modules/sha3module.c
Modules/signalmodule.c
Modules/socketmodule.c
Modules/symtablemodule.c
Modules/syslogmodule.c
Modules/termios.c
Modules/timemodule.c
Modules/unicodedata.c
Modules/xxlimited.c
Modules/xxlimited_35.c
Modules/xxmodule.c
Modules/xxsubtype.c
Modules/zlibmodule.c
Objects/moduleobject.c
Objects/unicodeobject.c
PC/_testconsole.c
PC/msvcrtmodule.c
PC/winreg.c
PC/winsound.c
Parser/asdl_c.py
Python/Python-ast.c
Python/Python-tokenize.c
Python/_warnings.c
Python/bltinmodule.c
Python/import.c
Python/marshal.c
Python/sysmodule.c

index 979b22261efa3b3f34e939d521685ed928c355ba..86308d921f47f2f2222cb28c1d7269780a7373ee 100644 (file)
@@ -411,6 +411,31 @@ The available slot types are:
 
    .. versionadded:: 3.12
 
+.. c:macro:: Py_mod_gil
+
+   Specifies one of the following values:
+
+   .. c:macro:: Py_MOD_GIL_USED
+
+      The module depends on the presence of the global interpreter lock (GIL),
+      and may access global state without synchronization.
+
+   .. c:macro:: Py_MOD_GIL_NOT_USED
+
+      The module is safe to run without an active GIL.
+
+   This slot is ignored by Python builds not configured with
+   :option:`--disable-gil`.  Otherwise, it determines whether or not importing
+   this module will cause the GIL to be automatically enabled. See
+   :envvar:`PYTHON_GIL` and :option:`-X gil <-X>` for more detail.
+
+   Multiple ``Py_mod_gil`` slots may not be specified in one module definition.
+
+   If ``Py_mod_gil`` is not specified, the import machinery defaults to
+   ``Py_MOD_GIL_USED``.
+
+   .. versionadded: 3.13
+
 See :PEP:`489` for more details on multi-phase initialization.
 
 Low-level module creation functions
@@ -609,6 +634,19 @@ state:
 
    .. versionadded:: 3.9
 
+.. c:function:: int PyModule_ExperimentalSetGIL(PyObject *module, void *gil)
+
+   Indicate that *module* does or does not support running without the global
+   interpreter lock (GIL), using one of the values from
+   :c:macro:`Py_mod_gil`. It must be called during *module*'s initialization
+   function. If this function is not called during module initialization, the
+   import machinery assumes the module does not support running without the
+   GIL. This function is only available in Python builds configured with
+   :option:`--disable-gil`.
+   Return ``-1`` on error, ``0`` on success.
+
+   .. versionadded:: 3.13
+
 
 Module lookup
 ^^^^^^^^^^^^^
index 5644bbe5e0552bdd432dd85dcff8a7b0da130e38..049677b292e23520e64c5f7d5192738a51365b85 100644 (file)
@@ -22,6 +22,9 @@ typedef struct {
     PyObject *md_weaklist;
     // for logging purposes after md_dict is cleared
     PyObject *md_name;
+#ifdef Py_GIL_DISABLED
+    void *md_gil;
+#endif
 } PyModuleObject;
 
 static inline PyModuleDef* _PyModule_GetDef(PyObject *mod) {
index 83f8c2030dbb8ff8d74809527ce048319492f794..6afa3c7be37ee7c3de325ffa5c1e94c21013ec4c 100644 (file)
@@ -76,9 +76,13 @@ struct PyModuleDef_Slot {
 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030c0000
 #  define Py_mod_multiple_interpreters 3
 #endif
+#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
+#  define Py_mod_gil 4
+#endif
+
 
 #ifndef Py_LIMITED_API
-#define _Py_mod_LAST_SLOT 3
+#define _Py_mod_LAST_SLOT 4
 #endif
 
 #endif /* New in 3.5 */
@@ -90,6 +94,16 @@ struct PyModuleDef_Slot {
 #  define Py_MOD_PER_INTERPRETER_GIL_SUPPORTED ((void *)2)
 #endif
 
+/* for Py_mod_gil: */
+#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
+#  define Py_MOD_GIL_USED ((void *)0)
+#  define Py_MOD_GIL_NOT_USED ((void *)1)
+#endif
+
+#if !defined(Py_LIMITED_API) && defined(Py_GIL_DISABLED)
+PyAPI_FUNC(int) PyModule_ExperimentalSetGIL(PyObject *module, void *gil);
+#endif
+
 struct PyModuleDef {
   PyModuleDef_Base m_base;
   const char* m_name;
diff --git a/Lib/test/test_importlib/extension/_test_nonmodule_cases.py b/Lib/test/test_importlib/extension/_test_nonmodule_cases.py
new file mode 100644 (file)
index 0000000..8ffd18d
--- /dev/null
@@ -0,0 +1,44 @@
+import types
+import unittest
+from test.test_importlib import util
+
+machinery = util.import_importlib('importlib.machinery')
+
+from test.test_importlib.extension.test_loader import MultiPhaseExtensionModuleTests
+
+
+class NonModuleExtensionTests:
+    setUp = MultiPhaseExtensionModuleTests.setUp
+    load_module_by_name = MultiPhaseExtensionModuleTests.load_module_by_name
+
+    def _test_nonmodule(self):
+        # Test returning a non-module object from create works.
+        name = self.name + '_nonmodule'
+        mod = self.load_module_by_name(name)
+        self.assertNotEqual(type(mod), type(unittest))
+        self.assertEqual(mod.three, 3)
+
+    # issue 27782
+    def test_nonmodule_with_methods(self):
+        # Test creating a non-module object with methods defined.
+        name = self.name + '_nonmodule_with_methods'
+        mod = self.load_module_by_name(name)
+        self.assertNotEqual(type(mod), type(unittest))
+        self.assertEqual(mod.three, 3)
+        self.assertEqual(mod.bar(10, 1), 9)
+
+    def test_null_slots(self):
+        # Test that NULL slots aren't a problem.
+        name = self.name + '_null_slots'
+        module = self.load_module_by_name(name)
+        self.assertIsInstance(module, types.ModuleType)
+        self.assertEqual(module.__name__, name)
+
+
+(Frozen_NonModuleExtensionTests,
+ Source_NonModuleExtensionTests
+ ) = util.test_both(NonModuleExtensionTests, machinery=machinery)
+
+
+if __name__ == '__main__':
+    unittest.main()
index 7607f0e085759599070177022e0fd378f75a8e04..0dd21e079eba224758a13c2427b1d5adb67ef75c 100644 (file)
@@ -10,7 +10,8 @@ import unittest
 import warnings
 import importlib.util
 import importlib
-from test.support import MISSING_C_DOCSTRINGS
+from test import support
+from test.support import MISSING_C_DOCSTRINGS, script_helper
 
 
 class LoaderTests:
@@ -325,29 +326,6 @@ class MultiPhaseExtensionModuleTests(abc.LoaderTests):
             self.load_module_by_name(name)
         self.assertEqual(cm.exception.name, name)
 
-    def test_nonmodule(self):
-        # Test returning a non-module object from create works.
-        name = self.name + '_nonmodule'
-        mod = self.load_module_by_name(name)
-        self.assertNotEqual(type(mod), type(unittest))
-        self.assertEqual(mod.three, 3)
-
-    # issue 27782
-    def test_nonmodule_with_methods(self):
-        # Test creating a non-module object with methods defined.
-        name = self.name + '_nonmodule_with_methods'
-        mod = self.load_module_by_name(name)
-        self.assertNotEqual(type(mod), type(unittest))
-        self.assertEqual(mod.three, 3)
-        self.assertEqual(mod.bar(10, 1), 9)
-
-    def test_null_slots(self):
-        # Test that NULL slots aren't a problem.
-        name = self.name + '_null_slots'
-        module = self.load_module_by_name(name)
-        self.assertIsInstance(module, types.ModuleType)
-        self.assertEqual(module.__name__, name)
-
     def test_bad_modules(self):
         # Test SystemError is raised for misbehaving extensions.
         for name_base in [
@@ -401,5 +379,14 @@ class MultiPhaseExtensionModuleTests(abc.LoaderTests):
  ) = util.test_both(MultiPhaseExtensionModuleTests, machinery=machinery)
 
 
+class NonModuleExtensionTests(unittest.TestCase):
+    def test_nonmodule_cases(self):
+        # The test cases in this file cause the GIL to be enabled permanently
+        # in free-threaded builds, so they are run in a subprocess to isolate
+        # this effect.
+        script = support.findfile("test_importlib/extension/_test_nonmodule_cases.py")
+        script_helper.run_test_script(script)
+
+
 if __name__ == '__main__':
     unittest.main()
index df0a6f09c09c082641b089276b2e36691b35226b..73912767ae25b74aab99dacf72ad8b5c6ae6af0f 100644 (file)
@@ -1606,7 +1606,10 @@ class SizeofTest(unittest.TestCase):
         check(int(PyLong_BASE**2-1), vsize('') + 2*self.longdigit)
         check(int(PyLong_BASE**2), vsize('') + 3*self.longdigit)
         # module
-        check(unittest, size('PnPPP'))
+        if support.Py_GIL_DISABLED:
+            check(unittest, size('PPPPPP'))
+        else:
+            check(unittest, size('PPPPP'))
         # None
         check(None, size(''))
         # NotImplementedType
diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-03-12-13-51-09.gh-issue-116322.q8TcDQ.rst b/Misc/NEWS.d/next/Core and Builtins/2024-03-12-13-51-09.gh-issue-116322.q8TcDQ.rst
new file mode 100644 (file)
index 0000000..2d3bf41
--- /dev/null
@@ -0,0 +1,5 @@
+Extension modules may indicate to the runtime that they can run without the
+GIL. Multi-phase init modules do so by calling providing
+``Py_MOD_GIL_NOT_USED`` for the ``Py_mod_gil`` slot, while single-phase init
+modules call ``PyModule_ExperimentalSetGIL(mod, Py_MOD_GIL_NOT_USED)`` from
+their init function.
index f2a523e6f2fc273d0a76984fa0324a67eef6017b..4f4b24b035db4af0ac649a15935b9878ff18010c 100644 (file)
@@ -970,6 +970,7 @@ _abcmodule_free(void *module)
 static PyModuleDef_Slot _abcmodule_slots[] = {
     {Py_mod_exec, _abcmodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 0873d32a9ec1a5b8951bb3515a64a29048264a83..a26714f9755df5f0cd750e00a3124ab0b42f2ae8 100644 (file)
@@ -3795,6 +3795,7 @@ module_exec(PyObject *mod)
 static struct PyModuleDef_Slot module_slots[] = {
     {Py_mod_exec, module_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index 9e0fd336419b44683ceaeab454515f54003d4071..56322c48b7cd354cdd035f0762c842aa44b6f870 100644 (file)
@@ -462,6 +462,7 @@ bisect_modexec(PyObject *m)
 static PyModuleDef_Slot bisect_slots[] = {
     {Py_mod_exec, bisect_modexec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 5df9fd3df493eebd6a1a1e0a174083ac078a2208..78242214764f2bb2888a1468ddc42f4c6948d81d 100644 (file)
@@ -137,6 +137,7 @@ blake2_exec(PyObject *m)
 static PyModuleDef_Slot _blake2_slots[] = {
     {Py_mod_exec, blake2_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 3d0d4ee5e79c2bb5634d5474b11cc6ec153ca3f3..661847ad26702ee550421236de940ceac55f1a8f 100644 (file)
@@ -802,6 +802,7 @@ _bz2_free(void *module)
 static struct PyModuleDef_Slot _bz2_slots[] = {
     {Py_mod_exec, _bz2_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index c31c1b6d6f2bbc0070189e43c308905b2f47be03..32373f0799bfeb8bdd258e8f6907e2502c269bda 100644 (file)
@@ -1050,6 +1050,7 @@ static PyMethodDef _codecs_functions[] = {
 
 static PyModuleDef_Slot _codecs_slots[] = {
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 309d63c9bf7cbe790461d7ac2391952a346d7dd3..b865351c93d2d8b8327b0fc4eaad142618f37f26 100644 (file)
@@ -2817,6 +2817,7 @@ collections_exec(PyObject *module) {
 static struct PyModuleDef_Slot collections_slots[] = {
     {Py_mod_exec, collections_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index f621c1de6d42d6b14b39c5f5e94f9abad4c6efd0..3f96f07909b69a6087d77000badc227ebaedfcc6 100644 (file)
@@ -45,6 +45,7 @@ _contextvars_exec(PyObject *m)
 static struct PyModuleDef_Slot _contextvars_slots[] = {
     {Py_mod_exec, _contextvars_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index ac948f417cebf51a57aa96d5386057251690823a..9d6b66d4938687ce79f834dff7e29446ae4e7b71 100644 (file)
@@ -1796,6 +1796,7 @@ csv_exec(PyObject *module) {
 static PyModuleDef_Slot csv_slots[] = {
     {Py_mod_exec, csv_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 3cb0b24668eb2aa9a3b40fed59edccb0caec2ec4..1b1a0ea549f1e162c9b3d00cb1aa42f6895f5a8e 100644 (file)
@@ -5948,6 +5948,7 @@ module_free(void *module)
 static PyModuleDef_Slot module_slots[] = {
     {Py_mod_exec, _ctypes_mod_exec},
     {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 1dd3ef1905247010b5f7540b2fd7775eebbd5e74..f46f6362ddd03b145a138c8eac768e45d49fa147 100644 (file)
@@ -1,7 +1,7 @@
-// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
+// Need limited C API version 3.13 for Py_mod_gil
 #include "pyconfig.h"   // Py_GIL_DISABLED
 #ifndef Py_GIL_DISABLED
-#  define Py_LIMITED_API 0x030c0000
+#  define Py_LIMITED_API 0x030d0000
 #endif
 
 // gh-85283: On Windows, Py_LIMITED_API requires Py_BUILD_CORE to not attempt
@@ -1167,6 +1167,7 @@ _testfunc_pylist_append(PyObject *list, PyObject *item)
 
 static struct PyModuleDef_Slot _ctypes_test_slots[] = {
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 2ec8f34c5c220b0558100c1935160cb955ad9b35..125c72dbbe771216639d578fa3a40dacd5848fd3 100644 (file)
@@ -697,6 +697,7 @@ static PyModuleDef_Slot _curses_slots[] = {
     // XXX gh-103092: fix isolation.
     {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
     //{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index d04d1e973af03036a392f2836479dba41f092f56..8bf6824b6d83ffa8f19a6a580c95845f24e5c604 100644 (file)
@@ -4743,6 +4743,9 @@ PyInit__curses(void)
     m = PyModule_Create(&_cursesmodule);
     if (m == NULL)
         return NULL;
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(m, Py_MOD_GIL_NOT_USED);
+#endif
 
     /* Add some symbolic constants to the module */
     d = PyModule_GetDict(m);
index 06004e258b2eff90390189d949d6769489568516..00015c5d8c23cbca5e46d085435a90e26b3dd87d 100644 (file)
@@ -6984,6 +6984,9 @@ PyInit__datetime(void)
     PyObject *mod = PyModule_Create(&datetimemodule);
     if (mod == NULL)
         return NULL;
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(mod, Py_MOD_GIL_NOT_USED);
+#endif
 
     if (_datetime_exec(mod) < 0) {
         Py_DECREF(mod);
index ee33fe625be3d707e3ca9216cfa0eb5fd3aa45d2..1be4234aad3291bda0c5170090ae4dcad847748e 100644 (file)
@@ -616,6 +616,7 @@ _dbm_module_free(void *module)
 static PyModuleDef_Slot _dbmmodule_slots[] = {
     {Py_mod_exec, _dbm_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index fe6711143b845b1d34932964e1cfa1c92f3f7a90..2daa24c823a54287b5b5b23a4307a64765072e14 100644 (file)
@@ -6157,6 +6157,7 @@ decimal_free(void *module)
 static struct PyModuleDef_Slot _decimal_slots[] = {
     {Py_mod_exec, _decimal_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index aaa0cad76ae5c4bd8515036e41f5548fd9e7bb4d..b11983d2caa2d1c82ae3c2ca6a60f5d91bdbf85e 100644 (file)
@@ -4463,6 +4463,7 @@ error:
 static struct PyModuleDef_Slot elementtree_slots[] = {
     {Py_mod_exec, module_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index e37473a582b55fba0f2cf0a7cda51288723911de..9dee7bf30627100712465eddfa6301458e8e07e6 100644 (file)
@@ -1559,6 +1559,7 @@ _functools_free(void *module)
 static struct PyModuleDef_Slot _functools_slots[] = {
     {Py_mod_exec, _functools_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index db868c18160fdadc83509392c75cb2529257c86b..df7fba67810ed04c84bce8134d0553bf117d4af7 100644 (file)
@@ -825,6 +825,7 @@ _gdbm_module_free(void *module)
 static PyModuleDef_Slot _gdbm_module_slots[] = {
     {Py_mod_exec, _gdbm_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index d0b46810dc148959579d81d837bdace910dbbe49..14d9c186151232c48fe1662c6721957cf0a77044 100644 (file)
@@ -2289,6 +2289,7 @@ static PyModuleDef_Slot hashlib_slots[] = {
     {Py_mod_exec, hashlib_init_constructors},
     {Py_mod_exec, hashlib_exception},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 9d4ec256ee9e3eff61ed34bf4cfb34d809a98484..695ce22f8049df8dfc80bc374926e8d137e5736c 100644 (file)
@@ -681,6 +681,7 @@ heapq_exec(PyObject *m)
 static struct PyModuleDef_Slot heapq_slots[] = {
     {Py_mod_exec, heapq_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 43c96584790fa058ab50e3d95daa34f1fcc3a4d2..ff8dacf5bd1ad0e681f3b002aa6303096a4509e2 100644 (file)
@@ -3326,6 +3326,7 @@ error:
 static struct PyModuleDef_Slot module_slots[] = {
     {Py_mod_exec, module_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index 46801bd416495a61580c612e288719f12d53cfbc..556953db6b803940d63a019bb29e570d274b2083 100644 (file)
@@ -1830,6 +1830,7 @@ error:
 static struct PyModuleDef_Slot module_slots[] = {
     {Py_mod_exec, module_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index 8fea56977ef3fe1c22838dc08ca6e88a6a6379b9..86a4113dcc16f1d69e5b672df4ba01730c591c42 100644 (file)
@@ -1519,6 +1519,7 @@ error:
 static struct PyModuleDef_Slot module_slots[] = {
     {Py_mod_exec, module_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index 173f5b55e5f732f6159e78bf12fc73f74c4850ed..269070fe2b0a4244e33673cd35da60f0d0565400 100644 (file)
@@ -720,6 +720,7 @@ iomodule_exec(PyObject *m)
 static struct PyModuleDef_Slot iomodule_slots[] = {
     {Py_mod_exec, iomodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index c55299899e77fe5c444e2b9719830cf047a7b271..fc39f624b723f5023c3ad0b64df8e9d8ac2a2dfc 100644 (file)
@@ -1780,6 +1780,7 @@ _json_exec(PyObject *module)
 static PyModuleDef_Slot _json_slots[] = {
     {Py_mod_exec, _json_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index fe8e4c5e30035b369d195cd37356a95c52bc46b5..d4923442478b3ec93902d921f9073c030b4e599e 100644 (file)
@@ -860,6 +860,7 @@ _locale_exec(PyObject *module)
 static struct PyModuleDef_Slot _locale_slots[] = {
     {Py_mod_exec, _locale_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index a76c3dea55578390ab1196de1eccab28a45837d3..18be01df5c13777dc796d45ba645dd0b484b9841 100644 (file)
@@ -1006,6 +1006,7 @@ _lsprof_exec(PyObject *module)
 static PyModuleDef_Slot _lsprofslots[] = {
     {Py_mod_exec, _lsprof_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index f6bfbfa62687b8ba83de558a4c99f3b042f1b485..97f3a8f03da9a86c776655a3f9364cdc756c17cd 100644 (file)
@@ -1604,6 +1604,7 @@ static PyMethodDef lzma_methods[] = {
 static PyModuleDef_Slot lzma_slots[] = {
     {Py_mod_exec, lzma_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 1f6ab718a36984a961b34dcde86ee7ab2afadb5d..cee8cf7b9a83c0651b79e221edda3e0a49e01f2e 100644 (file)
@@ -277,6 +277,7 @@ multiprocessing_exec(PyObject *module)
 static PyModuleDef_Slot multiprocessing_slots[] = {
     {Py_mod_exec, multiprocessing_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index d332a4e9d9ea0b8ff0b143e4fe2b9a69bd72989f..aeb2d79de6f9ed5b27fa0baeb739eda9d287f564 100644 (file)
@@ -2,10 +2,10 @@
 posixshmem - A Python extension that provides shm_open() and shm_unlink()
 */
 
-// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
+// Need limited C API version 3.13 for Py_mod_gil
 #include "pyconfig.h"   // Py_GIL_DISABLED
 #ifndef Py_GIL_DISABLED
-#  define Py_LIMITED_API 0x030c0000
+#  define Py_LIMITED_API 0x030d0000
 #endif
 
 #include <Python.h>
@@ -128,6 +128,7 @@ static PyMethodDef module_methods[ ] = {
 
 static PyModuleDef_Slot module_slots[] = {
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 85e0ffec900e89f9c2bf58fea63db9cb70815a12..cc72cb170ceaed434ebd5ace766d4367c5e72e31 100644 (file)
@@ -406,6 +406,7 @@ _opcode_exec(PyObject *m) {
 static PyModuleDef_Slot module_slots[] = {
     {Py_mod_exec, _opcode_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 306d4508f52a686f73cddbf3a1d22a33b8c113eb..5d3f88327d19ad7c3dc97260bd23df3b542e5e45 100644 (file)
@@ -1928,6 +1928,7 @@ operator_exec(PyObject *module)
 static struct PyModuleDef_Slot operator_slots[] = {
     {Py_mod_exec, operator_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index d7ffb04c28c2ac3caedeea29dcdb45dc9de8867c..754a326822e0f02c791095bd1b46d676358fd6e8 100644 (file)
@@ -7863,6 +7863,7 @@ _pickle_exec(PyObject *m)
 static PyModuleDef_Slot pickle_slots[] = {
     {Py_mod_exec, _pickle_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index b160cd78177a175ee05c8fef60814b827d722f30..daec4ad708dea46efcb7a859e88b5c6ad62f4e1f 100644 (file)
@@ -1317,6 +1317,7 @@ static PyMethodDef module_methods[] = {
 
 static PyModuleDef_Slot _posixsubprocess_slots[] = {
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 5db9b645849fcd8a8f8ce6277721d6a68e2fb20d..aee8db802d8c3f57bb5b290d223b1099ce426603 100644 (file)
@@ -594,6 +594,7 @@ queuemodule_exec(PyObject *module)
 static PyModuleDef_Slot queuemodule_slots[] = {
     {Py_mod_exec, queuemodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 56b891dfe0f85f84a65a79214d107fe991f66e1c..140640ae8fbf3a62a49fd9af39cb7b8a7d320694 100644 (file)
@@ -642,6 +642,7 @@ _random_exec(PyObject *module)
 static PyModuleDef_Slot _random_slots[] = {
     {Py_mod_exec, _random_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 042738b4ab83a2eca15f58ea39394cb132aad871..e9170f2ce1ae87216b003a5b7b47db03acc93ce3 100644 (file)
@@ -3,10 +3,10 @@
  * using the SystemConfiguration framework.
  */
 
-// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
+// Need limited C API version 3.13 for Py_mod_gil
 #include "pyconfig.h"   // Py_GIL_DISABLED
 #ifndef Py_GIL_DISABLED
-#  define Py_LIMITED_API 0x030c0000
+#  define Py_LIMITED_API 0x030d0000
 #endif
 
 #include <Python.h>
@@ -239,6 +239,7 @@ static PyMethodDef mod_methods[] = {
 
 static PyModuleDef_Slot _scproxy_slots[] = {
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 46fed9f13281f39159ae527f6062e3cddef2ba2c..2c25ee32e58189c73d276aa82e2b24b88628042b 100644 (file)
@@ -758,6 +758,7 @@ error:
 static struct PyModuleDef_Slot module_slots[] = {
     {Py_mod_exec, module_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index 00fbd9674b8cddaaa580061d40cc8309ec15e0b7..c1eff63d921de94cf128feed71689c7bbb1b82e8 100644 (file)
@@ -3272,6 +3272,7 @@ error:
 static PyModuleDef_Slot sre_slots[] = {
     {Py_mod_exec, sre_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index 885a9c25967d2d787135abd144fd6d0845e45600..9d50b576ba337f4ce0784b9d694a5e201cdcc470 100644 (file)
@@ -6515,6 +6515,7 @@ static PyModuleDef_Slot sslmodule_slots[] = {
     {Py_mod_exec, sslmodule_init_strings},
     {Py_mod_exec, sslmodule_init_lock},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 8059ec2f1f066db21185119452f5e2b16640d273..a4f15e8e65e89477dceb77a9f2b479c9358916b3 100644 (file)
@@ -679,6 +679,7 @@ stat_exec(PyObject *module)
 static PyModuleDef_Slot stat_slots[] = {
     {Py_mod_exec, stat_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 78a6552c4c9ec0c0a136c9a4a8801045ebff7e12..b84f731ad6a1da88f16826fa4c5f2aff300707e2 100644 (file)
@@ -1,9 +1,9 @@
 /* statistics accelerator C extension: _statistics module. */
 
-// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
+// Need limited C API version 3.13 for Py_mod_gil
 #include "pyconfig.h"   // Py_GIL_DISABLED
 #ifndef Py_GIL_DISABLED
-#  define Py_LIMITED_API 0x030c0000
+#  define Py_LIMITED_API 0x030d0000
 #endif
 
 #include "Python.h"
@@ -136,6 +136,7 @@ PyDoc_STRVAR(statistics_doc,
 
 static struct PyModuleDef_Slot _statisticsmodule_slots[] = {
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index fa2cd37e003e0a2c4cfde6ef5c9520bc6196b3de..905dcbdeeddc5a9e84072ffc63997f6d817f35bf 100644 (file)
@@ -2593,6 +2593,7 @@ _structmodule_exec(PyObject *m)
 static PyModuleDef_Slot _structmodule_slots[] = {
     {Py_mod_exec, _structmodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 30b524d70c121142c1139b46237d85a4611a52b9..80c7179c4c251c822df8f2de8788e7b1e79261ed 100644 (file)
@@ -49,15 +49,21 @@ static PyMethodDef module_methods[] = {
     {NULL, NULL, 0, NULL} // Sentinel
 };
 
+static PyModuleDef_Slot module_slots[] = {
+    {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
+    {0, NULL},
+};
+
 static struct PyModuleDef suggestions_module = {
     PyModuleDef_HEAD_INIT,
     "_suggestions",
     NULL,
-    -1,
-    module_methods
+    0,
+    module_methods,
+    module_slots,
 };
 
 PyMODINIT_FUNC PyInit__suggestions(void) {
-    return PyModule_Create(&suggestions_module);
+    return PyModuleDef_Init(&suggestions_module);
 }
-
index c76b9e6b3ebafab54e383b62b35486128ef74f87..c50c5cfabc2f1f0a3ce14850bbeede0c58b1decf 100644 (file)
@@ -80,6 +80,7 @@ static struct PyMethodDef sysconfig_methods[] = {
 
 static PyModuleDef_Slot sysconfig_slots[] = {
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 9e77744efad728a885690ceed7ce8d953d9c7a82..35d4ffecad6b15d5bd3abea35a6ecdfa365b5a02 100644 (file)
@@ -2901,6 +2901,9 @@ PyInit__testbuffer(void)
     if (mod == NULL) {
         return NULL;
     }
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(mod, Py_MOD_GIL_NOT_USED);
+#endif
     if (_testbuffer_exec(mod) < 0) {
         Py_DECREF(mod);
         return NULL;
index f5892fc5ed2a2c125024aaf7fe9161a85a9ce363..beae13cd74c731914abe5ecc82740b5252be6208 100644 (file)
@@ -3935,6 +3935,9 @@ PyInit__testcapi(void)
     m = PyModule_Create(&_testcapimodule);
     if (m == NULL)
         return NULL;
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(m, Py_MOD_GIL_NOT_USED);
+#endif
 
     Py_SET_TYPE(&_HashInheritanceTester_Type, &PyType_Type);
     if (PyType_Ready(&_HashInheritanceTester_Type) < 0) {
index 2e9d00ac2189eb716672ab3e7f34eb4861e476a0..c7af552f029b81122ac18cfccb871dbaf2a8b618 100644 (file)
@@ -1955,6 +1955,9 @@ PyInit__testclinic(void)
     if (m == NULL) {
         return NULL;
     }
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(m, Py_MOD_GIL_NOT_USED);
+#endif
     if (PyModule_AddType(m, &TestClass) < 0) {
         goto error;
     }
index 29f1b7c13e4c505d9228811a1d968f4245e0b049..d5f98085f84225573c0710db126fb99a5827d38f 100644 (file)
@@ -146,5 +146,8 @@ PyInit__testclinic_limited(void)
     if (m == NULL) {
         return NULL;
     }
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(m, Py_MOD_GIL_NOT_USED);
+#endif
     return m;
 }
index e2f96cdad5c58ef0430d59902d0447ed3907c051..d9c65fe253f8d3be1b016072cdc281f62624c6be 100644 (file)
@@ -627,6 +627,12 @@ PyMODINIT_FUNC
 PyInit__testexternalinspection(void)
 {
     PyObject* mod = PyModule_Create(&module);
+    if (mod == NULL) {
+        return NULL;
+    }
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(mod, Py_MOD_GIL_NOT_USED);
+#endif
     int rc = PyModule_AddIntConstant(mod, "PROCESS_VM_READV_SUPPORTED", HAVE_PROCESS_VM_READV);
     if (rc < 0) {
         Py_DECREF(mod);
index a65ca513a12516cb9113c2fd4a5b55b957c26cde..c147596f88a3a8654e7212eab2216a25275b833e 100644 (file)
@@ -6,18 +6,24 @@
 
 #include "pyconfig.h"   // Py_GIL_DISABLED
 #ifndef Py_GIL_DISABLED
-#  define Py_LIMITED_API 0x03020000
+#  define Py_LIMITED_API 0x030d0000
 #endif
 
 #include <Python.h>
 
+static PyModuleDef_Slot shared_slots[] = {
+    {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
+    {0, NULL},
+};
+
 static struct PyModuleDef _testimportmultiple = {
     PyModuleDef_HEAD_INIT,
     "_testimportmultiple",
     "_testimportmultiple doc",
-    -1,
-    NULL,
+    0,
     NULL,
+    shared_slots,
     NULL,
     NULL,
     NULL
@@ -25,16 +31,16 @@ static struct PyModuleDef _testimportmultiple = {
 
 PyMODINIT_FUNC PyInit__testimportmultiple(void)
 {
-    return PyModule_Create(&_testimportmultiple);
+    return PyModuleDef_Init(&_testimportmultiple);
 }
 
 static struct PyModuleDef _foomodule = {
     PyModuleDef_HEAD_INIT,
     "_testimportmultiple_foo",
     "_testimportmultiple_foo doc",
-    -1,
-    NULL,
+    0,
     NULL,
+    shared_slots,
     NULL,
     NULL,
     NULL
@@ -42,21 +48,21 @@ static struct PyModuleDef _foomodule = {
 
 PyMODINIT_FUNC PyInit__testimportmultiple_foo(void)
 {
-    return PyModule_Create(&_foomodule);
+    return PyModuleDef_Init(&_foomodule);
 }
 
 static struct PyModuleDef _barmodule = {
     PyModuleDef_HEAD_INIT,
     "_testimportmultiple_bar",
     "_testimportmultiple_bar doc",
-    -1,
-    NULL,
+    0,
     NULL,
+    shared_slots,
     NULL,
     NULL,
     NULL
 };
 
 PyMODINIT_FUNC PyInit__testimportmultiple_bar(void){
-    return PyModule_Create(&_barmodule);
+    return PyModuleDef_Init(&_barmodule);
 }
index f7952a119f0bd9c73c921f327c8170890bc69b28..de98af32b5dff736090f9ee6f35d4bc717b9a463 100644 (file)
@@ -2142,6 +2142,7 @@ module_exec(PyObject *module)
 static struct PyModuleDef_Slot module_slots[] = {
     {Py_mod_exec, module_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index 598071fe0ddbad87a53ea0528310f56f2f8b113b..f88476f4be20546bc95a61759423677eaf8e2d07 100644 (file)
@@ -25,6 +25,9 @@ PyInit__testlimitedcapi(void)
     if (mod == NULL) {
         return NULL;
     }
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(mod, Py_MOD_GIL_NOT_USED);
+#endif
 
     if (_PyTestLimitedCAPI_Init_Abstract(mod) < 0) {
         return NULL;
index 21c5f696a4f2ec4692ec39982dbb8eb1a07520e6..ca3d83233c5dd03056eecffef513c4c52319689d 100644 (file)
@@ -431,6 +431,7 @@ static int execfunc(PyObject *m)
 static PyModuleDef_Slot main_slots[] = {
     {Py_mod_exec, execfunc},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
@@ -519,13 +520,18 @@ PyInit__testmultiphase_nonmodule_with_methods(void)
 
 /**** Non-ASCII-named modules ****/
 
+static PyModuleDef_Slot nonascii_slots[] = {
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
+    {0, NULL},
+};
+
 static PyModuleDef def_nonascii_latin = { \
     PyModuleDef_HEAD_INIT,                      /* m_base */
     "_testmultiphase_nonascii_latin",           /* m_name */
     PyDoc_STR("Module named in Czech"),         /* m_doc */
     0,                                          /* m_size */
     NULL,                                       /* m_methods */
-    NULL,                                       /* m_slots */
+    nonascii_slots,                             /* m_slots */
     NULL,                                       /* m_traverse */
     NULL,                                       /* m_clear */
     NULL,                                       /* m_free */
@@ -543,7 +549,7 @@ static PyModuleDef def_nonascii_kana = { \
     PyDoc_STR("Module named in Japanese"),      /* m_doc */
     0,                                          /* m_size */
     NULL,                                       /* m_methods */
-    NULL,                                       /* m_slots */
+    nonascii_slots,                             /* m_slots */
     NULL,                                       /* m_traverse */
     NULL,                                       /* m_clear */
     NULL,                                       /* m_free */
@@ -757,6 +763,7 @@ static PyModuleDef_Slot slots_nonmodule_with_exec_slots[] = {
     {Py_mod_create, createfunc_nonmodule},
     {Py_mod_exec, execfunc},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
@@ -778,6 +785,7 @@ execfunc_err(PyObject *mod)
 static PyModuleDef_Slot slots_exec_err[] = {
     {Py_mod_exec, execfunc_err},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
@@ -800,6 +808,7 @@ execfunc_raise(PyObject *spec)
 static PyModuleDef_Slot slots_exec_raise[] = {
     {Py_mod_exec, execfunc_raise},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
@@ -822,6 +831,7 @@ execfunc_unreported_exception(PyObject *mod)
 static PyModuleDef_Slot slots_exec_unreported_exception[] = {
     {Py_mod_exec, execfunc_unreported_exception},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
@@ -857,6 +867,7 @@ meth_state_access_exec(PyObject *m)
 static PyModuleDef_Slot meth_state_access_slots[] = {
     {Py_mod_exec, meth_state_access_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
@@ -889,6 +900,9 @@ PyInit__test_module_state_shared(void)
     if (module == NULL) {
         return NULL;
     }
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(module, Py_MOD_GIL_NOT_USED);
+#endif
 
     if (PyModule_AddObjectRef(module, "Error", PyExc_Exception) < 0) {
         Py_DECREF(module);
@@ -903,6 +917,7 @@ PyInit__test_module_state_shared(void)
 static PyModuleDef_Slot slots_multiple_multiple_interpreters_slots[] = {
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
@@ -920,6 +935,7 @@ PyInit__testmultiphase_multiple_multiple_interpreters_slots(void)
 static PyModuleDef_Slot non_isolated_slots[] = {
     {Py_mod_exec, execfunc},
     {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
@@ -940,6 +956,7 @@ static PyModuleDef_Slot shared_gil_only_slots[] = {
        We put it here explicitly to draw attention to the contrast
        with Py_MOD_PER_INTERPRETER_GIL_SUPPORTED. */
     {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index ff533e44a82730cf70ccb9393338dacf0a2d296e..c0eb266751e9e6ea6413c59484ee63b630b5743c 100644 (file)
@@ -471,6 +471,9 @@ init__testsinglephase_basic(PyModuleDef *def)
     if (module == NULL) {
         return NULL;
     }
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(module, Py_MOD_GIL_NOT_USED);
+#endif
 
     module_state *state = &global_state.module;
     // It may have been set by a previous run or under a different name.
@@ -562,6 +565,9 @@ PyInit__testsinglephase_with_reinit(void)
     if (module == NULL) {
         return NULL;
     }
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(module, Py_MOD_GIL_NOT_USED);
+#endif
 
     assert(get_module_state(module) == NULL);
 
@@ -624,6 +630,9 @@ PyInit__testsinglephase_with_state(void)
     if (module == NULL) {
         return NULL;
     }
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(module, Py_MOD_GIL_NOT_USED);
+#endif
 
     module_state *state = get_module_state(module);
     assert(state != NULL);
index f5e3b42600675e46dbcb3e3ac7309fab4c111d01..39d309729d88b81fdb75482a35cbb023edf5be78 100644 (file)
@@ -2544,6 +2544,7 @@ The 'threading' module provides a more convenient interface.");
 static PyModuleDef_Slot thread_module_slots[] = {
     {Py_mod_exec, thread_module_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index e3789867dc085fde321effba85dca17e198dabd3..ecb7ca8de62ef1b7365cce86724caa09d1cacb79 100644 (file)
@@ -3205,6 +3205,9 @@ PyInit__tkinter(void)
     m = PyModule_Create(&_tkintermodule);
     if (m == NULL)
         return NULL;
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(m, Py_MOD_GIL_NOT_USED);
+#endif
 
     Tkinter_TclError = PyErr_NewException("_tkinter.TclError", NULL, NULL);
     if (PyModule_AddObjectRef(m, "TclError", Tkinter_TclError)) {
index 6dba3cac01c1c89ba31433d550fbfe472b1f7788..55028dc3a65ff46e34eba5fd4710de644c09965e 100644 (file)
@@ -219,6 +219,9 @@ PyInit__tracemalloc(void)
     m = PyModule_Create(&module_def);
     if (m == NULL)
         return NULL;
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(m, Py_MOD_GIL_NOT_USED);
+#endif
 
     if (_PyTraceMalloc_Init() < 0) {
         Py_DECREF(m);
index 180f3d7eb01794c01009a75cccfba07ca2e12139..09fbb3c5e8b91d790a6e7a0c29195f919a6b865e 100644 (file)
@@ -72,6 +72,7 @@ _typing_exec(PyObject *m)
 static struct PyModuleDef_Slot _typingmodule_slots[] = {
     {Py_mod_exec, _typing_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 052cb9fef3b21c07daf26d7d75d5b42021a8f08a..c5e78b1510b5e3a32fed16577e645c73e5d02321 100644 (file)
@@ -3,10 +3,10 @@
  * DCE compatible Universally Unique Identifier library.
  */
 
-// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
+// Need limited C API version 3.13 for Py_mod_gil
 #include "pyconfig.h"   // Py_GIL_DISABLED
 #ifndef Py_GIL_DISABLED
-#  define Py_LIMITED_API 0x030c0000
+#  define Py_LIMITED_API 0x030d0000
 #endif
 
 #include "Python.h"
@@ -111,6 +111,7 @@ static PyMethodDef uuid_methods[] = {
 static PyModuleDef_Slot uuid_slots[] = {
     {Py_mod_exec, uuid_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 1ea3ed5e40b761f69fdacac5f69279b95c4ba68e..a5c15c0f10b930a7d8fcb71349a6523bb623fefa 100644 (file)
@@ -171,6 +171,7 @@ weakref_exec(PyObject *module)
 static struct PyModuleDef_Slot weakref_slots[] = {
     {Py_mod_exec, weakref_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 23e3c0d87f0319011f797b36417dea9e7fcac47b..cd5dd503abe61f4a1fd96c10dc161cd4de61117d 100644 (file)
@@ -3189,6 +3189,7 @@ static int winapi_exec(PyObject *m)
 static PyModuleDef_Slot winapi_slots[] = {
     {Py_mod_exec, winapi_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index a2dbabce71ed67cdc1e7faa21c9fd56d8f2cb3c1..2952d7043e01fec88b6b1c56a6097fb45c65872f 100644 (file)
@@ -28,13 +28,18 @@ static PyMethodDef module_methods[] = {
     {NULL},
 };
 
+static PyModuleDef_Slot module_slots[] = {
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
+    {0, NULL},
+};
+
 static struct PyModuleDef _fuzzmodule = {
         PyModuleDef_HEAD_INIT,
         "_fuzz",
         NULL,
         0,
         module_methods,
-        NULL,
+        module_slots,
         NULL,
         NULL,
         NULL
@@ -43,5 +48,5 @@ static struct PyModuleDef _fuzzmodule = {
 PyMODINIT_FUNC
 PyInit__xxtestfuzz(void)
 {
-    return PyModule_Create(&_fuzzmodule);
+    return PyModuleDef_Init(&_fuzzmodule);
 }
index fcd4af64df0be94c1c1577d7a119c8c1af0ed955..38c3f0c45d803fdd547fe413e6acd03b282d3b9b 100644 (file)
@@ -2760,6 +2760,7 @@ error:
 static PyModuleDef_Slot zoneinfomodule_slots[] = {
     {Py_mod_exec, zoneinfomodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index 317f4974814945ecd383b6313e3c203fa3b0cd5a..a3b833d47cd9eae7b2743bca17d043fff55780b3 100644 (file)
@@ -3220,6 +3220,7 @@ array_modexec(PyObject *m)
 static PyModuleDef_Slot arrayslots[] = {
     {Py_mod_exec, array_modexec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 8e908da2534c554dc8b13b58b1d43ecca0831d65..297a8d74ba3bf4c1f8f84f8f4b9a6b3a80e305b8 100644 (file)
@@ -322,6 +322,7 @@ Two public functions, register and unregister, are defined.\n\
 
 static PyModuleDef_Slot atexitmodule_slots[] = {
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 86493241a1fb7e2a86868a52febcf4073e21399b..250f03a9531eedc240a74425c3a700353e8c9da4 100644 (file)
@@ -1278,6 +1278,7 @@ binascii_exec(PyObject *module)
 static PyModuleDef_Slot binascii_slots[] = {
     {Py_mod_exec, binascii_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 766f82983025e463a364181e8f9f2d77fc9523cf..2b446ba5226ac03b142b186cfc32dbc6f839bc4d 100644 (file)
@@ -503,6 +503,7 @@ static struct PyMethodDef _cjk_methods[] = {
 static PyModuleDef_Slot _cjk_slots[] = {
     {Py_mod_exec, _cjk_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index e5433d7dd8530666cacad85d0e18da3658952d9a..1c671adb4ff188a5c0831c0ab11326aa5fea97e7 100644 (file)
@@ -2094,6 +2094,7 @@ static struct PyMethodDef _multibytecodec_methods[] = {
 static PyModuleDef_Slot _multibytecodec_slots[] = {
     {Py_mod_exec, _multibytecodec_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 57bc55632be485975116ed0d16433ac27b332950..d901b350bc53430932028234d0d0e9588a76ce35 100644 (file)
@@ -1363,6 +1363,7 @@ cmath_exec(PyObject *mod)
 static PyModuleDef_Slot cmath_slots[] = {
     {Py_mod_exec, cmath_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 97e5f0180d76fb1eb2d9adb7fe80b72ec299ca93..3f96f2f846d6129b471139a7cf81a1fa5abc14f5 100644 (file)
@@ -1,9 +1,9 @@
 /* Errno module */
 
-// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
+// Need limited C API version 3.13 for Py_mod_gil
 #include "pyconfig.h"   // Py_GIL_DISABLED
 #ifndef Py_GIL_DISABLED
-#  define Py_LIMITED_API 0x030c0000
+#  define Py_LIMITED_API 0x030d0000
 #endif
 
 #include "Python.h"
@@ -951,6 +951,7 @@ errno_exec(PyObject *module)
 static PyModuleDef_Slot errno_slots[] = {
     {Py_mod_exec, errno_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index c70d43a36b5cc791085446d39a5c57bf55bda29a..cfa3cbdc34bc86af02794806c28873cd6c6ce68d 100644 (file)
@@ -1292,6 +1292,7 @@ static PyModuleDef_Slot faulthandler_slots[] = {
     {Py_mod_exec, PyExec_faulthandler},
     // XXX gh-103092: fix isolation.
     //{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index e24e5f98f4bc4d78e851de46485d830ab0d54e00..b6eeec2c66f6e592ce2fc5ffeaa235956f59c7d2 100644 (file)
@@ -745,6 +745,7 @@ fcntl_exec(PyObject *module)
 static PyModuleDef_Slot fcntl_slots[] = {
     {Py_mod_exec, fcntl_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 8a1b483eddae35499c7ca63924b73b9125871b8b..57e4aae9ed557eb31a964c36e58d1d362f7c235c 100644 (file)
@@ -535,6 +535,7 @@ gcmodule_exec(PyObject *module)
 static PyModuleDef_Slot gcmodule_slots[] = {
     {Py_mod_exec, gcmodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index a1fa6cf20f71fd831ed61b2ecf7abaef38cb33a8..f7d3e12f347ec2f810f45d7921293b620b95f9bd 100644 (file)
@@ -342,6 +342,7 @@ grpmodule_exec(PyObject *module)
 static PyModuleDef_Slot grpmodule_slots[] = {
     {Py_mod_exec, grpmodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 21ce3ecfad0354744d2d33af8cd1490999aacd49..8641c2f87e6db202a9f37fcc4d5044be3afb6f74 100644 (file)
@@ -4781,6 +4781,7 @@ itertoolsmodule_exec(PyObject *mod)
 static struct PyModuleDef_Slot itertoolsmodule_slots[] = {
     {Py_mod_exec, itertoolsmodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 8ba0431f4a47b79826ff248e244b884e2203e009..a3cbfc383761a02b2434a619f9348a0da7100d51 100644 (file)
@@ -4177,6 +4177,7 @@ static PyMethodDef math_methods[] = {
 static PyModuleDef_Slot math_slots[] = {
     {Py_mod_exec, math_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 9cbf11feaa9c32613ee2daae88520d44cd1b2289..ef9163e8be5b6c7063133eaedf1e700b5add784a 100644 (file)
@@ -375,6 +375,7 @@ md5_exec(PyObject *m)
 static PyModuleDef_Slot _md5_slots[] = {
     {Py_mod_exec, md5_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 0cce7c27f9b16a57c695856f00f60078d9c8d9c2..dfc16ff437034941dc417425132b3fc0f904a117 100644 (file)
@@ -1801,6 +1801,7 @@ mmap_exec(PyObject *module)
 static PyModuleDef_Slot mmap_slots[] = {
     {Py_mod_exec, mmap_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index b9881d91ded24471217ab8833846795e6e871c9d..77ee70ae133c858586460ec920b6ca96950f8238 100644 (file)
@@ -2070,6 +2070,7 @@ overlapped_exec(PyObject *module)
 static PyModuleDef_Slot overlapped_slots[] = {
     {Py_mod_exec, overlapped_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index e1a14e772c4bd03532972a6a72234754c2939800..9f4be98b35186ee2fbf1ac3f18adf766a0a00288 100644 (file)
@@ -18071,6 +18071,7 @@ posixmodule_exec(PyObject *m)
 static PyModuleDef_Slot posixmodile_slots[] = {
     {Py_mod_exec, posixmodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index f58735aff997992282ffd3d2bf0bd1613cb424ef..2240e2078b2d982719bbfaef912e53dee2691adb 100644 (file)
@@ -344,6 +344,7 @@ pwdmodule_exec(PyObject *module)
 static PyModuleDef_Slot pwdmodule_slots[] = {
     {Py_mod_exec, pwdmodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index f04f96bc2f7601c98568682484d2be8219616044..f67d480f19de001c5c63b06c0dc5d75a5f284ad2 100644 (file)
@@ -2117,6 +2117,7 @@ pyexpat_free(void *module)
 static PyModuleDef_Slot pyexpat_slots[] = {
     {Py_mod_exec, pyexpat_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index c5c34535de015469ce26a564aa3eb29a4638d739..f59f8a9834caafc0c161a7f0104f76f27b02dac7 100644 (file)
@@ -1552,6 +1552,9 @@ PyInit_readline(void)
 
     if (m == NULL)
         return NULL;
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(m, Py_MOD_GIL_NOT_USED);
+#endif
 
     if (PyModule_AddIntConstant(m, "_READLINE_VERSION",
                                 RL_READLINE_VERSION) < 0) {
index 8ee07bd0c8054c1f05bfc1a46ab14cc829641498..3fe18e7c98e3d812d64a5e9a100052c365af58af 100644 (file)
@@ -513,6 +513,7 @@ resource_exec(PyObject *module)
 static struct PyModuleDef_Slot resource_slots[] = {
     {Py_mod_exec, resource_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 6ea141ab1f91897d55bd9e1413b9920de50c1c92..3eaee22c652c28405c3cf369e906988e68058f0d 100644 (file)
@@ -2802,6 +2802,7 @@ _select_exec(PyObject *m)
 static PyModuleDef_Slot _select_slots[] = {
     {Py_mod_exec, _select_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 345a6c215eb16714d175f1a4737c6fd5159ad169..34a427a39b5cf844754bdbff8a838aadb16d3abb 100644 (file)
@@ -371,6 +371,7 @@ _sha1_exec(PyObject *module)
 static PyModuleDef_Slot _sha1_slots[] = {
     {Py_mod_exec, _sha1_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 60be4228a00a035fa653c37caee73369fd6f5e29..7d6a1e40243f9d4c09587c6c5bc3de27c1511360 100644 (file)
@@ -866,6 +866,7 @@ static int sha2_exec(PyObject *module)
 static PyModuleDef_Slot _sha2_slots[] = {
     {Py_mod_exec, sha2_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index c30e924a7072f76606c2bd801ec4917b815dc016..084332c1efa0e0f5e6308933786a5d42ed29dd85 100644 (file)
@@ -602,6 +602,7 @@ _sha3_exec(PyObject *m)
 static PyModuleDef_Slot _sha3_slots[] = {
     {Py_mod_exec, _sha3_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 08fedeacd96d283453847ceb3191cb01ea89f133..7de5ebe0899b3584cf1a3885c40d527e6b111415 100644 (file)
@@ -1698,6 +1698,7 @@ _signal_module_free(void *module)
 static PyModuleDef_Slot signal_slots[] = {
     {Py_mod_exec, signal_module_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 7720d59e46590ea6d1d20d6b5910ac436326aa0b..daec560ddfcac706533417a293abee88fb563bbc 100644 (file)
@@ -8896,6 +8896,7 @@ error:
 static struct PyModuleDef_Slot socket_slots[] = {
     {Py_mod_exec, socket_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index ddc9ac3324356dc37b0a3f714cea159ba8cff327..b4dbb54c3b47b00cf03c2822ad9f066de1925f46 100644 (file)
@@ -110,6 +110,7 @@ symtable_init_constants(PyObject *m)
 static PyModuleDef_Slot symtable_slots[] = {
     {Py_mod_exec, symtable_init_constants},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index cb3f2b03990cb84a817271f1f00e41e39bffe1e2..14e7ca591a076b22a7f319334c79e92263797992 100644 (file)
@@ -439,6 +439,7 @@ syslog_exec(PyObject *module)
 static PyModuleDef_Slot syslog_slots[] = {
     {Py_mod_exec, syslog_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index a29474d650127f166689cf19468cee8a1f63ab66..f2c5a4bafa70124b4cb821cd4be46ff98c027fad 100644 (file)
@@ -1364,6 +1364,7 @@ termios_exec(PyObject *mod)
 static PyModuleDef_Slot termios_slots[] = {
     {Py_mod_exec, termios_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 3211c7530da0b2ff0268092f6947d515ad522512..0511339978897a0725782d24b1b6171022b993a2 100644 (file)
@@ -2128,6 +2128,7 @@ time_module_free(void *module)
 static struct PyModuleDef_Slot time_slots[] = {
     {Py_mod_exec, time_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 6ae35b9372b830cbdfcca6e05a7e32b7592eab39..333ffe68a454e4995de698aeb950cf57dc912c93 100644 (file)
@@ -1668,6 +1668,7 @@ unicodedata_exec(PyObject *module)
 static PyModuleDef_Slot unicodedata_slots[] = {
     {Py_mod_exec, unicodedata_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 3357b8076b67b11666b376719d9beed6bfbcab36..d86741e1dfc18cf7bfcae7e2254b301b8a83a6f8 100644 (file)
           pass
    */
 
-// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
+// Need limited C API version 3.13 for Py_mod_gil
 #include "pyconfig.h"   // Py_GIL_DISABLED
 #ifndef Py_GIL_DISABLED
-#  define Py_LIMITED_API 0x030c0000
+#  define Py_LIMITED_API 0x030d0000
 #endif
 
 #include "Python.h"
@@ -395,6 +395,7 @@ xx_modexec(PyObject *m)
 static PyModuleDef_Slot xx_slots[] = {
     {Py_mod_exec, xx_modexec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 52690d9d10a81f800708956450ce36df7132c005..1063e54217b74658dbd8ee97642131c65c8b6acb 100644 (file)
@@ -297,6 +297,10 @@ xx_modexec(PyObject *m)
 
 static PyModuleDef_Slot xx_slots[] = {
     {Py_mod_exec, xx_modexec},
+#ifdef Py_GIL_DISABLED
+    // These definitions are in the limited API, but not until 3.13.
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
+#endif
     {0, NULL}
 };
 
index 1e4e0ea3743ce3e1d3e9dab405208e2b7aaf28ed..a46bf8f0e64ee2138df93e2513cc7ae39f73a193 100644 (file)
@@ -384,6 +384,7 @@ xx_exec(PyObject *m)
 static struct PyModuleDef_Slot xx_slots[] = {
     {Py_mod_exec, xx_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index 560f43e5b3a643a2ff8809e7a8cd55a8c4d6efa7..9c548f44558d417e74eb15c9a94829bf7fccab28 100644 (file)
@@ -288,6 +288,7 @@ xxsubtype_exec(PyObject* m)
 static struct PyModuleDef_Slot xxsubtype_slots[] = {
     {Py_mod_exec, xxsubtype_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index fe9a6d8d4150ab9a81c9bd25d6cd1ee426e6ca7e..b115f67f228ba7d55b6f643e1c9d1e5998b47621 100644 (file)
@@ -2106,6 +2106,7 @@ zlib_exec(PyObject *mod)
 static PyModuleDef_Slot zlib_slots[] = {
     {Py_mod_exec, zlib_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 2f6adb9a2e12be52c60d38cf1c463a541aefc213..d877edaf5453e10d1e279953bba1f5d5adfb506e 100644 (file)
@@ -249,6 +249,9 @@ _PyModule_CreateInitialized(PyModuleDef* module, int module_api_version)
         }
     }
     m->md_def = module;
+#ifdef Py_GIL_DISABLE
+    m->md_gil = Py_MOD_GIL_USED;
+#endif
     return (PyObject*)m;
 }
 
@@ -261,6 +264,8 @@ PyModule_FromDefAndSpec2(PyModuleDef* def, PyObject *spec, int module_api_versio
     PyObject *m = NULL;
     int has_multiple_interpreters_slot = 0;
     void *multiple_interpreters = (void *)0;
+    int has_gil_slot = 0;
+    void *gil_slot = Py_MOD_GIL_USED;
     int has_execution_slots = 0;
     const char *name;
     int ret;
@@ -315,6 +320,17 @@ PyModule_FromDefAndSpec2(PyModuleDef* def, PyObject *spec, int module_api_versio
                 multiple_interpreters = cur_slot->value;
                 has_multiple_interpreters_slot = 1;
                 break;
+            case Py_mod_gil:
+                if (has_gil_slot) {
+                    PyErr_Format(
+                       PyExc_SystemError,
+                       "module %s has more than one 'gil' slot",
+                       name);
+                    goto error;
+                }
+                gil_slot = cur_slot->value;
+                has_gil_slot = 1;
+                break;
             default:
                 assert(cur_slot->slot < 0 || cur_slot->slot > _Py_mod_LAST_SLOT);
                 PyErr_Format(
@@ -374,6 +390,11 @@ PyModule_FromDefAndSpec2(PyModuleDef* def, PyObject *spec, int module_api_versio
     if (PyModule_Check(m)) {
         ((PyModuleObject*)m)->md_state = NULL;
         ((PyModuleObject*)m)->md_def = def;
+#ifdef Py_GIL_DISABLED
+        ((PyModuleObject*)m)->md_gil = gil_slot;
+#else
+        (void)gil_slot;
+#endif
     } else {
         if (def->m_size > 0 || def->m_traverse || def->m_clear || def->m_free) {
             PyErr_Format(
@@ -415,6 +436,19 @@ error:
     return NULL;
 }
 
+#ifdef Py_GIL_DISABLED
+int
+PyModule_ExperimentalSetGIL(PyObject *module, void *gil)
+{
+    if (!PyModule_Check(module)) {
+        PyErr_BadInternalCall();
+        return -1;
+    }
+    ((PyModuleObject *)module)->md_gil = gil;
+    return 0;
+}
+#endif
+
 int
 PyModule_ExecDef(PyObject *module, PyModuleDef *def)
 {
@@ -470,6 +504,7 @@ PyModule_ExecDef(PyObject *module, PyModuleDef *def)
                 }
                 break;
             case Py_mod_multiple_interpreters:
+            case Py_mod_gil:
                 /* handled in PyModule_FromDefAndSpec2 */
                 break;
             default:
index 67b1282de790e09a42bfc9825c824e30dbf269d5..057b417074ebeaf85222398affeab4b66b855321 100644 (file)
@@ -15541,6 +15541,7 @@ static PyMethodDef _string_methods[] = {
 
 static PyModuleDef_Slot module_slots[] = {
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index f1ace003df483b0f25b4f104a7ece3621e3c0f35..0dcea866f65d359138d2febf3dd38fbd67f8ee92 100644 (file)
@@ -1,10 +1,10 @@
 /* Testing module for multi-phase initialization of extension modules (PEP 489)
  */
 
-// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
+// Need limited C API version 3.13 for Py_mod_gil
 #include "pyconfig.h"   // Py_GIL_DISABLED
 #ifndef Py_GIL_DISABLED
-#  define Py_LIMITED_API 0x030c0000
+#  define Py_LIMITED_API 0x030d0000
 #endif
 
 #include "Python.h"
@@ -31,6 +31,7 @@ static int execfunc(PyObject *m)
 PyModuleDef_Slot testconsole_slots[] = {
     {Py_mod_exec, execfunc},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL},
 };
 
index 5ff703217b421f887f3e9ddc7616e0320ea872cb..b170e06b47dd59912f881eb2daa95912a464af88 100644 (file)
@@ -656,6 +656,7 @@ exec_module(PyObject* m)
 static PyModuleDef_Slot msvcrt_slots[] = {
     {Py_mod_exec, exec_module},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 8096d17e43b7bce4bc114f60bee29eb72177a56f..efdf8addc061863d7654d252ae60c78214090418 100644 (file)
@@ -2179,6 +2179,7 @@ exec_module(PyObject *m)
 static PyModuleDef_Slot winreg_slots[] = {
     {Py_mod_exec, exec_module},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index a6b2dac6ac1466989b36224688d729b93f9b0be1..094c77ae34d6788df7096917b2e30d25e8ae2f78 100644 (file)
    winsound.PlaySound(None, 0)
 */
 
-// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
+// Need limited C API version 3.13 for Py_mod_gil
 #include "pyconfig.h"  // Py_GIL_DISABLED
 #ifndef Py_GIL_DISABLED
-#  define Py_LIMITED_API 0x030c0000
+#  define Py_LIMITED_API 0x030d0000
 #endif
 
 #include <Python.h>
@@ -246,6 +246,7 @@ exec_module(PyObject *module)
 static PyModuleDef_Slot sound_slots[] = {
     {Py_mod_exec, exec_module},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index c4df2c52c032bcec8eadfd17025977860ddd81c6..1f0be456655b25b91ba8b5f0060a285640bd1115 100755 (executable)
@@ -1443,6 +1443,7 @@ class ASTModuleVisitor(PickleVisitor):
 static PyModuleDef_Slot astmodule_slots[] = {
     {Py_mod_exec, astmodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index cc7734e0dbbf9f6e1d28a369552a34477a83b0c7..1953142f6def44b4c441c01e7855d3ea1c92a739 100644 (file)
@@ -17588,6 +17588,7 @@ astmodule_exec(PyObject *m)
 static PyModuleDef_Slot astmodule_slots[] = {
     {Py_mod_exec, astmodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index a7891709b3b44a2dacd11d4cb1f288194100858b..41e8107e205b469028ba41171fb9d969c510a5fe 100644 (file)
@@ -322,6 +322,7 @@ static PyMethodDef tokenize_methods[] = {
 static PyModuleDef_Slot tokenizemodule_slots[] = {
     {Py_mod_exec, tokenizemodule_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 2ba704dcaa79b20a744eafdacb64d55734aa5a9c..793cbc657f318450a4c9ea8d8f3f3af9ec07f4a9 100644 (file)
@@ -1498,6 +1498,7 @@ warnings_module_exec(PyObject *module)
 static PyModuleDef_Slot warnings_slots[] = {
     {Py_mod_exec, warnings_module_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 722353ebcbfc3d8f1192fea4bd5c6a0a34878036..88d858dc944863f278a22f379a38462556016a2b 100644 (file)
@@ -3124,6 +3124,9 @@ _PyBuiltin_Init(PyInterpreterState *interp)
     mod = _PyModule_CreateInitialized(&builtinsmodule, PYTHON_API_VERSION);
     if (mod == NULL)
         return NULL;
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(mod, Py_MOD_GIL_NOT_USED);
+#endif
     dict = PyModule_GetDict(mod);
 
 #ifdef Py_TRACE_REFS
index f120a3841b495da4034f142fdc78e0b2cc2a676c..4f91f03f091edd61819764bfa678ba19d3e054fe 100644 (file)
@@ -4212,6 +4212,7 @@ imp_module_exec(PyObject *module)
 static PyModuleDef_Slot imp_slots[] = {
     {Py_mod_exec, imp_module_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index 4bd8bb1d3a9308fa5ae2337a954e58ca90e1783c..ca22d6d679a2300c0398adf422664fc18ff6b08d 100644 (file)
@@ -1952,6 +1952,7 @@ marshal_module_exec(PyObject *mod)
 static PyModuleDef_Slot marshalmodule_slots[] = {
     {Py_mod_exec, marshal_module_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+    {Py_mod_gil, Py_MOD_GIL_NOT_USED},
     {0, NULL}
 };
 
index f469f165e7fb84da63acb9f03820d19fe6b86b6c..645b76fccf602c5816d32ad53fafcb9cf6a80589 100644 (file)
@@ -3756,6 +3756,9 @@ _PySys_Create(PyThreadState *tstate, PyObject **sysmod_p)
     if (sysmod == NULL) {
         return _PyStatus_ERR("failed to create a module object");
     }
+#ifdef Py_GIL_DISABLED
+    PyModule_ExperimentalSetGIL(sysmod, Py_MOD_GIL_NOT_USED);
+#endif
 
     PyObject *sysdict = PyModule_GetDict(sysmod);
     if (sysdict == NULL) {