.. 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
.. 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
^^^^^^^^^^^^^
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) {
#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 */
# 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;
--- /dev/null
+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()
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:
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 [
) = 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()
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
--- /dev/null
+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.
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}
};
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},
};
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}
};
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}
};
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}
};
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}
};
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}
};
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}
};
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}
};
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}
};
-// 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
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}
};
// 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}
};
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);
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);
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}
};
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},
};
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},
};
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}
};
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}
};
{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}
};
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}
};
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},
};
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},
};
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},
};
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},
};
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}
};
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}
};
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}
};
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}
};
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}
};
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>
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}
};
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}
};
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}
};
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},
};
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}
};
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}
};
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}
};
* 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>
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}
};
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},
};
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},
};
{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}
};
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}
};
/* 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"
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}
};
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}
};
{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);
}
-
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}
};
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;
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) {
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;
}
if (m == NULL) {
return NULL;
}
+#ifdef Py_GIL_DISABLED
+ PyModule_ExperimentalSetGIL(m, Py_MOD_GIL_NOT_USED);
+#endif
return m;
}
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);
#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
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
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);
}
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},
};
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;
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},
};
/**** 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 */
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 */
{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},
};
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},
};
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},
};
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},
};
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}
};
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);
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},
};
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},
};
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},
};
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.
if (module == NULL) {
return NULL;
}
+#ifdef Py_GIL_DISABLED
+ PyModule_ExperimentalSetGIL(module, Py_MOD_GIL_NOT_USED);
+#endif
assert(get_module_state(module) == NULL);
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);
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}
};
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)) {
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);
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}
};
* 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"
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}
};
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}
};
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}
};
{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
PyMODINIT_FUNC
PyInit__xxtestfuzz(void)
{
- return PyModule_Create(&_fuzzmodule);
+ return PyModuleDef_Init(&_fuzzmodule);
}
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},
};
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}
};
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}
};
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}
};
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}
};
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}
};
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}
};
/* 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"
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}
};
{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}
};
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}
};
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}
};
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}
};
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}
};
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}
};
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}
};
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}
};
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}
};
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}
};
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}
};
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}
};
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) {
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}
};
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}
};
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}
};
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}
};
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}
};
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}
};
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},
};
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}
};
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}
};
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}
};
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}
};
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}
};
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"
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}
};
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}
};
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},
};
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},
};
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}
};
}
}
m->md_def = module;
+#ifdef Py_GIL_DISABLE
+ m->md_gil = Py_MOD_GIL_USED;
+#endif
return (PyObject*)m;
}
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;
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(
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(
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)
{
}
break;
case Py_mod_multiple_interpreters:
+ case Py_mod_gil:
/* handled in PyModule_FromDefAndSpec2 */
break;
default:
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}
};
/* 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"
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},
};
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}
};
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}
};
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>
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}
};
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}
};
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}
};
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}
};
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}
};
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
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}
};
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}
};
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) {