Skip to content

gh-117953: Split Up _PyImport_LoadDynamicModuleWithSpec() #118203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move setting m_init to _imp_create_dynamic_impl().
  • Loading branch information
ericsnowcurrently committed Apr 24, 2024
commit 52f0656cb0fd6e136616605a031ac67e35eb348c
3 changes: 3 additions & 0 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -3942,6 +3942,9 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
goto finally;
}

/* Remember pointer to module init function. */
res.def->m_base.m_init = p0;

/* Remember the filename as the __file__ attribute */
if (PyModule_AddObjectRef(mod, "__file__", info.filename) < 0) {
PyErr_Clear(); /* Not important enough to report */
Expand Down
7 changes: 4 additions & 3 deletions Python/importdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,15 @@ _PyImport_RunModInitFunc(PyModInitFunction p0,
struct _Py_ext_module_loader_result res = {0};
const char *name_buf = PyBytes_AS_STRING(info->name_encoded);

/* Call the module init function. */

/* Package context is needed for single-phase init */
const char *oldcontext = _PyImport_SwapPackageContext(info->newcontext);
PyObject *m = p0();
_PyImport_SwapPackageContext(oldcontext);

/* Validate the result (and populate "res". */

if (m == NULL) {
if (!PyErr_Occurred()) {
PyErr_Format(
Expand Down Expand Up @@ -284,9 +288,6 @@ _PyImport_RunModInitFunc(PyModInitFunction p0,
"module", name_buf);
goto error;
}

/* Remember pointer to module init function. */
res.def->m_base.m_init = p0;
}

assert(!PyErr_Occurred());
Expand Down