diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-08-08 22:18:46 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-08-08 22:18:46 (GMT) |
commit | 696e03553b9e455bd6729cee5a8be43a2924f537 (patch) | |
tree | 1921798050d0e6f60e64e0a8408690398d2b82f6 /Modules | |
parent | 2e5f1178ac55c032982c69f4f4dd70c19f9fa46e (diff) | |
download | cpython-696e03553b9e455bd6729cee5a8be43a2924f537.zip cpython-696e03553b9e455bd6729cee5a8be43a2924f537.tar.gz cpython-696e03553b9e455bd6729cee5a8be43a2924f537.tar.bz2 |
Issue #477863: Print a warning at shutdown if gc.garbage is not empty.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/gcmodule.c | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 3717a27..7384327 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) |