Skip to content
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
Do interpreter fixups after the extension cache, not before.
  • Loading branch information
ericsnowcurrently committed Apr 23, 2024
commit 0d28e0faa47c80797fd3323d6c11f2590ec785eb
23 changes: 9 additions & 14 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,6 @@ fix_up_extension_for_interpreter(PyThreadState *tstate,
return 0;
}


static int
fix_up_extension(PyThreadState *tstate, PyObject *mod, PyModuleDef *def,
PyObject *name, PyObject *path,
Expand All @@ -1201,12 +1200,6 @@ fix_up_extension(PyThreadState *tstate, PyObject *mod, PyModuleDef *def,
assert(mod != NULL && PyModule_Check(mod));
assert(def == _PyModule_GetDef(mod));

if (fix_up_extension_for_interpreter(
tstate, mod, def, name, modules) < 0)
{
return -1;
}

// bpo-44050: Extensions and def->m_base.m_copy can be updated
// when the extension module doesn't support sub-interpreters.
if (def->m_size == -1) {
Expand All @@ -1221,11 +1214,11 @@ fix_up_extension(PyThreadState *tstate, PyObject *mod, PyModuleDef *def,
}
PyObject *dict = PyModule_GetDict(mod);
if (dict == NULL) {
goto error;
return -1;
}
def->m_base.m_copy = PyDict_Copy(dict);
if (def->m_base.m_copy == NULL) {
goto error;
return -1;
}
}
}
Expand All @@ -1237,15 +1230,17 @@ fix_up_extension(PyThreadState *tstate, PyObject *mod, PyModuleDef *def,
assert(cached == NULL || cached == def);
#endif
if (_extensions_cache_set(path, name, def) < 0) {
goto error;
return -1;
}
}

return 0;
if (fix_up_extension_for_interpreter(
tstate, mod, def, name, modules) < 0)
{
return -1;
}

error:
PyMapping_DelItem(modules, name);
return -1;
return 0;
}

int
Expand Down