diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2022-01-13 17:17:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-13 17:17:28 -0700 |
commit | 322f962f3ee31d0dbde99e36379de8488ccc6804 (patch) | |
tree | 5ff4958e37f0f556294804c2918bdfeb9ea87417 /Modules/gcmodule.c | |
parent | 324908ba936d5d262026deebb81f050803848c41 (diff) | |
download | cpython-git-322f962f3ee31d0dbde99e36379de8488ccc6804.tar.gz |
bpo-45953: Statically initialize all the non-object PyInterpreterState fields we can. (gh-30589)
https://bugs.python.org/issue45953
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r-- | Modules/gcmodule.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index e22f031f57..16f8c2b18e 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -139,24 +139,20 @@ get_gc_state(void) void _PyGC_InitState(GCState *gcstate) { - gcstate->enabled = 1; /* automatic collection enabled? */ - -#define _GEN_HEAD(n) GEN_HEAD(gcstate, n) - struct gc_generation generations[NUM_GENERATIONS] = { - /* PyGC_Head, threshold, count */ - {{(uintptr_t)_GEN_HEAD(0), (uintptr_t)_GEN_HEAD(0)}, 700, 0}, - {{(uintptr_t)_GEN_HEAD(1), (uintptr_t)_GEN_HEAD(1)}, 10, 0}, - {{(uintptr_t)_GEN_HEAD(2), (uintptr_t)_GEN_HEAD(2)}, 10, 0}, - }; +#define INIT_HEAD(GEN) \ + do { \ + GEN.head._gc_next = (uintptr_t)&GEN.head; \ + GEN.head._gc_prev = (uintptr_t)&GEN.head; \ + } while (0) + for (int i = 0; i < NUM_GENERATIONS; i++) { - gcstate->generations[i] = generations[i]; + assert(gcstate->generations[i].count == 0); + INIT_HEAD(gcstate->generations[i]); }; gcstate->generation0 = GEN_HEAD(gcstate, 0); - struct gc_generation permanent_generation = { - {(uintptr_t)&gcstate->permanent_generation.head, - (uintptr_t)&gcstate->permanent_generation.head}, 0, 0 - }; - gcstate->permanent_generation = permanent_generation; + INIT_HEAD(gcstate->permanent_generation); + +#undef INIT_HEAD } |