Skip to content

Commit 94185c8

Browse files
committed
Always untrack dicts and tuples whenever doing a collection
1 parent faa3272 commit 94185c8

File tree

1 file changed

+13
-35
lines changed

1 file changed

+13
-35
lines changed

Python/gc.c

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -725,35 +725,6 @@ move_unreachable(PyGC_Head *young, PyGC_Head *unreachable)
725725
unreachable->_gc_next &= _PyGC_PREV_MASK;
726726
}
727727

728-
static void
729-
untrack_tuples(PyGC_Head *head)
730-
{
731-
PyGC_Head *next, *gc = GC_NEXT(head);
732-
while (gc != head) {
733-
PyObject *op = FROM_GC(gc);
734-
next = GC_NEXT(gc);
735-
if (PyTuple_CheckExact(op)) {
736-
_PyTuple_MaybeUntrack(op);
737-
}
738-
gc = next;
739-
}
740-
}
741-
742-
/* Try to untrack all currently tracked dictionaries */
743-
static void
744-
untrack_dicts(PyGC_Head *head)
745-
{
746-
PyGC_Head *next, *gc = GC_NEXT(head);
747-
while (gc != head) {
748-
PyObject *op = FROM_GC(gc);
749-
next = GC_NEXT(gc);
750-
if (PyDict_CheckExact(op)) {
751-
_PyDict_MaybeUntrack(op);
752-
}
753-
gc = next;
754-
}
755-
}
756-
757728
/* Return true if object has a pre-PEP 442 finalization method. */
758729
static int
759730
has_legacy_finalizer(PyObject *op)
@@ -1463,7 +1434,7 @@ gc_collect_increment(PyThreadState *tstate, struct gc_collection_stats *stats)
14631434
gc_list_validate_space(&increment, gcstate->visited_space);
14641435
PyGC_Head survivors;
14651436
gc_list_init(&survivors);
1466-
gc_collect_region(tstate, &increment, &survivors, UNTRACK_TUPLES, stats);
1437+
gc_collect_region(tstate, &increment, &survivors, UNTRACK_TUPLES | UNTRACK_DICTS, stats);
14671438
gc_list_validate_space(&survivors, gcstate->visited_space);
14681439
gc_list_merge(&survivors, visited);
14691440
assert(gc_list_is_empty(&increment));
@@ -1528,11 +1499,18 @@ gc_collect_region(PyThreadState *tstate,
15281499
gc_list_init(&unreachable);
15291500
deduce_unreachable(from, &unreachable);
15301501
validate_consistent_old_space(from);
1531-
if (untrack & UNTRACK_TUPLES) {
1532-
untrack_tuples(from);
1533-
}
1534-
if (untrack & UNTRACK_DICTS) {
1535-
untrack_dicts(from);
1502+
1503+
gc = GC_NEXT(from);
1504+
while (gc != from) {
1505+
PyGC_Head *next = GC_NEXT(gc);
1506+
PyObject *op = FROM_GC(gc);
1507+
if (PyTuple_CheckExact(op)) {
1508+
_PyTuple_MaybeUntrack(op);
1509+
}
1510+
else if (PyDict_CheckExact(op)) {
1511+
_PyDict_MaybeUntrack(op);
1512+
}
1513+
gc = next;
15361514
}
15371515
validate_consistent_old_space(to);
15381516
if (from != to) {

0 commit comments

Comments
 (0)