summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/c-api/module.rst38
-rw-r--r--Include/internal/pycore_moduleobject.h3
-rw-r--r--Include/moduleobject.h16
-rw-r--r--Lib/test/test_importlib/extension/_test_nonmodule_cases.py44
-rw-r--r--Lib/test/test_importlib/extension/test_loader.py35
-rw-r--r--Lib/test/test_sys.py5
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2024-03-12-13-51-09.gh-issue-116322.q8TcDQ.rst5
-rw-r--r--Modules/_abc.c1
-rw-r--r--Modules/_asynciomodule.c1
-rw-r--r--Modules/_bisectmodule.c1
-rw-r--r--Modules/_blake2/blake2module.c1
-rw-r--r--Modules/_bz2module.c1
-rw-r--r--Modules/_codecsmodule.c1
-rw-r--r--Modules/_collectionsmodule.c1
-rw-r--r--Modules/_contextvarsmodule.c1
-rw-r--r--Modules/_csv.c1
-rw-r--r--Modules/_ctypes/_ctypes.c1
-rw-r--r--Modules/_ctypes/_ctypes_test.c5
-rw-r--r--Modules/_curses_panel.c1
-rw-r--r--Modules/_cursesmodule.c3
-rw-r--r--Modules/_datetimemodule.c3
-rw-r--r--Modules/_dbmmodule.c1
-rw-r--r--Modules/_decimal/_decimal.c1
-rw-r--r--Modules/_elementtree.c1
-rw-r--r--Modules/_functoolsmodule.c1
-rw-r--r--Modules/_gdbmmodule.c1
-rw-r--r--Modules/_hashopenssl.c1
-rw-r--r--Modules/_heapqmodule.c1
-rw-r--r--Modules/_interpchannelsmodule.c1
-rw-r--r--Modules/_interpqueuesmodule.c1
-rw-r--r--Modules/_interpretersmodule.c1
-rw-r--r--Modules/_io/_iomodule.c1
-rw-r--r--Modules/_json.c1
-rw-r--r--Modules/_localemodule.c1
-rw-r--r--Modules/_lsprof.c1
-rw-r--r--Modules/_lzmamodule.c1
-rw-r--r--Modules/_multiprocessing/multiprocessing.c1
-rw-r--r--Modules/_multiprocessing/posixshmem.c5
-rw-r--r--Modules/_opcode.c1
-rw-r--r--Modules/_operator.c1
-rw-r--r--Modules/_pickle.c1
-rw-r--r--Modules/_posixsubprocess.c1
-rw-r--r--Modules/_queuemodule.c1
-rw-r--r--Modules/_randommodule.c1
-rw-r--r--Modules/_scproxy.c5
-rw-r--r--Modules/_sqlite/module.c1
-rw-r--r--Modules/_sre/sre.c1
-rw-r--r--Modules/_ssl.c1
-rw-r--r--Modules/_stat.c1
-rw-r--r--Modules/_statisticsmodule.c5
-rw-r--r--Modules/_struct.c1
-rw-r--r--Modules/_suggestions.c14
-rw-r--r--Modules/_sysconfig.c1
-rw-r--r--Modules/_testbuffer.c3
-rw-r--r--Modules/_testcapimodule.c3
-rw-r--r--Modules/_testclinic.c3
-rw-r--r--Modules/_testclinic_limited.c3
-rw-r--r--Modules/_testexternalinspection.c6
-rw-r--r--Modules/_testimportmultiple.c26
-rw-r--r--Modules/_testinternalcapi.c1
-rw-r--r--Modules/_testlimitedcapi.c3
-rw-r--r--Modules/_testmultiphase.c21
-rw-r--r--Modules/_testsinglephase.c9
-rw-r--r--Modules/_threadmodule.c1
-rw-r--r--Modules/_tkinter.c3
-rw-r--r--Modules/_tracemalloc.c3
-rw-r--r--Modules/_typingmodule.c1
-rw-r--r--Modules/_uuidmodule.c5
-rw-r--r--Modules/_weakref.c1
-rw-r--r--Modules/_winapi.c1
-rw-r--r--Modules/_xxtestfuzz/_xxtestfuzz.c9
-rw-r--r--Modules/_zoneinfo.c1
-rw-r--r--Modules/arraymodule.c1
-rw-r--r--Modules/atexitmodule.c1
-rw-r--r--Modules/binascii.c1
-rw-r--r--Modules/cjkcodecs/cjkcodecs.h1
-rw-r--r--Modules/cjkcodecs/multibytecodec.c1
-rw-r--r--Modules/cmathmodule.c1
-rw-r--r--Modules/errnomodule.c5
-rw-r--r--Modules/faulthandler.c1
-rw-r--r--Modules/fcntlmodule.c1
-rw-r--r--Modules/gcmodule.c1
-rw-r--r--Modules/grpmodule.c1
-rw-r--r--Modules/itertoolsmodule.c1
-rw-r--r--Modules/mathmodule.c1
-rw-r--r--Modules/md5module.c1
-rw-r--r--Modules/mmapmodule.c1
-rw-r--r--Modules/overlapped.c1
-rw-r--r--Modules/posixmodule.c1
-rw-r--r--Modules/pwdmodule.c1
-rw-r--r--Modules/pyexpat.c1
-rw-r--r--Modules/readline.c3
-rw-r--r--Modules/resource.c1
-rw-r--r--Modules/selectmodule.c1
-rw-r--r--Modules/sha1module.c1
-rw-r--r--Modules/sha2module.c1
-rw-r--r--Modules/sha3module.c1
-rw-r--r--Modules/signalmodule.c1
-rw-r--r--Modules/socketmodule.c1
-rw-r--r--Modules/symtablemodule.c1
-rw-r--r--Modules/syslogmodule.c1
-rw-r--r--Modules/termios.c1
-rw-r--r--Modules/timemodule.c1
-rw-r--r--Modules/unicodedata.c1
-rw-r--r--Modules/xxlimited.c5
-rw-r--r--Modules/xxlimited_35.c4
-rw-r--r--Modules/xxmodule.c1
-rw-r--r--Modules/xxsubtype.c1
-rw-r--r--Modules/zlibmodule.c1
-rw-r--r--Objects/moduleobject.c35
-rw-r--r--Objects/unicodeobject.c1
-rw-r--r--PC/_testconsole.c5
-rw-r--r--PC/msvcrtmodule.c1
-rw-r--r--PC/winreg.c1
-rw-r--r--PC/winsound.c5
-rwxr-xr-xParser/asdl_c.py1
-rw-r--r--Python/Python-ast.c1
-rw-r--r--Python/Python-tokenize.c1
-rw-r--r--Python/_warnings.c1
-rw-r--r--Python/bltinmodule.c3
-rw-r--r--Python/import.c1
-rw-r--r--Python/marshal.c1
-rw-r--r--Python/sysmodule.c3
123 files changed, 376 insertions, 62 deletions
diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst
index 979b222..86308d9 100644
--- a/Doc/c-api/module.rst
+++ b/Doc/c-api/module.rst
@@ -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
^^^^^^^^^^^^^
diff --git a/Include/internal/pycore_moduleobject.h b/Include/internal/pycore_moduleobject.h
index 5644bbe..049677b 100644
--- a/Include/internal/pycore_moduleobject.h
+++ b/Include/internal/pycore_moduleobject.h
@@ -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) {
diff --git a/Include/moduleobject.h b/Include/moduleobject.h
index 83f8c20..6afa3c7 100644
--- a/Include/moduleobject.h
+++ b/Include/moduleobject.h
@@ -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
index 0000000..8ffd18d
--- /dev/null
+++ b/Lib/test/test_importlib/extension/_test_nonmodule_cases.py
@@ -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()
diff --git a/Lib/test/test_importlib/extension/test_loader.py b/Lib/test/test_importlib/extension/test_loader.py
index 7607f0e..0dd21e0 100644
--- a/Lib/test/test_importlib/extension/test_loader.py
+++ b/Lib/test/test_importlib/extension/test_loader.py
@@ -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()
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index df0a6f0..7391276 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -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
index 0000000..2d3bf41
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2024-03-12-13-51-09.gh-issue-116322.q8TcDQ.rst
@@ -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.
diff --git a/Modules/_abc.c b/Modules/_abc.c
index f2a523e..4f4b24b 100644
--- a/Modules/_abc.c
+++ b/Modules/_abc.c
@@ -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}
};
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index 0873d32..a26714f 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -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},
};
diff --git a/Modules/_bisectmodule.c b/Modules/_bisectmodule.c
index 9e0fd33..56322c4 100644
--- a/Modules/_bisectmodule.c
+++ b/Modules/_bisectmodule.c
@@ -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}
};
diff --git a/Modules/_blake2/blake2module.c b/Modules/_blake2/blake2module.c
index 5df9fd3..7824221 100644
--- a/Modules/_blake2/blake2module.c
+++ b/Modules/_blake2/blake2module.c
@@ -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}
};
diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c
index 3d0d4ee..661847a 100644
--- a/Modules/_bz2module.c
+++ b/Modules/_bz2module.c
@@ -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}
};
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index c31c1b6..32373f0 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -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}
};
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 309d63c..b865351 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -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}
};
diff --git a/Modules/_contextvarsmodule.c b/Modules/_contextvarsmodule.c
index f621c1d..3f96f07 100644
--- a/Modules/_contextvarsmodule.c
+++ b/Modules/_contextvarsmodule.c
@@ -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}
};
diff --git a/Modules/_csv.c b/Modules/_csv.c
index ac948f4..9d6b66d 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -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}
};
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 3cb0b24..1b1a0ea 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -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}
};
diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c
index 1dd3ef1..f46f636 100644
--- a/Modules/_ctypes/_ctypes_test.c
+++ b/Modules/_ctypes/_ctypes_test.c
@@ -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}
};
diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c
index 2ec8f34..125c72d 100644
--- a/Modules/_curses_panel.c
+++ b/Modules/_curses_panel.c
@@ -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}
};
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index d04d1e9..8bf6824 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -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);
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 06004e2..00015c5 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -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);
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
index ee33fe6..1be4234 100644
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -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}
};
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index fe6711143b..2daa24c 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -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},
};
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index aaa0cad..b11983d 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -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},
};
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index e37473a..9dee7bf 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -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}
};
diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c
index db868c1..df7fba6 100644
--- a/Modules/_gdbmmodule.c
+++ b/Modules/_gdbmmodule.c
@@ -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}
};
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index d0b4681..14d9c18 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -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}
};
diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c
index 9d4ec25..695ce22 100644
--- a/Modules/_heapqmodule.c
+++ b/Modules/_heapqmodule.c
@@ -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}
};
diff --git a/Modules/_interpchannelsmodule.c b/Modules/_interpchannelsmodule.c
index 43c9658..ff8dacf 100644
--- a/Modules/_interpchannelsmodule.c
+++ b/Modules/_interpchannelsmodule.c
@@ -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},
};
diff --git a/Modules/_interpqueuesmodule.c b/Modules/_interpqueuesmodule.c
index 46801bd..556953d 100644
--- a/Modules/_interpqueuesmodule.c
+++ b/Modules/_interpqueuesmodule.c
@@ -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},
};
diff --git a/Modules/_interpretersmodule.c b/Modules/_interpretersmodule.c
index 8fea569..86a4113 100644
--- a/Modules/_interpretersmodule.c
+++ b/Modules/_interpretersmodule.c
@@ -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},
};
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
index 173f5b5..269070f 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -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},
};
diff --git a/Modules/_json.c b/Modules/_json.c
index c552998..fc39f62 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -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}
};
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index fe8e4c5..d492344 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -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}
};
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
index a76c3de..18be01d 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -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}
};
diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c
index f6bfbfa..97f3a8f 100644
--- a/Modules/_lzmamodule.c
+++ b/Modules/_lzmamodule.c
@@ -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}
};
diff --git a/Modules/_multiprocessing/multiprocessing.c b/Modules/_multiprocessing/multiprocessing.c
index 1f6ab71..cee8cf7 100644
--- a/Modules/_multiprocessing/multiprocessing.c
+++ b/Modules/_multiprocessing/multiprocessing.c
@@ -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}
};
diff --git a/Modules/_multiprocessing/posixshmem.c b/Modules/_multiprocessing/posixshmem.c
index d332a4e..aeb2d79 100644
--- a/Modules/_multiprocessing/posixshmem.c
+++ b/Modules/_multiprocessing/posixshmem.c
@@ -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}
};
diff --git a/Modules/_opcode.c b/Modules/_opcode.c
index 85e0ffe..cc72cb1 100644
--- a/Modules/_opcode.c
+++ b/Modules/_opcode.c
@@ -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}
};
diff --git a/Modules/_operator.c b/Modules/_operator.c
index 306d450..5d3f883 100644
--- a/Modules/_operator.c
+++ b/Modules/_operator.c
@@ -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}
};
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index d7ffb04..754a326 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -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},
};
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c
index b160cd7..daec4ad 100644
--- a/Modules/_posixsubprocess.c
+++ b/Modules/_posixsubprocess.c
@@ -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}
};
diff --git a/Modules/_queuemodule.c b/Modules/_queuemodule.c
index 5db9b64..aee8db8 100644
--- a/Modules/_queuemodule.c
+++ b/Modules/_queuemodule.c
@@ -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}
};
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index 56b891d..140640a 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -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}
};
diff --git a/Modules/_scproxy.c b/Modules/_scproxy.c
index 042738b..e9170f2 100644
--- a/Modules/_scproxy.c
+++ b/Modules/_scproxy.c
@@ -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}
};
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index 46fed9f..2c25ee3 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -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},
};
diff --git a/Modules/_sre/sre.c b/Modules/_sre/sre.c
index 00fbd96..c1eff63 100644
--- a/Modules/_sre/sre.c
+++ b/Modules/_sre/sre.c
@@ -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},
};
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 885a9c2..9d50b57 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -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}
};
diff --git a/Modules/_stat.c b/Modules/_stat.c
index 8059ec2..a4f15e8 100644
--- a/Modules/_stat.c
+++ b/Modules/_stat.c
@@ -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}
};
diff --git a/Modules/_statisticsmodule.c b/Modules/_statisticsmodule.c
index 78a6552..b84f731 100644
--- a/Modules/_statisticsmodule.c
+++ b/Modules/_statisticsmodule.c
@@ -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}
};
diff --git a/Modules/_struct.c b/Modules/_struct.c
index fa2cd37..905dcbd 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -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}
};
diff --git a/Modules/_suggestions.c b/Modules/_suggestions.c
index 30b524d..80c7179 100644
--- a/Modules/_suggestions.c
+++ b/Modules/_suggestions.c
@@ -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);
}
-
diff --git a/Modules/_sysconfig.c b/Modules/_sysconfig.c
index c76b9e6..c50c5cf 100644
--- a/Modules/_sysconfig.c
+++ b/Modules/_sysconfig.c
@@ -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}
};
diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c
index 9e77744..35d4ffe 100644
--- a/Modules/_testbuffer.c
+++ b/Modules/_testbuffer.c
@@ -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;
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index f5892fc..beae13c 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -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) {
diff --git a/Modules/_testclinic.c b/Modules/_testclinic.c
index 2e9d00a..c7af552 100644
--- a/Modules/_testclinic.c
+++ b/Modules/_testclinic.c
@@ -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;
}
diff --git a/Modules/_testclinic_limited.c b/Modules/_testclinic_limited.c
index 29f1b7c..d5f9808 100644
--- a/Modules/_testclinic_limited.c
+++ b/Modules/_testclinic_limited.c
@@ -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;
}
diff --git a/Modules/_testexternalinspection.c b/Modules/_testexternalinspection.c
index e2f96cd..d9c65fe 100644
--- a/Modules/_testexternalinspection.c
+++ b/Modules/_testexternalinspection.c
@@ -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);
diff --git a/Modules/_testimportmultiple.c b/Modules/_testimportmultiple.c
index a65ca51..c147596 100644
--- a/Modules/_testimportmultiple.c
+++ b/Modules/_testimportmultiple.c
@@ -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);
}
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index f7952a1..de98af3 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -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},
};
diff --git a/Modules/_testlimitedcapi.c b/Modules/_testlimitedcapi.c
index 598071f..f88476f 100644
--- a/Modules/_testlimitedcapi.c
+++ b/Modules/_testlimitedcapi.c
@@ -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;
diff --git a/Modules/_testmultiphase.c b/Modules/_testmultiphase.c
index 21c5f69..ca3d832 100644
--- a/Modules/_testmultiphase.c
+++ b/Modules/_testmultiphase.c
@@ -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},
};
diff --git a/Modules/_testsinglephase.c b/Modules/_testsinglephase.c
index ff533e4..c0eb266 100644
--- a/Modules/_testsinglephase.c
+++ b/Modules/_testsinglephase.c
@@ -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);
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index f5e3b42..39d3097 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -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}
};
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index e378986..ecb7ca8 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -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)) {
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index 6dba3cac..55028dc 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -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);
diff --git a/Modules/_typingmodule.c b/Modules/_typingmodule.c
index 180f3d7..09fbb3c 100644
--- a/Modules/_typingmodule.c
+++ b/Modules/_typingmodule.c
@@ -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}
};
diff --git a/Modules/_uuidmodule.c b/Modules/_uuidmodule.c
index 052cb9f..c5e78b1 100644
--- a/Modules/_uuidmodule.c
+++ b/Modules/_uuidmodule.c
@@ -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}
};
diff --git a/Modules/_weakref.c b/Modules/_weakref.c
index 1ea3ed5..a5c15c0 100644
--- a/Modules/_weakref.c
+++ b/Modules/_weakref.c
@@ -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}
};
diff --git a/Modules/_winapi.c b/Modules/_winapi.c
index 23e3c0d..cd5dd50 100644
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -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}
};
diff --git a/Modules/_xxtestfuzz/_xxtestfuzz.c b/Modules/_xxtestfuzz/_xxtestfuzz.c
index a2dbabc..2952d70 100644
--- a/Modules/_xxtestfuzz/_xxtestfuzz.c
+++ b/Modules/_xxtestfuzz/_xxtestfuzz.c
@@ -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);
}
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index fcd4af6..38c3f0c 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -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},
};
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 317f497..a3b833d 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -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}
};
diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c
index 8e908da..297a8d7 100644
--- a/Modules/atexitmodule.c
+++ b/Modules/atexitmodule.c
@@ -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}
};
diff --git a/Modules/binascii.c b/Modules/binascii.c
index 8649324..250f03a 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -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}
};
diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h
index 766f829..2b446ba 100644
--- a/Modules/cjkcodecs/cjkcodecs.h
+++ b/Modules/cjkcodecs/cjkcodecs.h
@@ -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}
};
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index e5433d7..1c671ad 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -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}
};
diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c
index 57bc556..d901b35 100644
--- a/Modules/cmathmodule.c
+++ b/Modules/cmathmodule.c
@@ -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}
};
diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c
index 97e5f01..3f96f2f 100644
--- a/Modules/errnomodule.c
+++ b/Modules/errnomodule.c
@@ -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}
};
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index c70d43a..cfa3cbd 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -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}
};
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c
index e24e5f9..b6eeec2 100644
--- a/Modules/fcntlmodule.c
+++ b/Modules/fcntlmodule.c
@@ -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}
};
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 8a1b483..57e4aae 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -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}
};
diff --git a/Modules/grpmodule.c b/Modules/grpmodule.c
index a1fa6cf..f7d3e12 100644
--- a/Modules/grpmodule.c
+++ b/Modules/grpmodule.c
@@ -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}
};
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 21ce3ec..8641c2f 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -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}
};
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 8ba0431..a3cbfc3 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -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}
};
diff --git a/Modules/md5module.c b/Modules/md5module.c
index 9cbf11f..ef9163e 100644
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -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}
};
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 0cce7c2..dfc16ff 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -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}
};
diff --git a/Modules/overlapped.c b/Modules/overlapped.c
index b9881d9..77ee70a 100644
--- a/Modules/overlapped.c
+++ b/Modules/overlapped.c
@@ -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}
};
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index e1a14e7..9f4be98 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -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}
};
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
index f58735a..2240e20 100644
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -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}
};
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index f04f96b..f67d480 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -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}
};
diff --git a/Modules/readline.c b/Modules/readline.c
index c5c3453..f59f8a9 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -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) {
diff --git a/Modules/resource.c b/Modules/resource.c
index 8ee07bd..3fe18e7 100644
--- a/Modules/resource.c
+++ b/Modules/resource.c
@@ -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}
};
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 6ea141a..3eaee22 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -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}
};
diff --git a/Modules/sha1module.c b/Modules/sha1module.c
index 345a6c2..34a427a 100644
--- a/Modules/sha1module.c
+++ b/Modules/sha1module.c
@@ -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}
};
diff --git a/Modules/sha2module.c b/Modules/sha2module.c
index 60be422..7d6a1e4 100644
--- a/Modules/sha2module.c
+++ b/Modules/sha2module.c
@@ -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}
};
diff --git a/Modules/sha3module.c b/Modules/sha3module.c
index c30e924..084332c 100644
--- a/Modules/sha3module.c
+++ b/Modules/sha3module.c
@@ -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}
};
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 08fedea..7de5ebe 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -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}
};
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 7720d59..daec560 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -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},
};
diff --git a/Modules/symtablemodule.c b/Modules/symtablemodule.c
index ddc9ac3..b4dbb54 100644
--- a/Modules/symtablemodule.c
+++ b/Modules/symtablemodule.c
@@ -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}
};
diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c
index cb3f2b0..14e7ca5 100644
--- a/Modules/syslogmodule.c
+++ b/Modules/syslogmodule.c
@@ -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}
};
diff --git a/Modules/termios.c b/Modules/termios.c
index a29474d..f2c5a4b 100644
--- a/Modules/termios.c
+++ b/Modules/termios.c
@@ -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}
};
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 3211c75..0511339 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -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}
};
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index 6ae35b9..333ffe6 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -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}
};
diff --git a/Modules/xxlimited.c b/Modules/xxlimited.c
index 3357b80..d86741e 100644
--- a/Modules/xxlimited.c
+++ b/Modules/xxlimited.c
@@ -62,10 +62,10 @@
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}
};
diff --git a/Modules/xxlimited_35.c b/Modules/xxlimited_35.c
index 52690d9..1063e54 100644
--- a/Modules/xxlimited_35.c
+++ b/Modules/xxlimited_35.c
@@ -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}
};
diff --git a/Modules/xxmodule.c b/Modules/xxmodule.c
index 1e4e0ea..a46bf8f 100644
--- a/Modules/xxmodule.c
+++ b/Modules/xxmodule.c
@@ -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},
};
diff --git a/Modules/xxsubtype.c b/Modules/xxsubtype.c
index 560f43e..9c548f4 100644
--- a/Modules/xxsubtype.c
+++ b/Modules/xxsubtype.c
@@ -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},
};
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index fe9a6d8..b115f67 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -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}
};
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 2f6adb9..d877eda 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -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:
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 67b1282..057b417 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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}
};
diff --git a/PC/_testconsole.c b/PC/_testconsole.c
index f1ace00..0dcea86 100644
--- a/PC/_testconsole.c
+++ b/PC/_testconsole.c
@@ -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},
};
diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c
index 5ff7032..b170e06 100644
--- a/PC/msvcrtmodule.c
+++ b/PC/msvcrtmodule.c
@@ -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}
};
diff --git a/PC/winreg.c b/PC/winreg.c
index 8096d17..efdf8ad 100644
--- a/PC/winreg.c
+++ b/PC/winreg.c
@@ -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}
};
diff --git a/PC/winsound.c b/PC/winsound.c
index a6b2dac..094c77a 100644
--- a/PC/winsound.c
+++ b/PC/winsound.c
@@ -35,10 +35,10 @@
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}
};
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index c4df2c5..1f0be45 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -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}
};
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index cc7734e..1953142 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -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}
};
diff --git a/Python/Python-tokenize.c b/Python/Python-tokenize.c
index a789170..41e8107 100644
--- a/Python/Python-tokenize.c
+++ b/Python/Python-tokenize.c
@@ -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}
};
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 2ba704d..793cbc6 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -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}
};
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 722353e..88d858d 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -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
diff --git a/Python/import.c b/Python/import.c
index f120a38..4f91f03 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -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}
};
diff --git a/Python/marshal.c b/Python/marshal.c
index 4bd8bb1..ca22d6d 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -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}
};
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index f469f16..645b76fc 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -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) {