Skip to content

Commit 9d3f538

Browse files
authored
[3.13] gh-131740: Update PyUnstable_GC_VisitObjects to traverse perm … (gh-131754)
* [3.13] gh-131740: Update PyUnstable_GC_VisitObjects to traverse perm gen (gh-131744) (cherry picked from commit 7bb41ae) * fix
1 parent 5bcb476 commit 9d3f538

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.

Python/gc.c

+20-10
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
{
@@ -1974,18 +1991,11 @@ PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void *arg)
19741991
int origenstate = gcstate->enabled;
19751992
gcstate->enabled = 0;
19761993
for (i = 0; i < NUM_GENERATIONS; i++) {
1977-
PyGC_Head *gc_list, *gc;
1978-
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-
}
1994+
if (visit_generation(callback, arg, &gcstate->generations[i])) {
1995+
goto done;
19871996
}
19881997
}
1998+
visit_generation(callback, arg, &gcstate->permanent_generation);
19891999
done:
19902000
gcstate->enabled = origenstate;
19912001
}

0 commit comments

Comments
 (0)