diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-05-05 20:04:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-05 20:04:55 (GMT) |
commit | 1c420e138fd828895b6bd3c44ef99156e8796095 (patch) | |
tree | fa6b714a49de1ee679c2de50eeb13735a8c69b1a /Objects | |
parent | 55671fe04700ccb4e73c8db3dd1e9c031dafe700 (diff) | |
download | cpython-1c420e138fd828895b6bd3c44ef99156e8796095.zip cpython-1c420e138fd828895b6bd3c44ef99156e8796095.tar.gz cpython-1c420e138fd828895b6bd3c44ef99156e8796095.tar.bz2 |
gh-104108: Add the Py_mod_multiple_interpreters Module Def Slot (gh-104148)
I'll be adding a value to indicate support for per-interpreter GIL in gh-99114.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/moduleobject.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index ffcd90e..63f4226 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -245,6 +245,8 @@ PyModule_FromDefAndSpec2(PyModuleDef* def, PyObject *spec, int module_api_versio PyObject *(*create)(PyObject *, PyModuleDef*) = NULL; PyObject *nameobj; PyObject *m = NULL; + int has_multiple_interpreters_slot = 0; + void *multiple_interpreters = (void *)0; int has_execution_slots = 0; const char *name; int ret; @@ -287,6 +289,17 @@ PyModule_FromDefAndSpec2(PyModuleDef* def, PyObject *spec, int module_api_versio case Py_mod_exec: has_execution_slots = 1; break; + case Py_mod_multiple_interpreters: + if (has_multiple_interpreters_slot) { + PyErr_Format( + PyExc_SystemError, + "module %s has more than one 'multiple interpreters' slots", + name); + goto error; + } + multiple_interpreters = cur_slot->value; + has_multiple_interpreters_slot = 1; + break; default: assert(cur_slot->slot < 0 || cur_slot->slot > _Py_mod_LAST_SLOT); PyErr_Format( @@ -297,6 +310,20 @@ PyModule_FromDefAndSpec2(PyModuleDef* def, PyObject *spec, int module_api_versio } } + /* By default, multi-phase init modules are expected + to work under multiple interpreters. */ + if (!has_multiple_interpreters_slot) { + multiple_interpreters = Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED; + } + if (multiple_interpreters == Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED) { + PyInterpreterState *interp = _PyInterpreterState_GET(); + if (!_Py_IsMainInterpreter(interp) + && _PyImport_CheckSubinterpIncompatibleExtensionAllowed(name) < 0) + { + goto error; + } + } + if (create) { m = create(spec, def); if (m == NULL) { @@ -421,6 +448,9 @@ PyModule_ExecDef(PyObject *module, PyModuleDef *def) return -1; } break; + case Py_mod_multiple_interpreters: + /* handled in PyModule_FromDefAndSpec2 */ + break; default: PyErr_Format( PyExc_SystemError, |