https://github.com/python/cpython/commit/98afa0352233eefa60d6f1117ce521a3a39b22a5
commit: 98afa0352233eefa60d6f1117ce521a3a39b22a5
branch: main
author: sobolevn <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-05-02T18:24:17+03:00
summary:

gh-149282: Fix `gc.c` compilation with `--enable-pystats` (#149283)

files:
M Python/gc.c

diff --git a/Python/gc.c b/Python/gc.c
index de485320a4b6d4..134da107e1b61d 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
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to