mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
gh-95324: Emit a warning if an object doesn't call PyObject_GC_UnTrack during deallocation in debug mode (#95325)
This commit is contained in:
parent
2833f3798d
commit
f40bc7fa49
8 changed files with 18 additions and 2 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue