bpo-44050: Extension modules can share state when they don't support … · python/cpython@b9bb748 · GitHub
Skip to content

Commit b9bb748

Browse files
authored
bpo-44050: Extension modules can share state when they don't support sub-interpreters. (GH-27794)
Automerge-Triggered-By: GH:encukou
1 parent 5146877 commit b9bb748

4 files changed

Lines changed: 59 additions & 1 deletion

File tree

Lib/test/test_capi.py

Lines changed: 31 additions & 0 deletions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Extensions that indicate they use global state (by setting ``m_size`` to -1)
2+
can again be used in multiple interpreters. This reverts to behavior of
3+
Python 3.8.

Modules/_testmultiphase.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,28 @@ PyInit__testmultiphase_meth_state_access(PyObject *spec)
844844
return PyModuleDef_Init(&def_meth_state_access);
845845
}
846846

847+
static PyModuleDef def_module_state_shared = {
848+
PyModuleDef_HEAD_INIT,
849+
.m_name = "_test_module_state_shared",
850+
.m_doc = PyDoc_STR("Regression Test module for single-phase init."),
851+
.m_size = -1,
852+
};
853+
854+
PyMODINIT_FUNC
855+
PyInit__test_module_state_shared(PyObject *spec)
856+
{
857+
PyObject *module = PyModule_Create(&def_module_state_shared);
858+
if (module == NULL) {
859+
return NULL;
860+
}
861+
862+
if (PyModule_AddObjectRef(module, "Error", PyExc_Exception) < 0) {
863+
Py_DECREF(module);
864+
return NULL;
865+
}
866+
return module;
867+
}
868+
847869

848870
/*** Helper for imp test ***/
849871

Python/import.c

Lines changed: 3 additions & 1 deletion

0 commit comments

Comments
 (0)