bpo-30626: Fix error handling in PyImport_Import(). (#2103)
In rare circumstances PyImport_Import() could return NULL without raising an error.
This commit is contained in:
parent
96c7c06850
commit
145541cfa0
|
@ -1784,9 +1784,13 @@ PyImport_Import(PyObject *module_name)
|
||||||
Py_DECREF(r);
|
Py_DECREF(r);
|
||||||
|
|
||||||
modules = PyImport_GetModuleDict();
|
modules = PyImport_GetModuleDict();
|
||||||
r = PyDict_GetItem(modules, module_name);
|
r = PyDict_GetItemWithError(modules, module_name);
|
||||||
if (r != NULL)
|
if (r != NULL) {
|
||||||
Py_INCREF(r);
|
Py_INCREF(r);
|
||||||
|
}
|
||||||
|
else if (!PyErr_Occurred()) {
|
||||||
|
PyErr_SetObject(PyExc_KeyError, module_name);
|
||||||
|
}
|
||||||
|
|
||||||
err:
|
err:
|
||||||
Py_XDECREF(globals);
|
Py_XDECREF(globals);
|
||||||
|
|
Loading…
Reference in New Issue