]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-149282: Fix `gc.c` compilation with `--enable-pystats` (#149283)
authorsobolevn <mail@sobolevn.me>
Sat, 2 May 2026 15:24:17 +0000 (18:24 +0300)
committerGitHub <noreply@github.com>
Sat, 2 May 2026 15:24:17 +0000 (18:24 +0300)
Python/gc.c

index de485320a4b6d49c510d96c629d974f2461c474a..134da107e1b61dc50aefc5d97c1fc75c7e4c9b6c 100644 (file)
@@ -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