mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-09 19:30:29 +00:00
remove spec._initializing + related locking check
spec._initializing is only there for a single check + optimization within import.c that ends up calling _lock_unlock_module. Since we are ignoring locks for the time being, this check can also be ignored.
This commit is contained in:
parent
a0c31d2ab6
commit
fccb0f11b0
2 changed files with 7 additions and 48 deletions
18
third_party/python/Lib/importlib/_bootstrap.py
vendored
18
third_party/python/Lib/importlib/_bootstrap.py
vendored
|
@ -300,22 +300,14 @@ class _installed_safely:
|
||||||
# This must be done before putting the module in sys.modules
|
# This must be done before putting the module in sys.modules
|
||||||
# (otherwise an optimization shortcut in import.c becomes
|
# (otherwise an optimization shortcut in import.c becomes
|
||||||
# wrong)
|
# wrong)
|
||||||
self._spec._initializing = True
|
|
||||||
sys.modules[self._spec.name] = self._module
|
sys.modules[self._spec.name] = self._module
|
||||||
|
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
try:
|
spec = self._spec
|
||||||
spec = self._spec
|
if args and any(arg is not None for arg in args):
|
||||||
if any(arg is not None for arg in args):
|
sys.modules.pop(spec.name, None)
|
||||||
try:
|
else:
|
||||||
del sys.modules[spec.name]
|
_verbose_message('import {!r} # {!r}', spec.name, spec.loader)
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
_verbose_message('import {!r} # {!r}', spec.name, spec.loader)
|
|
||||||
finally:
|
|
||||||
self._spec._initializing = False
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleSpec:
|
class ModuleSpec:
|
||||||
"""The specification for a module, used for loading.
|
"""The specification for a module, used for loading.
|
||||||
|
|
37
third_party/python/Python/import.c
vendored
37
third_party/python/Python/import.c
vendored
|
@ -1588,40 +1588,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
|
||||||
|
|
||||||
mod = PyDict_GetItem(interp->modules, abs_name);
|
mod = PyDict_GetItem(interp->modules, abs_name);
|
||||||
if (mod != NULL && mod != Py_None) {
|
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;
|
|
||||||
|
|
||||||
Py_INCREF(mod);
|
Py_INCREF(mod);
|
||||||
/* Optimization: only call _bootstrap._lock_unlock_module() if
|
|
||||||
__spec__._initializing is true.
|
|
||||||
NOTE: because of this, initializing must be set *before*
|
|
||||||
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 (0 && initializing > 0) {
|
|
||||||
value = _PyObject_CallMethodIdObjArgs(interp->importlib,
|
|
||||||
&PyId__lock_unlock_module, abs_name,
|
|
||||||
NULL);
|
|
||||||
if (value == NULL)
|
|
||||||
goto error;
|
|
||||||
Py_DECREF(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mod = _PyObject_CallMethodIdObjArgs(interp->importlib,
|
mod = _PyObject_CallMethodIdObjArgs(interp->importlib,
|
||||||
|
@ -2462,8 +2429,7 @@ static PyObject *SFLObject_get_code(SourcelessFileLoader *self, PyObject *arg) {
|
||||||
// bytes_data = _validate_bytecode_header(data, name=fullname, path=path)
|
// bytes_data = _validate_bytecode_header(data, name=fullname, path=path)
|
||||||
headerlen = fread(bytecode_header, sizeof(char), sizeof(bytecode_header), fp);
|
headerlen = fread(bytecode_header, sizeof(char), sizeof(bytecode_header), fp);
|
||||||
|
|
||||||
if (headerlen < 4 || (magic = READ16LE(bytecode_header)) != 3390 ||
|
if (headerlen < 4 || (magic = READ32LE(bytecode_header)) != PyImport_GetMagicNumber()) {
|
||||||
bytecode_header[2] != '\r' || bytecode_header[3] != '\n') {
|
|
||||||
PyErr_Format(PyExc_ImportError, "bad magic number in %s: %d\n", name,
|
PyErr_Format(PyExc_ImportError, "bad magic number in %s: %d\n", name,
|
||||||
magic);
|
magic);
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -2636,6 +2602,7 @@ static PyTypeObject SourcelessFileLoaderType = {
|
||||||
* to be portable to Windows without using C++. */
|
* to be portable to Windows without using C++. */
|
||||||
PyVarObject_HEAD_INIT(NULL, 0).tp_name =
|
PyVarObject_HEAD_INIT(NULL, 0).tp_name =
|
||||||
"_imp.SourcelessFileLoader", /*tp_name*/
|
"_imp.SourcelessFileLoader", /*tp_name*/
|
||||||
|
.tp_base = &PyBaseObject_Type, /*tp_base*/
|
||||||
.tp_basicsize = sizeof(SourcelessFileLoader), /*tp_basicsize*/
|
.tp_basicsize = sizeof(SourcelessFileLoader), /*tp_basicsize*/
|
||||||
.tp_dealloc = (destructor)SFLObject_dealloc, /*tp_dealloc*/
|
.tp_dealloc = (destructor)SFLObject_dealloc, /*tp_dealloc*/
|
||||||
.tp_hash = (hashfunc)SFLObject_hash, /*tp_hash*/
|
.tp_hash = (hashfunc)SFLObject_hash, /*tp_hash*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue