-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-38392: PyObject_GC_Track() validates object in debug mode #16615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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