diff options
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/Python/import.c b/Python/import.c index 1e8c07b..e761f65 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1721,11 +1721,8 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, mod = PyImport_GetModule(abs_name); if (mod != NULL && mod != Py_None) { _Py_IDENTIFIER(__spec__); - _Py_IDENTIFIER(_initializing); _Py_IDENTIFIER(_lock_unlock_module); - PyObject *value = NULL; PyObject *spec; - int initializing = 0; /* Optimization: only call _bootstrap._lock_unlock_module() if __spec__._initializing is true. @@ -1733,26 +1730,17 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, stuffing the new module in sys.modules. */ spec = _PyObject_GetAttrId(mod, &PyId___spec__); - if (spec != NULL) { - value = _PyObject_GetAttrId(spec, &PyId__initializing); - Py_DECREF(spec); - } - if (value == NULL) - PyErr_Clear(); - else { - initializing = PyObject_IsTrue(value); - Py_DECREF(value); - if (initializing == -1) - PyErr_Clear(); - if (initializing > 0) { - value = _PyObject_CallMethodIdObjArgs(interp->importlib, - &PyId__lock_unlock_module, abs_name, - NULL); - if (value == NULL) - goto error; - Py_DECREF(value); + if (_PyModuleSpec_IsInitializing(spec)) { + PyObject *value = _PyObject_CallMethodIdObjArgs(interp->importlib, + &PyId__lock_unlock_module, abs_name, + NULL); + if (value == NULL) { + Py_DECREF(spec); + goto error; } + Py_DECREF(value); } + Py_XDECREF(spec); } else { Py_XDECREF(mod); |