Skip to content

Commit 0bac6ac

Browse files
Fix gc_free_threading compilation
1 parent d09c49a commit 0bac6ac

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

Include/internal/pycore_interp_structs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,13 @@ struct gc_generation_stats {
208208
double duration;
209209
};
210210

211+
#ifdef Py_GIL_DISABLED
212+
#define GC_YOUNG_STATS_SIZE 1
213+
#define GC_OLD_STATS_SIZE 1
214+
#else
211215
#define GC_YOUNG_STATS_SIZE 11
212216
#define GC_OLD_STATS_SIZE 3
217+
#endif
213218
struct gc_young_stats_buffer {
214219
struct gc_generation_stats items[GC_YOUNG_STATS_SIZE];
215220
int8_t index;

Python/gc_free_threading.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2383,6 +2383,21 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state,
23832383
handle_legacy_finalizers(state);
23842384
}
23852385

2386+
static struct gc_generation_stats *
2387+
get_stats(GCState *gcstate, int gen)
2388+
{
2389+
if (gen == 0) {
2390+
struct gc_young_stats_buffer *buffer = &gcstate->generation_stats.young;
2391+
struct gc_generation_stats *stats = &buffer->items[buffer->index];
2392+
return stats;
2393+
}
2394+
else {
2395+
struct gc_old_stats_buffer *buffer = &gcstate->generation_stats.old[gen - 1];
2396+
struct gc_generation_stats *stats = &buffer->items[buffer->index];
2397+
return stats;
2398+
}
2399+
}
2400+
23862401
/* This is the main function. Read this to understand how the
23872402
* collection process works. */
23882403
static Py_ssize_t
@@ -2471,7 +2486,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
24712486
}
24722487

24732488
/* Update stats */
2474-
struct gc_generation_stats *stats = &gcstate->generation_stats[generation];
2489+
struct gc_generation_stats *stats = get_stats(gcstate, generation);
24752490
stats->collections++;
24762491
stats->collected += m;
24772492
stats->uncollectable += n;

0 commit comments

Comments
 (0)