@@ -912,8 +912,7 @@ is_builtin(PyObject *name)
912
912
that can handle the path item. Return None if no hook could;
913
913
this tells our caller that the path based finder could not find
914
914
a finder for this path item. Cache the result in
915
- path_importer_cache.
916
- Returns a borrowed reference. */
915
+ path_importer_cache. */
917
916
918
917
static PyObject *
919
918
get_path_importer (PyThreadState * tstate , PyObject * path_importer_cache ,
@@ -931,8 +930,10 @@ get_path_importer(PyThreadState *tstate, PyObject *path_importer_cache,
931
930
return NULL ; /* Shouldn't happen */
932
931
933
932
importer = PyDict_GetItemWithError (path_importer_cache , p );
934
- if (importer != NULL || _PyErr_Occurred (tstate ))
933
+ if (importer != NULL || _PyErr_Occurred (tstate )) {
934
+ Py_XINCREF (importer );
935
935
return importer ;
936
+ }
936
937
937
938
/* set path_importer_cache[p] to None to avoid recursion */
938
939
if (PyDict_SetItem (path_importer_cache , p , Py_None ) != 0 )
@@ -952,13 +953,11 @@ get_path_importer(PyThreadState *tstate, PyObject *path_importer_cache,
952
953
_PyErr_Clear (tstate );
953
954
}
954
955
if (importer == NULL ) {
955
- return Py_None ;
956
+ Py_RETURN_NONE ;
956
957
}
957
- if (importer != NULL ) {
958
- int err = PyDict_SetItem (path_importer_cache , p , importer );
958
+ if (PyDict_SetItem (path_importer_cache , p , importer ) < 0 ) {
959
959
Py_DECREF (importer );
960
- if (err != 0 )
961
- return NULL ;
960
+ return NULL ;
962
961
}
963
962
return importer ;
964
963
}
@@ -967,16 +966,12 @@ PyObject *
967
966
PyImport_GetImporter (PyObject * path )
968
967
{
969
968
PyThreadState * tstate = _PyThreadState_GET ();
970
- PyObject * importer = NULL , * path_importer_cache = NULL , * path_hooks = NULL ;
971
-
972
- path_importer_cache = PySys_GetObject ("path_importer_cache" );
973
- path_hooks = PySys_GetObject ("path_hooks" );
974
- if (path_importer_cache != NULL && path_hooks != NULL ) {
975
- importer = get_path_importer (tstate , path_importer_cache ,
976
- path_hooks , path );
969
+ PyObject * path_importer_cache = PySys_GetObject ("path_importer_cache" );
970
+ PyObject * path_hooks = PySys_GetObject ("path_hooks" );
971
+ if (path_importer_cache == NULL || path_hooks == NULL ) {
972
+ return NULL ;
977
973
}
978
- Py_XINCREF (importer ); /* get_path_importer returns a borrowed reference */
979
- return importer ;
974
+ return get_path_importer (tstate , path_importer_cache , path_hooks , path );
980
975
}
981
976
982
977
static PyObject *
@@ -1178,13 +1173,12 @@ PyImport_ImportFrozenModuleObject(PyObject *name)
1178
1173
goto err_return ;
1179
1174
}
1180
1175
m = exec_code_in_module (tstate , name , d , co );
1176
+ Py_DECREF (d );
1181
1177
if (m == NULL ) {
1182
- Py_DECREF (d );
1183
1178
goto err_return ;
1184
1179
}
1185
1180
Py_DECREF (co );
1186
1181
Py_DECREF (m );
1187
- Py_DECREF (d );
1188
1182
return 1 ;
1189
1183
1190
1184
err_return :
0 commit comments