diff options
author | Stefan Krah <skrah@bytereef.org> | 2019-03-25 21:50:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-25 21:50:58 +0100 |
commit | 027b09c5a13aac9e14a3b43bb385298d549c3833 (patch) | |
tree | 44c35e9ec4e1ae42dde580a0ea369e5a1c32de1a /Python/import.c | |
parent | d1e768a67707bf7bb426c1537e1a764e89eaff78 (diff) | |
download | cpython-git-027b09c5a13aac9e14a3b43bb385298d549c3833.tar.gz |
bpo-36370: Check for PyErr_Occurred() after PyImport_GetModule() (GH-12504)
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/Python/import.c b/Python/import.c index bf3a99414f..c00c3aa640 100644 --- a/Python/import.c +++ b/Python/import.c @@ -966,11 +966,10 @@ exec_code_in_module(PyObject *name, PyObject *module_dict, PyObject *code_object Py_DECREF(v); m = PyImport_GetModule(name); - if (m == NULL) { + if (m == NULL && !PyErr_Occurred()) { PyErr_Format(PyExc_ImportError, "Loaded module %R not found in sys.modules", name); - return NULL; } return m; @@ -1735,6 +1734,10 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, } mod = PyImport_GetModule(abs_name); + if (mod == NULL && PyErr_Occurred()) { + goto error; + } + if (mod != NULL && mod != Py_None) { _Py_IDENTIFIER(__spec__); _Py_IDENTIFIER(_lock_unlock_module); @@ -1810,9 +1813,11 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, final_mod = PyImport_GetModule(to_return); Py_DECREF(to_return); if (final_mod == NULL) { - PyErr_Format(PyExc_KeyError, - "%R not in sys.modules as expected", - to_return); + if (!PyErr_Occurred()) { + PyErr_Format(PyExc_KeyError, + "%R not in sys.modules as expected", + to_return); + } goto error; } } @@ -1875,6 +1880,10 @@ PyImport_ReloadModule(PyObject *m) PyObject *reloaded_module = NULL; PyObject *imp = _PyImport_GetModuleId(&PyId_imp); if (imp == NULL) { + if (PyErr_Occurred()) { + return NULL; + } + imp = PyImport_ImportModule("imp"); if (imp == NULL) { return NULL; |