summaryrefslogtreecommitdiffstats
path: root/Modules/gcmodule.c
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2022-07-27 15:03:38 (GMT)
committerGitHub <noreply@github.com>2022-07-27 15:03:38 (GMT)
commitf40bc7fa49f8d137f9b38f7a14569e9a9bdbed07 (patch)
tree01f24798d6ac958feac40337a0a877ba60a66b5f /Modules/gcmodule.c
parent2833f3798dc3647e850b303a4d0fa00609a0ae9b (diff)
downloadcpython-f40bc7fa49f8d137f9b38f7a14569e9a9bdbed07.zip
cpython-f40bc7fa49f8d137f9b38f7a14569e9a9bdbed07.tar.gz
cpython-f40bc7fa49f8d137f9b38f7a14569e9a9bdbed07.tar.bz2
gh-95324: Emit a warning if an object doesn't call PyObject_GC_UnTrack during deallocation in debug mode (#95325)
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r--Modules/gcmodule.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 3bda6e4..dcd46fe 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -2347,6 +2347,13 @@ PyObject_GC_Del(void *op)
size_t presize = _PyType_PreHeaderSize(((PyObject *)op)->ob_type);
PyGC_Head *g = AS_GC(op);
if (_PyObject_GC_IS_TRACKED(op)) {
+#ifdef Py_DEBUG
+ if (PyErr_WarnExplicitFormat(PyExc_ResourceWarning, "gc", 0,
+ "gc", NULL, "Object of type %s is not untracked before destruction",
+ ((PyObject*)op)->ob_type->tp_name)) {
+ PyErr_WriteUnraisable(NULL);
+ }
+#endif
gc_list_remove(g);
}
GCState *gcstate = get_gc_state();