summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-06-15 17:54:38 (GMT)
committerGitHub <noreply@github.com>2017-06-15 17:54:38 (GMT)
commit145541cfa05394c38cfd64c0be2c5fb382860995 (patch)
tree87b9fc17c18c011488d260208a9a0b01e71b73e9
parent96c7c0685045b739fdc5145018cddfd252155713 (diff)
downloadcpython-145541cfa05394c38cfd64c0be2c5fb382860995.zip
cpython-145541cfa05394c38cfd64c0be2c5fb382860995.tar.gz
cpython-145541cfa05394c38cfd64c0be2c5fb382860995.tar.bz2
bpo-30626: Fix error handling in PyImport_Import(). (#2103)
In rare circumstances PyImport_Import() could return NULL without raising an error.
-rw-r--r--Python/import.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/import.c b/Python/import.c
index 9a78d6a..d8a207b 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1784,9 +1784,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);