[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 7bb41aef4b)

* fix
This commit is contained in:
Donghee Na 2025-03-27 02:43:16 +09:00 committed by GitHub
parent 5bcb476df1
commit 9d3f538471
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 10 deletions

View file

@ -0,0 +1 @@
Update PyUnstable_GC_VisitObjects to traverse perm gen.

View file

@ -1966,6 +1966,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)
{
@ -1974,18 +1991,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;
}