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

Skip to content

Commit 165e01f

Browse files
committed
Fix the builtin module initialization code to store the init function for future reinitialization.
2 parents af5facc + 6c40eb7 commit 165e01f

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.3 Alpha 1?
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
@@ -2542,6 +2542,7 @@ init_builtin(PyObject *name)
25422542

25432543
for (p = PyImport_Inittab; p->name != NULL; p++) {
25442544
PyObject *mod;
2545+
PyModuleDef *def;
25452546
if (PyUnicode_CompareWithASCIIString(name, p->name) == 0) {
25462547
if (p->initfunc == NULL) {
25472548
PyErr_Format(PyExc_ImportError,
@@ -2554,6 +2555,9 @@ init_builtin(PyObject *name)
25542555
mod = (*p->initfunc)();
25552556
if (mod == 0)
25562557
return -1;
2558+
/* Remember pointer to module init function. */
2559+
def = PyModule_GetDef(mod);
2560+
def->m_base.m_init = p->initfunc;
25572561
if (_PyImport_FixupExtensionObject(mod, name, name) < 0)
25582562
return -1;
25592563
/* FixupExtension has put the module into sys.modules,

0 commit comments

Comments
 (0)