Skip to content

bpo-44531: Add _PyType_AllocNoTrack() function #26947

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

Merged
merged 1 commit into from
Jul 1, 2021
Merged

bpo-44531: Add _PyType_AllocNoTrack() function #26947

merged 1 commit into from
Jul 1, 2021

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jun 29, 2021

Add an internal _PyType_AllocNoTrack() function to allocate an object
without tracking it in the GC.

Modify dict_new() to use _PyType_AllocNoTrack(): dict subclasses are
now only tracked once all PyDictObject members are initialized.
Calling _PyObject_GC_UNTRACK() is no longer needed for the dict type.

Similar change in tuple_subtype_new() for tuple subclasses.

Replace tuple_gc_track() with _PyObject_GC_TRACK().

https://bugs.python.org/issue44531

Add an internal _PyType_AllocNoTrack() function to allocate an object
without tracking it in the GC.

Modify dict_new() to use _PyType_AllocNoTrack(): dict subclasses are
now only tracked once all PyDictObject members are initialized.
Calling _PyObject_GC_UNTRACK() is no longer needed for the dict type.

Similar change in tuple_subtype_new() for tuple subclasses.

Replace tuple_gc_track() with _PyObject_GC_TRACK().
@vstinner
Copy link
Member Author

cc @methane @pablogsal: Would you mind to review this change?

dict_new() and tuple_subtype_new() detect if a subclass overrides tp_alloc. IMO it's possible and so it's safer to detect it: check _PyObject_GC_IS_TRACKED().

@vstinner vstinner merged commit 818628c into python:main Jul 1, 2021
@vstinner vstinner deleted the alloc_no_track branch July 1, 2021 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants