Skip to content

Commit 2b839b9

Browse files
committed
pythongh-142029: Restore different handling of inittab not found vs found but is core module
1 parent 229ed3d commit 2b839b9

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

Python/import.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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,15 +2430,22 @@ 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-
assert(is_core_module(tstate->interp, info.name, info.path));
2439-
mod = import_add_module(tstate, info.name);
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);
24402438
goto finally;
24412439
}
2440+
p0 = (PyModInitFunction)entry->initfunc;
2441+
} else {
2442+
p0 = initfunc;
2443+
}
2444+
if (p0 == NULL) {
2445+
/* Cannot re-init internal module ("sys" or "builtins") */
2446+
assert(is_core_module(tstate->interp, info.name, info.path));
2447+
mod = import_add_module(tstate, info.name);
2448+
goto finally;
24422449
}
24432450

24442451
#ifdef Py_GIL_DISABLED

0 commit comments

Comments
 (0)