Skip to content

Commit c6761a9

Browse files
Pass the context to initializers explicitly.
1 parent 2b3cce7 commit c6761a9

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

Include/internal/pycore_obmalloc_init.h

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,44 @@ extern "C" {
99
#endif
1010

1111

12-
#define PTA(x) ((poolp )((uint8_t *)&(usedpools[2*(x)]) - 2*sizeof(pymem_block *)))
13-
#define PT(x) PTA(x), PTA(x)
12+
#define PTA(pools, x) \
13+
((poolp )((uint8_t *)&(pools.used[2*(x)]) - 2*sizeof(pymem_block *)))
14+
#define PT(p, x) PTA(p, x), PTA(p, x)
1415

15-
#define PT_8(start) \
16-
PT(start), PT(start+1), PT(start+2), PT(start+3), PT(start+4), PT(start+5), PT(start+6), PT(start+7)
16+
#define PT_8(p, st) \
17+
PT(p, st), PT(p, st+1), PT(p, st+2), PT(p, st+3), PT(p, st+4), PT(p, st+5), PT(p, st+6), PT(p, st+7)
1718

1819
#if NB_SMALL_SIZE_CLASSES <= 8
19-
# define _obmalloc_pools_INIT \
20-
{ PT_8(0) }
20+
# define _obmalloc_pools_INIT(p) \
21+
{ PT_8(p, 0) }
2122
#elif NB_SMALL_SIZE_CLASSES <= 16
22-
# define _obmalloc_pools_INIT \
23-
{ PT_8(0), PT_8(8) }
23+
# define _obmalloc_pools_INIT(p) \
24+
{ PT_8(p, 0), PT_8(p, 8) }
2425
#elif NB_SMALL_SIZE_CLASSES <= 24
25-
# define _obmalloc_pools_INIT \
26-
{ PT_8(0), PT_8(8), PT_8(16) }
26+
# define _obmalloc_pools_INIT(p) \
27+
{ PT_8(p, 0), PT_8(p, 8), PT_8(p, 16) }
2728
#elif NB_SMALL_SIZE_CLASSES <= 32
28-
# define _obmalloc_pools_INIT \
29-
{ PT_8(0), PT_8(8), PT_8(16), PT_8(24) }
29+
# define _obmalloc_pools_INIT(p) \
30+
{ PT_8(p, 0), PT_8(p, 8), PT_8(p, 16), PT_8(p, 24) }
3031
#elif NB_SMALL_SIZE_CLASSES <= 40
31-
# define _obmalloc_pools_INIT \
32-
{ PT_8(0), PT_8(8), PT_8(16), PT_8(24), PT_8(32) }
32+
# define _obmalloc_pools_INIT(p) \
33+
{ PT_8(p, 0), PT_8(p, 8), PT_8(p, 16), PT_8(p, 24), PT_8(p, 32) }
3334
#elif NB_SMALL_SIZE_CLASSES <= 48
34-
# define _obmalloc_pools_INIT \
35-
{ PT_8(0), PT_8(8), PT_8(16), PT_8(24), PT_8(32), PT_8(40) }
35+
# define _obmalloc_pools_INIT(p) \
36+
{ PT_8(p, 0), PT_8(p, 8), PT_8(p, 16), PT_8(p, 24), PT_8(p, 32), PT_8(p, 40) }
3637
#elif NB_SMALL_SIZE_CLASSES <= 56
37-
# define _obmalloc_pools_INIT \
38-
{ PT_8(0), PT_8(8), PT_8(16), PT_8(24), PT_8(32), PT_8(40), PT_8(48) }
38+
# define _obmalloc_pools_INIT(p) \
39+
{ PT_8(p, 0), PT_8(p, 8), PT_8(p, 16), PT_8(p, 24), PT_8(p, 32), PT_8(p, 40), PT_8(p, 48) }
3940
#elif NB_SMALL_SIZE_CLASSES <= 64
40-
# define _obmalloc_pools_INIT \
41-
{ PT_8(0), PT_8(8), PT_8(16), PT_8(24), PT_8(32), PT_8(40), PT_8(48), PT_8(56) }
41+
# define _obmalloc_pools_INIT(p) \
42+
{ PT_8(p, 0), PT_8(p, 8), PT_8(p, 16), PT_8(p, 24), PT_8(p, 32), PT_8(p, 40), PT_8(p, 48), PT_8(p, 56) }
4243
#else
4344
# error "NB_SMALL_SIZE_CLASSES should be less than 64"
4445
#endif
4546

46-
#define _obmalloc_state_INIT \
47+
#define _obmalloc_state_INIT(obmalloc) \
4748
{ \
48-
.pools = _obmalloc_pools_INIT, \
49+
.pools = _obmalloc_pools_INIT(obmalloc.pools), \
4950
}
5051

5152

Include/internal/pycore_runtime_init.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern "C" {
1717
in the runtime init code (in pystate.c and pylifecycle.c). */
1818

1919

20-
#define _PyRuntimeState_INIT \
20+
#define _PyRuntimeState_INIT(runtime) \
2121
{ \
2222
.gilstate = { \
2323
.check_enabled = 1, \
@@ -30,7 +30,7 @@ extern "C" {
3030
_pymem_allocators_debug_INIT, \
3131
_pymem_allocators_obj_arena_INIT, \
3232
}, \
33-
.obmalloc = _obmalloc_state_INIT, \
33+
.obmalloc = _obmalloc_state_INIT(runtime.obmalloc), \
3434
.interpreters = { \
3535
/* This prevents interpreters from getting created \
3636
until _PyInterpreterState_Enable() is called. */ \

Python/pylifecycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ _PyRuntimeState _PyRuntime
102102
#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))
103103
__attribute__ ((section (".PyRuntime")))
104104
#endif
105-
= _PyRuntimeState_INIT;
105+
= _PyRuntimeState_INIT(_PyRuntime);
106106
_Py_COMP_DIAG_POP
107107

108108
static int runtime_initialized = 0;

Python/pystate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ _Py_COMP_DIAG_PUSH
5252
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
5353
/* We use "initial" if the runtime gets re-used
5454
(e.g. Py_Finalize() followed by Py_Initialize(). */
55-
static const _PyRuntimeState initial = _PyRuntimeState_INIT;
55+
static const _PyRuntimeState initial = _PyRuntimeState_INIT(initial);
5656
_Py_COMP_DIAG_POP
5757

5858
static int

0 commit comments

Comments
 (0)