mirror of
https://github.com/python/cpython.git
synced 2025-12-15 21:44:50 +00:00
gh-102013: Add PyUnstable_GC_VisitObjects (#102014)
This commit is contained in:
parent
457e4d1a51
commit
cbd3fbfb6e
5 changed files with 146 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue