diff --git a/third_party/python/Lib/importlib/_bootstrap.py b/third_party/python/Lib/importlib/_bootstrap.py index ec14d8471a7..7ff1415a2d1 100644 --- a/third_party/python/Lib/importlib/_bootstrap.py +++ b/third_party/python/Lib/importlib/_bootstrap.py @@ -300,22 +300,14 @@ def __enter__(self): # This must be done before putting the module in sys.modules # (otherwise an optimization shortcut in import.c becomes # wrong) - self._spec._initializing = True sys.modules[self._spec.name] = self._module def __exit__(self, *args): - try: - spec = self._spec - if any(arg is not None for arg in args): - try: - del sys.modules[spec.name] - except KeyError: - pass - else: - _verbose_message('import {!r} # {!r}', spec.name, spec.loader) - finally: - self._spec._initializing = False - + spec = self._spec + if args and any(arg is not None for arg in args): + sys.modules.pop(spec.name, None) + else: + _verbose_message('import {!r} # {!r}', spec.name, spec.loader) class ModuleSpec: """The specification for a module, used for loading. diff --git a/third_party/python/Python/import.c b/third_party/python/Python/import.c index f28dc798be4..5534cec2b8a 100644 --- a/third_party/python/Python/import.c +++ b/third_party/python/Python/import.c @@ -1588,40 +1588,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, mod = PyDict_GetItem(interp->modules, 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; - 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 { 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) headerlen = fread(bytecode_header, sizeof(char), sizeof(bytecode_header), fp); - if (headerlen < 4 || (magic = READ16LE(bytecode_header)) != 3390 || - bytecode_header[2] != '\r' || bytecode_header[3] != '\n') { + if (headerlen < 4 || (magic = READ32LE(bytecode_header)) != PyImport_GetMagicNumber()) { PyErr_Format(PyExc_ImportError, "bad magic number in %s: %d\n", name, magic); goto exit; @@ -2636,6 +2602,7 @@ static PyTypeObject SourcelessFileLoaderType = { * to be portable to Windows without using C++. */ PyVarObject_HEAD_INIT(NULL, 0).tp_name = "_imp.SourcelessFileLoader", /*tp_name*/ + .tp_base = &PyBaseObject_Type, /*tp_base*/ .tp_basicsize = sizeof(SourcelessFileLoader), /*tp_basicsize*/ .tp_dealloc = (destructor)SFLObject_dealloc, /*tp_dealloc*/ .tp_hash = (hashfunc)SFLObject_hash, /*tp_hash*/