https://github.com/python/cpython/commit/fc8d2cba541f378df0a439412665f3dbe0b9ae3c
commit: fc8d2cba541f378df0a439412665f3dbe0b9ae3c
branch: main
author: Petr Viktorin <[email protected]>
committer: encukou <[email protected]>
date: 2025-02-24T14:59:19+01:00
summary:
gh-129405: Fix doc for Py_mod_multiple_interpreters default, and add test
(GH-129406)
files:
M Doc/c-api/module.rst
M Lib/test/test_import/__init__.py
M Modules/_testmultiphase.c
diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst
index f71089370152ce..01a8e44828b191 100644
--- a/Doc/c-api/module.rst
+++ b/Doc/c-api/module.rst
@@ -415,7 +415,7 @@ The available slot types are:
in one module definition.
If ``Py_mod_multiple_interpreters`` is not specified, the import
- machinery defaults to ``Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED``.
+ machinery defaults to ``Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED``.
.. versionadded:: 3.12
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index 207b7ae7517450..f58633e0ce8dda 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -2386,8 +2386,10 @@ def test_single_init_extension_compat(self):
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase
module")
def test_multi_init_extension_compat(self):
+ # Module with Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
module = '_testmultiphase'
require_extension(module)
+
if not Py_GIL_DISABLED:
with self.subTest(f'{module}: not strict'):
self.check_compatible_here(module, strict=False)
@@ -2398,6 +2400,8 @@ def test_multi_init_extension_compat(self):
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase
module")
def test_multi_init_extension_non_isolated_compat(self):
+ # Module with Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED
+ # and Py_MOD_GIL_NOT_USED
modname = '_test_non_isolated'
filename = _testmultiphase.__file__
module = import_extension_from_file(modname, filename)
@@ -2413,20 +2417,31 @@ def test_multi_init_extension_non_isolated_compat(self):
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase
module")
def test_multi_init_extension_per_interpreter_gil_compat(self):
- modname = '_test_shared_gil_only'
- filename = _testmultiphase.__file__
- module = import_extension_from_file(modname, filename)
- require_extension(module)
- with self.subTest(f'{modname}: isolated, strict'):
- self.check_incompatible_here(modname, filename, isolated=True)
- with self.subTest(f'{modname}: not isolated, strict'):
- self.check_compatible_here(modname, filename,
- strict=True, isolated=False)
- if not Py_GIL_DISABLED:
- with self.subTest(f'{modname}: not isolated, not strict'):
- self.check_compatible_here(modname, filename,
- strict=False, isolated=False)
+ # _test_shared_gil_only:
+ # Explicit Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED (default)
+ # and Py_MOD_GIL_NOT_USED
+ # _test_no_multiple_interpreter_slot:
+ # No Py_mod_multiple_interpreters slot
+ # and Py_MOD_GIL_NOT_USED
+ for modname in ('_test_shared_gil_only',
+ '_test_no_multiple_interpreter_slot'):
+ with self.subTest(modname=modname):
+
+ filename = _testmultiphase.__file__
+ module = import_extension_from_file(modname, filename)
+
+ require_extension(module)
+ with self.subTest(f'{modname}: isolated, strict'):
+ self.check_incompatible_here(modname, filename,
+ isolated=True)
+ with self.subTest(f'{modname}: not isolated, strict'):
+ self.check_compatible_here(modname, filename,
+ strict=True, isolated=False)
+ if not Py_GIL_DISABLED:
+ with self.subTest(f'{modname}: not isolated, not strict'):
+ self.check_compatible_here(
+ modname, filename, strict=False, isolated=False)
@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
def test_python_compat(self):
diff --git a/Modules/_testmultiphase.c b/Modules/_testmultiphase.c
index 886b260aceb20d..3f456e1f40da1f 100644
--- a/Modules/_testmultiphase.c
+++ b/Modules/_testmultiphase.c
@@ -969,3 +969,21 @@ PyInit__test_shared_gil_only(void)
{
return PyModuleDef_Init(&shared_gil_only_def);
}
+
+
+static PyModuleDef_Slot no_multiple_interpreter_slot_slots[] = {
+ {Py_mod_exec, execfunc},
+ {Py_mod_gil, Py_MOD_GIL_NOT_USED},
+ {0, NULL},
+};
+
+static PyModuleDef no_multiple_interpreter_slot_def = TEST_MODULE_DEF(
+ "_test_no_multiple_interpreter_slot",
+ no_multiple_interpreter_slot_slots,
+ testexport_methods);
+
+PyMODINIT_FUNC
+PyInit__test_no_multiple_interpreter_slot(void)
+{
+ return PyModuleDef_Init(&no_multiple_interpreter_slot_def);
+}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]