8000 bpo-38070: Enhance visit_decref() debug trace (GH-16631) · python/cpython@4d5f94b · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d5f94b

Browse files
authored
bpo-38070: Enhance visit_decref() debug trace (GH-16631)
subtract_refs() now pass the parent object to visit_decref() which pass it to _PyObject_ASSERT(). So if the "is freed" assertion fails, the parent is used in debug trace, rather than the freed object. The parent object is more likely to contain useful information. Freed objects cannot be inspected are are displayed as "<object at xxx is freed>" with no other detail.
1 parent 36e33c3 commit 4d5f94b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Modules/gcmodule.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ update_refs(PyGC_Head *containers)
373373

374374
/* A traversal callback for subtract_refs. */
375375
static int
376-
visit_decref(PyObject *op, void *data)
376+
visit_decref(PyObject *op, void *parent)
377377
{
378-
_PyObject_ASSERT(op, !_PyObject_IsFreed(op));
378+
_PyObject_ASSERT(_PyObject_CAST(parent), !_PyObject_IsFreed(op));
379379

380380
if (PyObject_IS_GC(op)) {
381381
PyGC_Head *gc = AS_GC(op);
@@ -401,10 +401,11 @@ subtract_refs(PyGC_Head *containers)
401401
traverseproc traverse;
402402
PyGC_Head *gc = GC_NEXT(containers);
403403
for (; gc != containers; gc = GC_NEXT(gc)) {
404-
traverse = Py_TYPE(FROM_GC(gc))->tp_traverse;
404+
PyObject *op = FROM_GC(gc);
405+
traverse = Py_TYPE(op)->tp_traverse;
405406
(void) traverse(FROM_GC(gc),
406407
(visitproc)visit_decref,
407-
NULL);
408+
op);
408409
}
409410
}
410411

0 commit comments

Comments
 (0)
0