Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c40eb7

Browse files
committed
Fix the builtin module initialization code to store the init function for future reinitialization.
1 parent 0c60381 commit 6c40eb7

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.3?
1010
Core and Builtins
1111
-----------------
1212

13+
- Fix the builtin module initialization code to store the init function for
14+
future reinitialization.
15+
1316
- Issue #13629: Renumber the tokens in token.h so that they match the indexes
1417
into _PyParser_TokenNames.
1518

Python/import.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,7 @@ init_builtin(char *name)
21692169

21702170
for (p = PyImport_Inittab; p->name != NULL; p++) {
21712171
PyObject *mod;
2172+
PyModuleDef *def;
21722173
if (strcmp(name, p->name) == 0) {
21732174
if (p->initfunc == NULL) {
21742175
PyErr_Format(PyExc_ImportError,
@@ -2181,6 +2182,9 @@ init_builtin(char *name)
21812182
mod = (*p->initfunc)();
21822183
if (mod == 0)
21832184
return -1;
2185+
/* Remember pointer to module init function. */
2186+
def = PyModule_GetDef(mod);
2187+
def->m_base.m_init = p->initfunc;
21842188
if (_PyImport_FixupBuiltin(mod, name) < 0)
21852189
return -1;
21862190
/* FixupExtension has put the module into sys.modules,

0 commit comments

Comments
 (0)