-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
GH-91636: Clear weakrefs created by finalizers. #136401
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
GH-91636: Clear weakrefs created by finalizers. #136401
Conversation
Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have `tp_clear` called on them to Python-level code.
@colesbury In case you want to look at the free_threading_gc changes. |
Looks good to me. |
Add a boolean flag to indicate that callbacks should be enabled. This allows the same function to be used before and after finalizer execution.
if (!allow_callbacks) { | ||
return 0; | ||
} | ||
|
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.
Maybe it is worth to add an assert here for old != NULL
?
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.
Similar question: The old
and allow_callbacks
arguments are orthogonal even in older versions?
Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have `tp_clear` called on them to Python-level code.
Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have `tp_clear` called on them to Python-level code.
Weakrefs to unreachable garbage that are created during running of finalizers need to be cleared. This avoids exposing objects that have
tp_clear
called on them to Python-level code.Note that this is part of the GH-136189 change, split out to make it easier for back-porting. This change is conceptually quite simple and is a candidate to backport to all older Python versions (this bug existed for a long time, perhaps in version 2.3). There is some duplicated code between
handle_finalizers
andclear_finalizers
but I think it's simpler just to leave that duplication. In the "main" branch I'll clean that up.