summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-06-19 00:54:39 (GMT)
committerGitHub <noreply@github.com>2019-06-19 00:54:39 (GMT)
commit0a28f8d379544eee897979da0ce99f0b449b49dd (patch)
tree8bf54f5ac2e9c3fd7beff5f6fa529a4f2269f3fb /Python/pystate.c
parent809ff1181ccc09c3b629f3d0ec66e13eaa111b2e (diff)
downloadcpython-0a28f8d379544eee897979da0ce99f0b449b49dd.zip
cpython-0a28f8d379544eee897979da0ce99f0b449b49dd.tar.gz
cpython-0a28f8d379544eee897979da0ce99f0b449b49dd.tar.bz2
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.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 833e0fb..1e2b480 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -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);
}
}