Skip to content

[3.12] gh-131740: Update PyUnstable_GC_VisitObjects to traverse perm gen #131828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update PyUnstable_GC_VisitObjects to traverse perm gen.
30 changes: 20 additions & 10 deletions Modules/gcmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2443,6 +2443,23 @@ PyObject_GC_IsFinalized(PyObject *obj)
return 0;
}

static int
visit_generation(gcvisitobjects_t callback, void *arg, struct gc_generation *gen)
{
PyGC_Head *gc_list, *gc;
gc_list = &gen->head;
for (gc = GC_NEXT(gc_list); gc != gc_list; gc = GC_NEXT(gc)) {
PyObject *op = FROM_GC(gc);
Py_INCREF(op);
int res = callback(op, arg);
Py_DECREF(op);
if (!res) {
return -1;
}
}
return 0;
}

void
PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void *arg)
{
Expand All @@ -2451,18 +2468,11 @@ PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void *arg)
int origenstate = gcstate->enabled;
gcstate->enabled = 0;
for (i = 0; i < NUM_GENERATIONS; i++) {
PyGC_Head *gc_list, *gc;
gc_list = GEN_HEAD(gcstate, i);
for (gc = GC_NEXT(gc_list); gc != gc_list; gc = GC_NEXT(gc)) {
PyObject *op = FROM_GC(gc);
Py_INCREF(op);
int res = callback(op, arg);
Py_DECREF(op);
if (!res) {
goto done;
}
if (visit_generation(callback, arg, &gcstate->generations[i])) {
goto done;
}
}
visit_generation(callback, arg, &gcstate->permanent_generation);
done:
gcstate->enabled = origenstate;
}
Loading