mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-141780: Make PyModule_FromSlotsAndSpec enable GIL if needed (GH-141785)
This commit is contained in:
parent
6462322840
commit
bf66bce4ee
9 changed files with 183 additions and 22 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "Python.h"
|
||||
#include "pycore_call.h" // _PyObject_CallNoArgs()
|
||||
#include "pycore_ceval.h" // _PyEval_EnableGILTransient()
|
||||
#include "pycore_dict.h" // _PyDict_EnablePerThreadRefcounting()
|
||||
#include "pycore_fileutils.h" // _Py_wgetcwd
|
||||
#include "pycore_import.h" // _PyImport_GetNextModuleIndex()
|
||||
|
|
@ -522,6 +523,22 @@ module_from_def_and_spec(
|
|||
#undef COPY_COMMON_SLOT
|
||||
}
|
||||
|
||||
#ifdef Py_GIL_DISABLED
|
||||
// For modules created directly from slots (not from a def), we enable
|
||||
// the GIL here (pairing `_PyEval_EnableGILTransient` with
|
||||
// an immediate `_PyImport_EnableGILAndWarn`).
|
||||
// For modules created from a def, the caller is responsible for this.
|
||||
if (!original_def && requires_gil) {
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
if (_PyEval_EnableGILTransient(tstate) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (_PyImport_EnableGILAndWarn(tstate, nameobj) < 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* By default, multi-phase init modules are expected
|
||||
to work under multiple interpreters. */
|
||||
if (!has_multiple_interpreters_slot) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue