summaryrefslogtreecommitdiff
path: root/Modules/gcmodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-08-08 22:18:46 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2010-08-08 22:18:46 +0000
commit258aa419f44f3c3b45a9ac1db3f6f02519f3d91b (patch)
tree8dd0988cc1deb6f862f64fc2d434533b75d497be /Modules/gcmodule.c
parent9cf5be7cb4a473c73ca651db5ebee9dda4cad25a (diff)
downloadcpython-258aa419f44f3c3b45a9ac1db3f6f02519f3d91b.tar.gz
Issue #477863: Print a warning at shutdown if gc.garbage is not empty.
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r--Modules/gcmodule.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 3717a27675..73843272e1 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -1295,17 +1295,16 @@ static PyMethodDef GcMethods[] = {
static struct PyModuleDef gcmodule = {
PyModuleDef_HEAD_INIT,
- "gc",
- gc__doc__,
- -1,
- GcMethods,
- NULL,
- NULL,
- NULL,
- NULL
+ "gc", /* m_name */
+ gc__doc__, /* m_doc */
+ -1, /* m_size */
+ GcMethods, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL /* m_free */
};
-
PyMODINIT_FUNC
PyInit_gc(void)
{
@@ -1364,6 +1363,37 @@ PyGC_Collect(void)
return n;
}
+void
+_PyGC_Fini(void)
+{
+ if (garbage != NULL && PyList_GET_SIZE(garbage) > 0) {
+ PySys_WriteStderr(
+ "gc: "
+ "%" PY_FORMAT_SIZE_T "d uncollectable objects at shutdown:\n",
+ PyList_GET_SIZE(garbage)
+ );
+ if (debug & DEBUG_UNCOLLECTABLE) {
+ PyObject *repr = NULL, *bytes = NULL;
+ repr = PyObject_Repr(garbage);
+ if (!repr || !(bytes = PyUnicode_EncodeFSDefault(repr)))
+ PyErr_WriteUnraisable(garbage);
+ else {
+ PySys_WriteStderr(
+ " %s\n",
+ PyBytes_AS_STRING(bytes)
+ );
+ }
+ Py_XDECREF(repr);
+ Py_XDECREF(bytes);
+ }
+ else {
+ PySys_WriteStderr(
+ " Use gc.set_debug(gc.DEBUG_UNCOLLECTABLE) to list them.\n"
+ );
+ }
+ }
+}
+
/* for debugging */
void
_PyGC_Dump(PyGC_Head *g)