Commit 145541cf authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-30626: Fix error handling in PyImport_Import(). (#2103)

In rare circumstances PyImport_Import() could return NULL without raising
an error.
parent 96c7c068
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment