Skip to content

Commit 8a553d1

Browse files
committed
Add comment about wrlist iteration.
This is a bit trickly because the wrlist can be changing as we iterate over it.
1 parent 496c0b1 commit 8a553d1

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Python/gc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,9 @@ handle_weakref_callbacks(PyGC_Head *unreachable, PyGC_Head *old)
899899
*/
900900
PyWeakReference *next_wr;
901901
for (PyWeakReference *wr = *wrlist; wr != NULL; wr = next_wr) {
902+
// Get the next list element to get iterator progress if we omit
903+
// clearing of the weakref (because _PyWeakref_ClearRef changes
904+
// next pointer in the wrlist).
902905
next_wr = wr->wr_next;
903906

904907
// Weakrefs with callbacks always need to be cleared before

Python/gc_free_threading.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,9 @@ find_weakref_callbacks(struct collection_state *state)
15111511
// that must be called into wrcb_to_call.
15121512
PyWeakReference *next_wr;
15131513
for (PyWeakReference *wr = *wrlist; wr != NULL; wr = next_wr) {
1514+
// Get the next list element to get iterator progress if we omit
1515+
// clearing of the weakref (because _PyWeakref_ClearRef changes
1516+
// next pointer in the wrlist).
15141517
next_wr = wr->wr_next;
15151518

15161519
// Weakrefs with callbacks always need to be cleared before

0 commit comments

Comments
 (0)