gh-102013: Add PyUnstable_GC_VisitObjects (#102014)
This commit is contained in:
@@ -2401,3 +2401,27 @@ PyObject_GC_IsFinalized(PyObject *obj)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void *arg)
|
||||
{
|
||||
size_t i;
|
||||
GCState *gcstate = get_gc_state();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
done:
|
||||
gcstate->enabled = origenstate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user