Skip to content

Commit dba200e

Browse files
committed
[3.13] pythongh-131740: Update PyUnstable_GC_VisitObjects to traverse perm gen (pythongh-131744)
(cherry picked from commit 7bb41ae)
1 parent 91ae330 commit dba200e

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update PyUnstable_GC_VisitObjects to traverse perm gen.

Python/gc.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,23 @@ PyObject_GC_IsFinalized(PyObject *obj)
19661966
return 0;
19671967
}
19681968

1969+
static int
1970+
visit_generation(gcvisitobjects_t callback, void *arg, struct gc_generation *gen)
1971+
{
1972+
PyGC_Head *gc_list, *gc;
1973+
gc_list = &gen->head;
1974+
for (gc = GC_NEXT(gc_list); gc != gc_list; gc = GC_NEXT(gc)) {
1975+
PyObject *op = FROM_GC(gc);
1976+
Py_INCREF(op);
1977+
int res = callback(op, arg);
1978+
Py_DECREF(op);
1979+
if (!res) {
1980+
return -1;
1981+
}
1982+
}
1983+
return 0;
1984+
}
1985+
19691986
void
19701987
PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void *arg)
19711988
{
@@ -1976,16 +1993,11 @@ PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void *arg)
19761993
for (i = 0; i < NUM_GENERATIONS; i++) {
19771994
PyGC_Head *gc_list, *gc;
19781995
gc_list = GEN_HEAD(gcstate, i);
1979-
for (gc = GC_NEXT(gc_list); gc != gc_list; gc = GC_NEXT(gc)) {
1980-
PyObject *op = FROM_GC(gc);
1981-
Py_INCREF(op);
1982-
int res = callback(op, arg);
1983-
Py_DECREF(op);
1984-
if (!res) {
1985-
goto done;
1986-
}
1996+
if (visit_generation(callback, arg, &gcstate->generations[i])) {
1997+
goto done;
19871998
}
19881999
}
2000+
visit_generation(callback, arg, &gcstate->permanent_generation);
19892001
done:
19902002
gcstate->enabled = origenstate;
19912003
}

0 commit comments

Comments
 (0)