Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Checkins

cpython: Issue #10241: Clear extension module dict copies at interpreter shutdown.

 

 

Python checkins RSS feed   Index | Next | Previous | View Threaded


python-checkins at python

Aug 1, 2013, 1:07 PM

Post #1 of 2 (7 views)
Permalink
cpython: Issue #10241: Clear extension module dict copies at interpreter shutdown.

http://hg.python.org/cpython/rev/62658d9d8926
changeset: 84958:62658d9d8926
parent: 84956:36ff479e429c
user: Antoine Pitrou <solipsis [at] pitrou>
date: Thu Aug 01 22:07:06 2013 +0200
summary:
Issue #10241: Clear extension module dict copies at interpreter shutdown.
Patch by Neil Schemenauer, minimally modified.

files:
Include/pystate.h | 3 +++
Misc/NEWS | 3 +++
Python/import.c | 2 ++
Python/pystate.c | 25 +++++++++++++++++++++++++
4 files changed, 33 insertions(+), 0 deletions(-)


diff --git a/Include/pystate.h b/Include/pystate.h
--- a/Include/pystate.h
+++ b/Include/pystate.h
@@ -134,6 +134,9 @@
PyAPI_FUNC(int) PyState_RemoveModule(struct PyModuleDef*);
#endif
PyAPI_FUNC(PyObject*) PyState_FindModule(struct PyModuleDef*);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(void) _PyState_ClearModules(void);
+#endif

PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
Core and Builtins
-----------------

+- Issue #10241: Clear extension module dict copies at interpreter shutdown.
+ Patch by Neil Schemenauer, minimally modified.
+
- Issue #9035: ismount now recognises volumes mounted below a drive root
on Windows. Original patch by Atsuo Ishimoto.

diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -380,6 +380,8 @@
builtins = interp->builtins;
interp->builtins = PyDict_New();
Py_DECREF(builtins);
+ /* Clear module dict copies stored in the interpreter state */
+ _PyState_ClearModules();
/* Collect references */
_PyGC_CollectNoFail();
/* Dump GC stats before it's too late, since it uses the warnings
diff --git a/Python/pystate.c b/Python/pystate.c
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -320,6 +320,31 @@
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)
{

--
Repository URL: http://hg.python.org/cpython


python-checkins at python

Aug 10, 2013, 3:31 PM

Post #2 of 2 (5 views)
Permalink
cpython: Issue #10241: Clear extension module dict copies at interpreter shutdown. [In reply to]

http://hg.python.org/cpython/rev/1edff836c954
changeset: 85112:1edff836c954
user: Antoine Pitrou <solipsis [at] pitrou>
date: Sun Aug 11 00:30:09 2013 +0200
summary:
Issue #10241: Clear extension module dict copies at interpreter shutdown.
Patch by Neil Schemenauer, minimally modified.

(re-apply after fix for tkinter-related crash)

files:
Include/pystate.h | 3 +++
Misc/NEWS | 3 +++
Python/import.c | 2 ++
Python/pystate.c | 25 +++++++++++++++++++++++++
4 files changed, 33 insertions(+), 0 deletions(-)


diff --git a/Include/pystate.h b/Include/pystate.h
--- a/Include/pystate.h
+++ b/Include/pystate.h
@@ -134,6 +134,9 @@
PyAPI_FUNC(int) PyState_RemoveModule(struct PyModuleDef*);
#endif
PyAPI_FUNC(PyObject*) PyState_FindModule(struct PyModuleDef*);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(void) _PyState_ClearModules(void);
+#endif

PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -54,6 +54,9 @@

- Issue #17899: Fix rare file descriptor leak in os.listdir().

+- Issue #10241: Clear extension module dict copies at interpreter shutdown.
+ Patch by Neil Schemenauer, minimally modified.
+
- Issue #9035: ismount now recognises volumes mounted below a drive root
on Windows. Original patch by Atsuo Ishimoto.

diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -380,6 +380,8 @@
builtins = interp->builtins;
interp->builtins = PyDict_New();
Py_DECREF(builtins);
+ /* Clear module dict copies stored in the interpreter state */
+ _PyState_ClearModules();
/* Collect references */
_PyGC_CollectNoFail();
/* Dump GC stats before it's too late, since it uses the warnings
diff --git a/Python/pystate.c b/Python/pystate.c
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -320,6 +320,31 @@
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)
{

--
Repository URL: http://hg.python.org/cpython

Python checkins RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.