Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix gc_free_threading compilation
  • Loading branch information
sergey-miryanov committed Mar 28, 2026
commit 0bac6ac5f3a56c61a5dc2978be5697eae574b02c
5 changes: 5 additions & 0 deletions Include/internal/pycore_interp_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,13 @@ struct gc_generation_stats {
double duration;
};

#ifdef Py_GIL_DISABLED
#define GC_YOUNG_STATS_SIZE 1
#define GC_OLD_STATS_SIZE 1
#else
#define GC_YOUNG_STATS_SIZE 11
#define GC_OLD_STATS_SIZE 3
#endif
struct gc_young_stats_buffer {
struct gc_generation_stats items[GC_YOUNG_STATS_SIZE];
int8_t index;
Expand Down
17 changes: 16 additions & 1 deletion Python/gc_free_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -2383,6 +2383,21 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state,
handle_legacy_finalizers(state);
}

static struct gc_generation_stats *
get_stats(GCState *gcstate, int gen)
{
if (gen == 0) {
struct gc_young_stats_buffer *buffer = &gcstate->generation_stats.young;
struct gc_generation_stats *stats = &buffer->items[buffer->index];
return stats;
}
else {
struct gc_old_stats_buffer *buffer = &gcstate->generation_stats.old[gen - 1];
struct gc_generation_stats *stats = &buffer->items[buffer->index];
return stats;
}
}

/* This is the main function. Read this to understand how the
* collection process works. */
static Py_ssize_t
Expand Down Expand Up @@ -2471,7 +2486,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
}

/* Update stats */
struct gc_generation_stats *stats = &gcstate->generation_stats[generation];
struct gc_generation_stats *stats = get_stats(gcstate, generation);
stats->collections++;
stats->collected += m;
stats->uncollectable += n;
Expand Down
Loading