-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Modify _PyObject_GC_TRACK() to ensure that newly tracked object is valid #84323
Comments
In bpo-38392, I modified PyObject_GC_Track() to ensure that the object newly tracked is valid: call its traverse function. I propose to now also attempt to implement the same check in _PyObject_GC_TRACK() which is part of the internal C API. PyType_GenericAlloc() allocates memory for a type allocated on the heap... and then immediately track it in the GC. Problem: this type is not initialized yet, all fields are set to zero. Calling type_traverse() at this point fails with an assertion error: object address : 0x840860 By the way, Python crash in _PyObject_Dump() on PyObject_Repr() call: type_repr() crash when accessing type->tp_name which is NULL. type_call() should only track the newly created type when it's fully initialized. Try attached track.patch to reproduce the crash. |
While it might be doable, I don't have the bandwidth to investigate this issue and so I prefer to close it as out of date. |
PyType_GenericAlloc() cannot traverse the object since the object members are not initialized yet. For example, dict_traverse() can only be called when PyDict_New() completes. A different approach would be to:
In short, PyType_GenericAlloc() cannot be modified for backward compatibility. Moreover, _PyObject_GC_TRACK() should only be used inside Python internals, since it's part the internal C API. |
I created bpo-44531 "Add _PyType_AllocNoTrack() function: allocate without tracking in the GC". |
Attached gc_track.patch: my latest attempt to implement this idea. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: