]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-129405: Fix doc for Py_mod_multiple_interpreters default, and add test...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 24 Feb 2025 15:49:35 +0000 (16:49 +0100)
committerGitHub <noreply@github.com>
Mon, 24 Feb 2025 15:49:35 +0000 (16:49 +0100)
(cherry picked from commit fc8d2cba541f378df0a439412665f3dbe0b9ae3c)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Doc/c-api/module.rst
Lib/test/test_import/__init__.py
Modules/_testmultiphase.c

index f71089370152ce61bae8e2ce756f0b181a4957a8..01a8e44828b1916909d154857dc1b8d4e51f3460 100644 (file)
@@ -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
 
index d9246c0ea70a046c9299d2672d638e2298518900..c5a545777a9ae696cc4d56dc5f4329951a7f082f 100644 (file)
@@ -2404,8 +2404,10 @@ class SubinterpImportTests(unittest.TestCase):
 
     @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)
@@ -2416,6 +2418,8 @@ class SubinterpImportTests(unittest.TestCase):
 
     @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)
@@ -2431,20 +2435,31 @@ class SubinterpImportTests(unittest.TestCase):
 
     @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):
index 886b260aceb20d89bac4db38ab5840501cdf7c01..3f456e1f40da1f55644d0367fc5e63dd1ca2d03a 100644 (file)
@@ -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);
+}