bpo-38392: PyObject_GC_Track() validates object in debug mode#16615
bpo-38392: PyObject_GC_Track() validates object in debug mode#16615vstinner merged 2 commits intopython:masterfrom vstinner:gc_track_validate
Conversation
|
This change is backward incompatible and I'm not sure that it's a good idea, so I marked is a WIP. See https://bugs.python.org/issue38392 for the rationale an discussion. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM. Please add a NEWS entry.
Should I add an entry in What's New in Python 3.9? |
|
This change does not change the documented behavior. So I think that an entry in NEWS would be enough. If you used |
In debug mode, PyObject_GC_Track() now calls tp_traverse() of the object type to ensure that the object is valid: test that objects visited by tp_traverse() are valid. Fix pyexpat.c: only track the parser in the GC once the parser is fully initialized.
|
I modified my PR: if a bug is detected, _PyObject_ASSERT_FAILED_MSG() now gets the object passed to PyObject_GC_Track(). This object is more likely to help the developer debugging an issue, rather than displaying the visited object which is invalid and may only be displayed as "" without any further information. I reintroduced https://bugs.python.org/issue33803 bug with this patch: The hamt bug is immediately detected. Example (with tracemalloc enabled):
Note, when tracemalloc is disabled (default), this reminder is logged: |
Onyly track the object in the GC once it's fully initialized.
…GH-16615) In debug mode, PyObject_GC_Track() now calls tp_traverse() of the object type to ensure that the object is valid: test that objects visited by tp_traverse() are valid. Fix pyexpat.c: only track the parser in the GC once the parser is fully initialized.
In debug mode, PyObject_GC_Track() now calls tp_traverse() of the
object to ensure that all object attributes visited by tp_traverse()
are initialized.
Fix pyexpat.c: only track the parser in the GC once the parser is
fully initialized.
https://bugs.python.org/issue38392