gh-131740: minor readability fix in PyUnstable_GC_VisitObjects (gh-131786)

Minor readability fix in PyUnstable_GC_VisitObjects

Replaces `if (visit_generation())` with `if (visit_generation() < 0)`,
since we are checking for the failure case, and it's confusing to have
that be implicitly `true`.

Also fixes a misspelt variable name.
This commit is contained in:
Martin DeMello 2025-03-28 16:58:17 -07:00 committed by GitHub
parent 2984ff9e51
commit 9c1e85fd64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2407,20 +2407,20 @@ void
PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void *arg) PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void *arg)
{ {
GCState *gcstate = get_gc_state(); GCState *gcstate = get_gc_state();
int origenstate = gcstate->enabled; int original_state = gcstate->enabled;
gcstate->enabled = 0; gcstate->enabled = 0;
if (visit_generation(callback, arg, &gcstate->young)) { if (visit_generation(callback, arg, &gcstate->young) < 0) {
goto done; goto done;
} }
if (visit_generation(callback, arg, &gcstate->old[0])) { if (visit_generation(callback, arg, &gcstate->old[0]) < 0) {
goto done; goto done;
} }
if (visit_generation(callback, arg, &gcstate->old[1])) { if (visit_generation(callback, arg, &gcstate->old[1]) < 0) {
goto done; goto done;
} }
visit_generation(callback, arg, &gcstate->permanent_generation); visit_generation(callback, arg, &gcstate->permanent_generation);
done: done:
gcstate->enabled = origenstate; gcstate->enabled = original_state;
} }
#endif // Py_GIL_DISABLED #endif // Py_GIL_DISABLED