summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-06-15 18:15:26 (GMT)
committerGitHub <noreply@github.com>2017-06-15 18:15:26 (GMT)
commit263dcc39daa74066c2b2fcb007a4bd4f7ec65073 (patch)
tree840aa9da9e6b77ced9efe3428993c92045df6ab8 /Python
parentfb0825c2784f80689c4c00c3ede22958faaf512c (diff)
downloadcpython-263dcc39daa74066c2b2fcb007a4bd4f7ec65073.zip
cpython-263dcc39daa74066c2b2fcb007a4bd4f7ec65073.tar.gz
cpython-263dcc39daa74066c2b2fcb007a4bd4f7ec65073.tar.bz2
[3.5] bpo-30626: Fix error handling in PyImport_Import(). (GH-2103) (#2222)
In rare circumstances PyImport_Import() could return NULL without raising an error. (cherry picked from commit 145541c)
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/import.c b/Python/import.c
index ea8bc00..4f08d5e 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1806,9 +1806,13 @@ PyImport_Import(PyObject *module_name)
Py_DECREF(r);
modules = PyImport_GetModuleDict();
- r = PyDict_GetItem(modules, module_name);
- if (r != NULL)
+ r = PyDict_GetItemWithError(modules, module_name);
+ if (r != NULL) {
Py_INCREF(r);
+ }
+ else if (!PyErr_Occurred()) {
+ PyErr_SetObject(PyExc_KeyError, module_name);
+ }
err:
Py_XDECREF(globals);