https://github.com/python/cpython/commit/940c937c1369291832024fa210827fa678366181 commit: 940c937c1369291832024fa210827fa678366181 branch: 3.12 author: Donghee Na <donghee...@python.org> committer: pablogsal <pablog...@gmail.com> date: 2025-03-28T14:55:58+01:00 summary:
[3.12] gh-131740: Update PyUnstable_GC_VisitObjects to traverse perm gen (#131828) files: A Misc/NEWS.d/next/C API/2025-03-26-06-56-40.gh-issue-131740.9PdxxQ.rst M Modules/gcmodule.c diff --git a/Misc/NEWS.d/next/C API/2025-03-26-06-56-40.gh-issue-131740.9PdxxQ.rst b/Misc/NEWS.d/next/C API/2025-03-26-06-56-40.gh-issue-131740.9PdxxQ.rst new file mode 100644 index 00000000000000..585f07aaddd8c8 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2025-03-26-06-56-40.gh-issue-131740.9PdxxQ.rst @@ -0,0 +1 @@ +Update PyUnstable_GC_VisitObjects to traverse perm gen. diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index e14d9d58f8c464..cd1115b0288f99 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -2443,6 +2443,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) { @@ -2451,18 +2468,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; } _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com