Skip to content

Commit

Permalink
[3.5] bpo-30626: Fix error handling in PyImport_Import(). (GH-2103) (#…
Browse files Browse the repository at this point in the history
…2222)

In rare circumstances PyImport_Import() could return NULL without raising
an error.
(cherry picked from commit 145541c)
  • Loading branch information
serhiy-storchaka committed Jun 15, 2017
1 parent fb0825c commit 263dcc3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 263dcc3

Please sign in to comment.