diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-08-01 20:07:06 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-08-01 20:07:06 (GMT) |
commit | 84f31a567627bc69204caf2d801a63c7f96207eb (patch) | |
tree | 9b02a8f58eff611cfd39fd92584d57482b75630a /Python/pystate.c | |
parent | a68cbfa5561434208d7a822128eeabca50bd7a29 (diff) | |
download | cpython-84f31a567627bc69204caf2d801a63c7f96207eb.zip cpython-84f31a567627bc69204caf2d801a63c7f96207eb.tar.gz cpython-84f31a567627bc69204caf2d801a63c7f96207eb.tar.bz2 |
Issue #10241: Clear extension module dict copies at interpreter shutdown.
Patch by Neil Schemenauer, minimally modified.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index 40606bf..924b6a2 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -320,6 +320,31 @@ PyState_RemoveModule(struct PyModuleDef* def) return PyList_SetItem(state->modules_by_index, index, Py_None); } +/* used by import.c:PyImport_Cleanup */ +void +_PyState_ClearModules(void) +{ + PyInterpreterState *state = PyThreadState_GET()->interp; + 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); + } + } + /* 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); + } +} + void PyThreadState_Clear(PyThreadState *tstate) { |