[3.7] bpo-38070: visit_decref() calls _PyObject_IsFreed() in debug mode by vstinner · Pull Request #16816 · python/cpython

@vstinner

* _PyMem_IsPtrFreed(ptr) now also returns 1 if ptr is NULL
  (equals to 0).
* Reorder _PyObject_Dump() to write safe fields first, and only
  attempt to render repr() at the end.
* Add _PyObject_AssertFailed() function and _PyObject_ASSERT() macro.

* 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 and are displayed as "<object at xxx is
freed>" with no other detail.

@vstinner vstinner changed the title [3.7] bpo-36389: Backport debug enhancements from master [3.7] bpo-38070: Backport debug enhancements from master

Oct 16, 2019

@vstinner vstinner changed the title [3.7] bpo-38070: Backport debug enhancements from master [3.7] bpo-38070: visit_decref() calls _PyObject_IsFreed() in debug mode

Oct 16, 2019