@@ -2383,12 +2383,12 @@ is_builtin(PyObject *name)
23832383 return 0 ;
23842384}
23852385
2386- static PyModInitFunction
2387- lookup_inittab_initfunc (const struct _Py_ext_module_loader_info * info )
2386+ static struct _inittab *
2387+ lookup_inittab_entry (const struct _Py_ext_module_loader_info * info )
23882388{
23892389 for (struct _inittab * p = INITTAB ; p -> name != NULL ; p ++ ) {
23902390 if (_PyUnicode_EqualToASCIIString (info -> name , p -> name )) {
2391- return ( PyModInitFunction ) p -> initfunc ;
2391+ return p ;
23922392 }
23932393 }
23942394 // not found
@@ -2430,22 +2430,28 @@ create_builtin(
24302430 _extensions_cache_delete (info .path , info .name );
24312431 }
24322432
2433- PyModInitFunction p0 = initfunc ;
2434- if (p0 == NULL ) {
2435- p0 = lookup_inittab_initfunc (& info );
2436- if (p0 == NULL ) {
2437- /* Cannot re-init internal module ("sys" or "builtins") */
2438- if (is_core_module (tstate -> interp , info .name , info .path )) {
2439- mod = import_add_module (tstate , info .name );
2440- goto finally ;
2441- }
2442- else {
2443- mod = Py_NewRef (Py_None );
2444- goto finally ;
2445- }
2433+ PyModInitFunction p0 = NULL ;
2434+ if (initfunc == NULL ) {
2435+ struct _inittab * entry = lookup_inittab_entry (& info );
2436+ if (entry == NULL ) {
2437+ mod = Py_NewRef (Py_None );
2438+ goto finally ;
24462439 }
2440+
2441+ p0 = (PyModInitFunction )entry -> initfunc ;
2442+ }
2443+ else {
2444+ p0 = initfunc ;
2445+ }
2446+
2447+ if (p0 == NULL ) {
2448+ /* Cannot re-init internal module ("sys" or "builtins") */
2449+ assert (is_core_module (tstate -> interp , info .name , info .path ));
2450+ mod = import_add_module (tstate , info .name );
2451+ goto finally ;
24472452 }
24482453
2454+
24492455#ifdef Py_GIL_DISABLED
24502456 // This call (and the corresponding call to _PyImport_CheckGILForModule())
24512457 // would ideally be inside import_run_extension(). They are kept in the
0 commit comments