Message 338490 - Python tracker

Message338490

Author skrah
Recipients asmeurer, brett.cannon, remi.lapeyre, skrah, xtreak
Date 2019-03-20.16:03:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1553097821.06.0.891456717964.issue36370@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-03-20 16:03:41skrahsetrecipients: + skrah, brett.cannon, remi.lapeyre, asmeurer, xtreak
2019-03-20 16:03:41skrahsetmessageid: <1553097821.06.0.891456717964.issue36370@roundup.psfhosted.org>
2019-03-20 16:03:41skrahlinkissue36370 messages
2019-03-20 16:03:40skrahcreate