Stefan Krah <[email protected]> added the comment:
The issue is that PyImport_GetModule() can legitimately NULL (not found)
but also NULL after an error occurred in PyDict_GetItemWithError().
So one (quick and dirty) approach that fixes this abort() is:
diff --git a/Python/import.c b/Python/import.c
index bf3a99414f..22eecd7cd6 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1735,7 +1735,10 @@ PyImport_ImportModuleLevelObject(PyObject *name,
PyObject *globals,
}
mod = PyImport_GetModule(abs_name);
- if (mod != NULL && mod != Py_None) {
+ if (mod == NULL && PyErr_Occurred()) {
+ goto error;
+ }
+ else if (mod != NULL && mod != Py_None) {
_Py_IDENTIFIER(__spec__);
_Py_IDENTIFIER(_lock_unlock_module);
PyObject *spec;
cc Brett as the import expert, perhaps he would like another approach.
----------
nosy: +brett.cannon
title: "Fatal Python error: Cannot recover from stack overflow" from SymPy
tests -> Check for PyErr_Occurred() after PyImport_GetModule().
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36370>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com