Skip to content

Commit 940c937

Browse files
authored
[3.12] gh-131740: Update PyUnstable_GC_VisitObjects to traverse perm gen (#131828)
1 parent 4f7b66a commit 940c937

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update PyUnstable_GC_VisitObjects to traverse perm gen.

Modules/gcmodule.c

+20-10
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,23 @@ PyObject_GC_IsFinalized(PyObject *obj)
24432443
return 0;
24442444
}
24452445

2446+
static int
2447+
visit_generation(gcvisitobjects_t callback, void *arg, struct gc_generation *gen)
2448+
{
2449+
PyGC_Head *gc_list, *gc;
2450+
gc_list = &gen->head;
2451+
for (gc = GC_NEXT(gc_list); gc != gc_list; gc = GC_NEXT(gc)) {
2452+
PyObject *op = FROM_GC(gc);
2453+
Py_INCREF(op);
2454+
int res = callback(op, arg);
2455+
Py_DECREF(op);
2456+
if (!res) {
2457+
return -1;
2458+
}
2459+
}
2460+
return 0;
2461+
}
2462+
24462463
void
24472464
PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void *arg)
24482465
{
@@ -2451,18 +2468,11 @@ PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void *arg)
24512468
int origenstate = gcstate->enabled;
24522469
gcstate->enabled = 0;
24532470
for (i = 0; i < NUM_GENERATIONS; i++) {
2454-
PyGC_Head *gc_list, *gc;
2455-
gc_list = GEN_HEAD(gcstate, i);
2456-
for (gc = GC_NEXT(gc_list); gc != gc_list; gc = GC_NEXT(gc)) {
2457-
PyObject *op = FROM_GC(gc);
2458-
Py_INCREF(op);
2459-
int res = callback(op, arg);
2460-
Py_DECREF(op);
2461-
if (!res) {
2462-
goto done;
2463-
}
2471+
if (visit_generation(callback, arg, &gcstate->generations[i])) {
2472+
goto done;
24642473
}
24652474
}
2475+
visit_generation(callback, arg, &gcstate->permanent_generation);
24662476
done:
24672477
gcstate->enabled = origenstate;
24682478
}

0 commit comments

Comments
 (0)