mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
bpo-36710: Add tstate parameter in import.c (GH-14218)
* Add 'tstate' parameter to many internal import.c functions. * _PyImportZip_Init() now gets 'tstate' parameter rather than 'interp'. * Add 'interp' parameter to _PyState_ClearModules() and rename it to _PyInterpreterState_ClearModules(). * Move private _PyImport_FindBuiltin() to the internal C API; add 'tstate' parameter to it. * Remove private _PyImport_AddModuleObject() from the C API: use public PyImport_AddModuleObject() instead. * Remove private _PyImport_FindExtensionObjectEx() from the C API: use private _PyImport_FindExtensionObject() instead.
This commit is contained in:
parent
809ff1181c
commit
0a28f8d379
8 changed files with 248 additions and 191 deletions
|
@ -741,28 +741,32 @@ PyState_RemoveModule(struct PyModuleDef* def)
|
|||
return PyList_SetItem(state->modules_by_index, index, Py_None);
|
||||
}
|
||||
|
||||
/* used by import.c:PyImport_Cleanup */
|
||||
/* Used by PyImport_Cleanup() */
|
||||
void
|
||||
_PyState_ClearModules(void)
|
||||
_PyInterpreterState_ClearModules(PyInterpreterState *interp)
|
||||
{
|
||||
PyInterpreterState *state = _PyInterpreterState_GET_UNSAFE();
|
||||
if (state->modules_by_index) {
|
||||
Py_ssize_t i;
|
||||
for (i = 0; i < PyList_GET_SIZE(state->modules_by_index); i++) {
|
||||
PyObject *m = PyList_GET_ITEM(state->modules_by_index, i);
|
||||
if (PyModule_Check(m)) {
|
||||
/* cleanup the saved copy of module dicts */
|
||||
PyModuleDef *md = PyModule_GetDef(m);
|
||||
if (md)
|
||||
Py_CLEAR(md->m_base.m_copy);
|
||||
if (!interp->modules_by_index) {
|
||||
return;
|
||||
}
|
||||
|
||||
Py_ssize_t i;
|
||||
for (i = 0; i < PyList_GET_SIZE(interp->modules_by_index); i++) {
|
||||
PyObject *m = PyList_GET_ITEM(interp->modules_by_index, i);
|
||||
if (PyModule_Check(m)) {
|
||||
/* cleanup the saved copy of module dicts */
|
||||
PyModuleDef *md = PyModule_GetDef(m);
|
||||
if (md) {
|
||||
Py_CLEAR(md->m_base.m_copy);
|
||||
}
|
||||
}
|
||||
/* Setting modules_by_index to NULL could be dangerous, so we
|
||||
clear the list instead. */
|
||||
if (PyList_SetSlice(state->modules_by_index,
|
||||
0, PyList_GET_SIZE(state->modules_by_index),
|
||||
NULL))
|
||||
PyErr_WriteUnraisable(state->modules_by_index);
|
||||
}
|
||||
|
||||
/* Setting modules_by_index to NULL could be dangerous, so we
|
||||
clear the list instead. */
|
||||
if (PyList_SetSlice(interp->modules_by_index,
|
||||
0, PyList_GET_SIZE(interp->modules_by_index),
|
||||
NULL)) {
|
||||
PyErr_WriteUnraisable(interp->modules_by_index);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue