summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-06-15 18:15:11 (GMT)
committerGitHub <noreply@github.com>2017-06-15 18:15:11 (GMT)
commitfab05de21480fc54a5101cf813195cb32724b5ad (patch)
treea383051a79e526670a283e86ae35c0e2498d5149 /Python
parente45ea377b8d9ae23893d4587003c6d3e7f54b99a (diff)
downloadcpython-fab05de21480fc54a5101cf813195cb32724b5ad.zip
cpython-fab05de21480fc54a5101cf813195cb32724b5ad.tar.gz
cpython-fab05de21480fc54a5101cf813195cb32724b5ad.tar.bz2
[3.6] bpo-30626: Fix error handling in PyImport_Import(). (GH-2103) (#2221)
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 cd865a5..a23a102 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1785,9 +1785,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);