From: sobolevn Date: Sat, 2 May 2026 15:24:17 +0000 (+0300) Subject: gh-149282: Fix `gc.c` compilation with `--enable-pystats` (#149283) X-Git-Tag: v3.15.0b1~114 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=98afa0352233eefa60d6f1117ce521a3a39b22a5;p=thirdparty%2FPython%2Fcpython.git gh-149282: Fix `gc.c` compilation with `--enable-pystats` (#149283) --- diff --git a/Python/gc.c b/Python/gc.c index de485320a4b6..134da107e1b6 100644 --- a/Python/gc.c +++ b/Python/gc.c @@ -1456,10 +1456,14 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason) assert(generation >= 0 && generation < NUM_GENERATIONS); #ifdef Py_STATS - if (_Py_stats) { - _Py_stats->object_stats.object_visits = 0; + { + PyStats *s = _PyStats_GET(); + if (s) { + s->object_stats.object_visits = 0; + } } #endif + GC_STAT_ADD(generation, collections, 1); struct gc_generation_stats stats = { 0 }; @@ -1617,12 +1621,16 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason) /* Update stats */ add_stats(gcstate, generation, &stats); - GC_STAT_ADD(generation, objects_collected, m); + GC_STAT_ADD(generation, objects_collected, stats.collected); + #ifdef Py_STATS - if (_Py_stats) { - GC_STAT_ADD(generation, object_visits, - _Py_stats->object_stats.object_visits); - _Py_stats->object_stats.object_visits = 0; + { + PyStats *s = _PyStats_GET(); + if (s) { + GC_STAT_ADD(generation, object_visits, + s->object_stats.object_visits); + s->object_stats.object_visits = 0; + } } #endif