Skip to content

Commit 52f0656

Browse files
Move setting m_init to _imp_create_dynamic_impl().
1 parent 4e72371 commit 52f0656

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Diff for: Python/import.c

+3
Original file line numberDiff line numberDiff line change
@@ -3942,6 +3942,9 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
39423942
goto finally;
39433943
}
39443944

3945+
/* Remember pointer to module init function. */
3946+
res.def->m_base.m_init = p0;
3947+
39453948
/* Remember the filename as the __file__ attribute */
39463949
if (PyModule_AddObjectRef(mod, "__file__", info.filename) < 0) {
39473950
PyErr_Clear(); /* Not important enough to report */

Diff for: Python/importdl.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,15 @@ _PyImport_RunModInitFunc(PyModInitFunction p0,
218218
struct _Py_ext_module_loader_result res = {0};
219219
const char *name_buf = PyBytes_AS_STRING(info->name_encoded);
220220

221+
/* Call the module init function. */
222+
221223
/* Package context is needed for single-phase init */
222224
const char *oldcontext = _PyImport_SwapPackageContext(info->newcontext);
223225
PyObject *m = p0();
224226
_PyImport_SwapPackageContext(oldcontext);
225227

228+
/* Validate the result (and populate "res". */
229+
226230
if (m == NULL) {
227231
if (!PyErr_Occurred()) {
228232
PyErr_Format(
@@ -284,9 +288,6 @@ _PyImport_RunModInitFunc(PyModInitFunction p0,
284288
"module", name_buf);
285289
goto error;
286290
}
287-
288-
/* Remember pointer to module init function. */
289-
res.def->m_base.m_init = p0;
290291
}
291292

292293
assert(!PyErr_Occurred());

0 commit comments

Comments
 (0)