Skip to content

Commit cedc2e5

Browse files
committed
update
1 parent 16c66ca commit cedc2e5

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

Modules/gcmodule.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ gc_is_collecting(PyGC_Head *g)
4747
return (g->gc.gc_prev & MASK_COLLECTING) != 0;
4848
}
4949

50+
static inline void
51+
gc_clear_masks(PyGC_Head *g)
52+
{
53+
g->gc.gc_prev &= ~(MASK_COLLECTING | MASK_TENTATIVELY_UNREACHABLE);
54+
}
55+
5056
static inline Py_ssize_t
5157
gc_get_refs(PyGC_Head *g)
5258
{
@@ -146,7 +152,6 @@ gc_refs
146152
subtract_refs() then adjusts gc_refs so that it equals the number of
147153
times an object is referenced directly from outside the generation
148154
being collected.
149-
gc_refs remains >= 0 throughout these steps.
150155
151156
MASK_TENTATIVELY_UNREACHABLE
152157
move_unreachable() then moves objects not reachable (whether directly or
@@ -517,7 +522,7 @@ move_legacy_finalizers(PyGC_Head *unreachable, PyGC_Head *finalizers)
517522

518523
if (has_legacy_finalizer(op)) {
519524
gc_list_move(gc, finalizers);
520-
gc->gc.gc_prev &= ~(MASK_TENTATIVELY_UNREACHABLE | MASK_COLLECTING);
525+
gc_clear_masks(gc);
521526
}
522527
}
523528
}
@@ -530,7 +535,7 @@ visit_move(PyObject *op, PyGC_Head *tolist)
530535
if (IS_TENTATIVELY_UNREACHABLE(op)) {
531536
PyGC_Head *gc = AS_GC(op);
532537
gc_list_move(gc, tolist);
533-
gc->gc.gc_prev &= ~(MASK_TENTATIVELY_UNREACHABLE | MASK_COLLECTING);
538+
gc_clear_masks(gc);
534539
}
535540
}
536541
return 0;
@@ -798,22 +803,12 @@ check_garbage(PyGC_Head *collectable)
798803
ret = -1;
799804
}
800805
_PyGCHead_SET_PREV(gc, prev);
801-
gc->gc.gc_prev &= ~(MASK_TENTATIVELY_UNREACHABLE | MASK_COLLECTING);
806+
gc_clear_masks(gc);
802807
prev = gc;
803808
}
804809
return ret;
805810
}
806811

807-
static void
808-
revive_garbage(PyGC_Head *collectable)
809-
{
810-
PyGC_Head *gc;
811-
for (gc = collectable->gc.gc_next; gc != collectable;
812-
gc = gc->gc.gc_next) {
813-
gc->gc.gc_prev &= ~(MASK_TENTATIVELY_UNREACHABLE | MASK_COLLECTING);
814-
}
815-
}
816-
817812
/* Break reference cycles by clearing the containers involved. This is
818813
* tricky business as the lists can be changing and we don't know which
819814
* objects may be freed. It is possible I screwed something up here.
@@ -992,7 +987,6 @@ collect(int generation, Py_ssize_t *n_collected, Py_ssize_t *n_uncollectable,
992987
finalize_garbage(&unreachable);
993988

994989
if (check_garbage(&unreachable)) { // clears MASKs
995-
revive_garbage(&unreachable);
996990
gc_list_merge(&unreachable, old);
997991
}
998992
else {

0 commit comments

Comments
 (0)