Skip to content

Commit 1e73945

Browse files
authored
visit_reachable: replace release-mode test with an assert. (GH-16866)
It should be impossible for an untracked object to have the collecting flag set. Back when state was stored in gc_refs, it obviously was impossible (gc_refs couldn't possibly have a positive & negative value simultaneously). While the _implementation_ of "state" has gotten much more complicated, it's still _logically_ just as impossible.
1 parent 5bc6a7c commit 1e73945

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Modules/gcmodule.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,16 @@ visit_reachable(PyObject *op, PyGC_Head *reachable)
468468
PyGC_Head *gc = AS_GC(op);
469469
const Py_ssize_t gc_refs = gc_get_refs(gc);
470470

471-
// Ignore untracked objects and objects in other generation.
471+
// Ignore objects in other generation.
472472
// This also skips objects "to the left" of the current position in
473473
// move_unreachable's scan of the 'young' list - they've already been
474474
// traversed, and no longer have the PREV_MASK_COLLECTING flag.
475-
if (gc->_gc_next == 0 || !gc_is_collecting(gc)) {
475+
if (! gc_is_collecting(gc)) {
476476
return 0;
477477
}
478+
// It would be a logic error elsewhere if the collecting flag were set on
479+
// an untracked object.
480+
assert(gc->_gc_next != 0);
478481

479482
if (gc->_gc_next & NEXT_MASK_UNREACHABLE) {
480483
/* This had gc_refs = 0 when move_unreachable got

0 commit comments

Comments
 (0)