mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Fix error paths and edge cases
This commit is contained in:
parent
952ac2164d
commit
80133a59ff
2 changed files with 23 additions and 7 deletions
|
|
@ -178,6 +178,7 @@ new_module_notrack(PyTypeObject *mt)
|
|||
m->md_state = NULL;
|
||||
m->md_weaklist = NULL;
|
||||
m->md_name = NULL;
|
||||
m->m_dict_version = 0;
|
||||
m->md_token_is_def = false;
|
||||
#ifdef Py_GIL_DISABLED
|
||||
m->md_requires_gil = true;
|
||||
|
|
|
|||
|
|
@ -3874,6 +3874,10 @@ _PyImport_LoadLazyImportTstate(PyThreadState *tstate, PyObject *lazy_import)
|
|||
if (PyMapping_GetOptionalItem(lz->lz_builtins, &_Py_ID(__import__), &import_func) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (import_func == NULL) {
|
||||
PyErr_SetString(PyExc_ImportError, "__import__ not found");
|
||||
goto error;
|
||||
}
|
||||
if (full) {
|
||||
obj = _PyEval_ImportNameWithImport(tstate,
|
||||
import_func,
|
||||
|
|
@ -4305,7 +4309,12 @@ register_lazy_on_parent(PyThreadState *tstate, PyObject *name, PyObject *builtin
|
|||
if (parent_dict == NULL) {
|
||||
goto done;
|
||||
}
|
||||
if (PyDict_CheckExact(parent_dict) && !PyDict_Contains(parent_dict, child)) {
|
||||
if (PyDict_CheckExact(parent_dict)) {
|
||||
int contains = PyDict_Contains(parent_dict, child);
|
||||
if (contains < 0) {
|
||||
goto done;
|
||||
}
|
||||
if (!contains) {
|
||||
PyObject *lazy_module_attr = _PyLazyImport_New(builtins, parent, child);
|
||||
if (lazy_module_attr == NULL) {
|
||||
goto done;
|
||||
|
|
@ -4317,6 +4326,7 @@ register_lazy_on_parent(PyThreadState *tstate, PyObject *name, PyObject *builtin
|
|||
Py_DECREF(lazy_module_attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Py_DECREF(name);
|
||||
name = parent;
|
||||
|
|
@ -4344,7 +4354,8 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
|
|||
}
|
||||
|
||||
PyInterpreterState *interp = tstate->interp;
|
||||
assert(_PyEval_GetFrame()->f_globals == _PyEval_GetFrame()->f_locals); // should only be called in global scope
|
||||
_PyInterpreterFrame *frame = _PyEval_GetFrame();
|
||||
assert(frame != NULL && frame->f_globals == frame->f_locals); // should only be called in global scope
|
||||
|
||||
// Check if the filter disables the lazy import
|
||||
PyObject *filter = FT_ATOMIC_LOAD_PTR_RELAXED(LAZY_IMPORTS_FILTER(interp));
|
||||
|
|
@ -4374,6 +4385,10 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
|
|||
int is_true = PyObject_IsTrue(res);
|
||||
Py_DECREF(res);
|
||||
|
||||
if (is_true < 0) {
|
||||
Py_DECREF(abs_name);
|
||||
return NULL;
|
||||
}
|
||||
if (!is_true) {
|
||||
Py_DECREF(abs_name);
|
||||
return PyImport_ImportModuleLevelObject(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue