diff options
author | Victor Stinner <vstinner@python.org> | 2019-10-08 00:37:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-08 00:37:38 (GMT) |
commit | 4d5f94b8cd20f804c7868c5395a15aa6032f874c (patch) | |
tree | ac7b34d63409a67659c9986b80e25970aea9a2fd /Modules | |
parent | 36e33c360ed7716a2b5ab2b53210da81f8ce1295 (diff) | |
download | cpython-4d5f94b8cd20f804c7868c5395a15aa6032f874c.zip cpython-4d5f94b8cd20f804c7868c5395a15aa6032f874c.tar.gz cpython-4d5f94b8cd20f804c7868c5395a15aa6032f874c.tar.bz2 |
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.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/gcmodule.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 2cbf573..2b47aba 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -373,9 +373,9 @@ update_refs(PyGC_Head *containers) /* A traversal callback for subtract_refs. */ static int -visit_decref(PyObject *op, void *data) +visit_decref(PyObject *op, void *parent) { - _PyObject_ASSERT(op, !_PyObject_IsFreed(op)); + _PyObject_ASSERT(_PyObject_CAST(parent), !_PyObject_IsFreed(op)); if (PyObject_IS_GC(op)) { PyGC_Head *gc = AS_GC(op); @@ -401,10 +401,11 @@ subtract_refs(PyGC_Head *containers) traverseproc traverse; PyGC_Head *gc = GC_NEXT(containers); for (; gc != containers; gc = GC_NEXT(gc)) { - traverse = Py_TYPE(FROM_GC(gc))->tp_traverse; + PyObject *op = FROM_GC(gc); + traverse = Py_TYPE(op)->tp_traverse; (void) traverse(FROM_GC(gc), (visitproc)visit_decref, - NULL); + op); } } |