8000 gh-117953: Split Up _PyImport_LoadDynamicModuleWithSpec() by ericsnowcurrently · Pull Request #118203 · python/cpython · GitHub
[go: up one dir, main page]

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
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
We already know the def is okay.
  • Loading branch information
ericsnowcurrently committed Apr 24, 2024
commit c253654e7f70d6800a615b04fa50b4e349b159a5
27 changes: 18 additions & 9 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ finish_singlephase_extension(PyThreadState *tstate,
PyObject *name, PyObject *modules)
{
assert(mod != NULL && PyModule_Check(mod));
assert(def == PyModule_GetDef(mod));
assert(def == _PyModule_GetDef(mod));

if (_modules_by_index_set(tstate->interp, def, mod) < 0) {
return -1;
Expand Down Expand Up @@ -1395,6 +1395,7 @@ create_dynamic(PyThreadState *tstate, struct _Py_ext_module_loader_info *info,
PyObject *file, PyObject *spec)
{
PyObject *mod = NULL;
PyModuleDef *def = NULL;

/* We would move this (and the fclose() below) into
* _PyImport_GetModInitFunc(), but it isn't clear if the intervening
Expand All @@ -1421,15 +1422,23 @@ create_dynamic(PyThreadState *tstate, struct _Py_ext_module_loader_info *info,
goto finally;
}

if (res.module == NULL) {
//assert(!is_singlephase(res.def));
mod = PyModule_FromDefAndSpec(res.def, spec);
mod = res.module;
res.module = NULL;
def = res.def;
assert(def != NULL);

if (mo AAD1 d == NULL) {
//assert(!is_singlephase(def));
mod = PyModule_FromDefAndSpec(def, spec);
if (mod == NULL) {
goto finally;
}
}
else {
assert(is_singlephase(res.def));
assert(is_singlephase(def));
assert(!is_core_module(tstate->interp, info->name, info->filename));
assert(!is_core_module(tstate->interp, info->name, info->name));
mod = Py_NewRef(res.module);
mod = Py_NewRef(mod);

const char *name_buf = PyBytes_AS_STRING(info->name_encoded);
if (_PyImport_CheckSubinterpIncompatibleExtensionAllowed(name_buf) < 0) {
Expand All @@ -1445,20 +1454,20 @@ create_dynamic(PyThreadState *tstate, struct _Py_ext_module_loader_info *info,
struct singlephase_global_update singlephase = {0};
// gh-88216: Extensions and def->m_base.m_copy can be updated
// when the extension module doesn't support sub-interpreters.
if (res.def->m_size == -1) {
if (def->m_size == -1) {
singlephase.m_dict = PyModule_GetDict(mod);
assert(singlephase.m_dict != NULL);
}
if (update_global_state_for_extension(
tstate, info->filename, info->name, res.def, &singlephase) < 0)
tstate, info->filename, info->name, def, &singlephase) < 0)
{
Py_CLEAR(mod);
goto finally;
}

PyObject *modules = get_modules_dict(tstate, true);
if (finish_singlephase_extension(
tstate, mod, res.def, info->name, modules) < 0)
tstate, mod, def, info->name, modules) < 0)
{
Py_CLEAR(mod);
goto finally;
Expand Down
0