diff options
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r-- | Modules/gcmodule.c | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 3717a27675..10a4ed7f6a 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,38 @@ PyGC_Collect(void) return n; } +void +_PyGC_Fini(void) +{ + if (!(debug & DEBUG_SAVEALL) + && garbage != NULL && PyList_GET_SIZE(garbage) > 0) { + char *message; + if (debug & DEBUG_UNCOLLECTABLE) + message = "gc: %zd uncollectable objects at " \ + "shutdown"; + else + message = "gc: %zd uncollectable objects at " \ + "shutdown; use gc.set_debug(gc.DEBUG_UNCOLLECTABLE) to list them"; + if (PyErr_WarnFormat(PyExc_ResourceWarning, 0, message, + PyList_GET_SIZE(garbage)) < 0) + PyErr_WriteUnraisable(NULL); + 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); + } + } +} + /* for debugging */ void _PyGC_Dump(PyGC_Head *g) @@ -1480,11 +1511,3 @@ PyObject_GC_Del(void *op) } PyObject_FREE(g); } - -/* for binary compatibility with 2.2 */ -#undef _PyObject_GC_Del -void -_PyObject_GC_Del(PyObject *op) -{ - PyObject_GC_Del(op); -} |