8000 gh-135552: Make the GC clear weakrefs later. by nascheme · Pull Request #136189 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-135552: Make the GC clear weakrefs later. #136189

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge 'origin/main' into gh-135552-wr-clear-later
  • Loading branch information
nascheme committed Jul 8, 2025
commit 00606023e0ecb1ff38a785d6e3481727aadf606a
8 changes: 1 addition & 7 deletions Python/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,7 @@ handle_weakref_callbacks(PyGC_Head *unreachable, PyGC_Head *old)
PyGC_Head *next;
int num_freed = 0;

if (allow_callbacks) {
gc_list_init(&wrcb_to_call);
}
gc_list_init(&wrcb_to_call);

/* Find all weakrefs with callbacks and move into `wrcb_to_call` if the
* callback needs to be invoked. We make another pass over wrcb_to_call,
Expand Down Expand Up @@ -987,10 +985,6 @@ handle_weakref_callbacks(PyGC_Head *unreachable, PyGC_Head *old)
}
}

if (!allow_callbacks) {
return 0;
}

/* Invoke the callbacks we decided to honor. It's safe to invoke them
* because they can't reference unreachable objects.
*/
Expand Down
2 changes: 1 addition & 1 deletion Python/gc_free_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ find_weakref_callbacks(struct collection_state *state)

// Clear all weakrefs to unreachable objects.
static void
clear_weakrefs(struct collection_state *state, bool enqueue_callbacks)
clear_weakrefs(struct collection_state *state)
{
PyObject *op;
WORKSTACK_FOR_EACH(&state->unreachable, op) {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0