@@ -1549,9 +1549,14 @@ create_builtin(PyThreadState *tstate, PyObject *name, PyObject *spec)
1549
1549
{
1550
1550
PyModuleDef * def = NULL ;
1551
1551
PyObject * mod = import_find_extension (tstate , name , name );
1552
- if (mod || _PyErr_Occurred (tstate )) {
1552
+ if (mod != NULL ) {
1553
+ assert (!_PyErr_Occurred (tstate ));
1554
+ assert (is_singlephase (_PyModule_GetDef (mod )));
1553
1555
return mod ;
1554
1556
}
1557
+ else if (_PyErr_Occurred (tstate )) {
1558
+ return NULL ;
1559
+ }
1555
1560
1556
1561
struct _inittab * found = NULL ;
1557
1562
for (struct _inittab * p = INITTAB ; p -> name != NULL ; p ++ ) {
@@ -3922,20 +3927,23 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
3922
3927
/*[clinic end generated code: output=83249b827a4fde77 input=c31b954f4cf4e09d]*/
3923
3928
{
3924
3929
PyObject * mod = NULL ;
3930
+ PyThreadState * tstate = _PyThreadState_GET ();
3925
3931
3926
3932
struct _Py_ext_module_loader_info info ;
3927
3933
if (_Py_ext_module_loader_info_init_from_spec (& info , spec ) < 0 ) {
3928
3934
return NULL ;
3929
3935
}
3930
3936
3931
- PyThreadState * tstate = _PyThreadState_GET ();
3932
3937
mod = import_find_extension (tstate , info .name , info .filename );
3933
- if (mod != NULL || _PyErr_Occurred (tstate )) {
3934
- assert (mod == NULL || !_PyErr_Occurred (tstate ));
3938
+ if (mod != NULL ) {
3939
+ assert (!_PyErr_Occurred (tstate ));
3940
+ assert (is_singlephase (_PyModule_GetDef (mod )));
3935
3941
goto finally ;
3936
3942
}
3937
-
3938
- /* Is multi-phase init or this is the first time being loaded. */
3943
+ else if (_PyErr_Occurred (tstate )) {
3944
+ goto finally ;
3945
+ }
3946
+ /* Otherwise it must be multi-phase init or the first time it's loaded. */
3939
3947
3940
3948
if (PySys_Audit ("import" , "OOOOO" , info .name , info .filename ,
3941
3949
Py_None , Py_None , Py_None ) < 0 )
0 commit comments