mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-81057: Move the Allocators to _PyRuntimeState (gh-99217)
The global allocators were stored in 3 static global variables: _PyMem_Raw, _PyMem, and _PyObject. State for the "small block" allocator was stored in another 13. That makes a total of 16 global variables. We are moving all 16 to the _PyRuntimeState struct as part of the work for gh-81057. (If PEP 684 is accepted then we will follow up by moving them all to PyInterpreterState.) https://github.com/python/cpython/issues/81057
This commit is contained in:
parent
55c96e8053
commit
67807cfc87
14 changed files with 1129 additions and 925 deletions
68
Include/internal/pycore_obmalloc_init.h
Normal file
68
Include/internal/pycore_obmalloc_init.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
#ifndef Py_INTERNAL_OBMALLOC_INIT_H
|
||||
#define Py_INTERNAL_OBMALLOC_INIT_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef Py_BUILD_CORE
|
||||
# error "this header requires Py_BUILD_CORE define"
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************/
|
||||
/* the default object allocator's state initializer */
|
||||
|
||||
#define PTA(pools, x) \
|
||||
((poolp )((uint8_t *)&(pools.used[2*(x)]) - 2*sizeof(pymem_block *)))
|
||||
#define PT(p, x) PTA(p, x), PTA(p, x)
|
||||
|
||||
#define PT_8(p, start) \
|
||||
PT(p, start), \
|
||||
PT(p, start+1), \
|
||||
PT(p, start+2), \
|
||||
PT(p, start+3), \
|
||||
PT(p, start+4), \
|
||||
PT(p, start+5), \
|
||||
PT(p, start+6), \
|
||||
PT(p, start+7)
|
||||
|
||||
#if NB_SMALL_SIZE_CLASSES <= 8
|
||||
# define _obmalloc_pools_INIT(p) \
|
||||
{ PT_8(p, 0) }
|
||||
#elif NB_SMALL_SIZE_CLASSES <= 16
|
||||
# define _obmalloc_pools_INIT(p) \
|
||||
{ PT_8(p, 0), PT_8(p, 8) }
|
||||
#elif NB_SMALL_SIZE_CLASSES <= 24
|
||||
# define _obmalloc_pools_INIT(p) \
|
||||
{ PT_8(p, 0), PT_8(p, 8), PT_8(p, 16) }
|
||||
#elif NB_SMALL_SIZE_CLASSES <= 32
|
||||
# define _obmalloc_pools_INIT(p) \
|
||||
{ PT_8(p, 0), PT_8(p, 8), PT_8(p, 16), PT_8(p, 24) }
|
||||
#elif NB_SMALL_SIZE_CLASSES <= 40
|
||||
# define _obmalloc_pools_INIT(p) \
|
||||
{ PT_8(p, 0), PT_8(p, 8), PT_8(p, 16), PT_8(p, 24), PT_8(p, 32) }
|
||||
#elif NB_SMALL_SIZE_CLASSES <= 48
|
||||
# define _obmalloc_pools_INIT(p) \
|
||||
{ PT_8(p, 0), PT_8(p, 8), PT_8(p, 16), PT_8(p, 24), PT_8(p, 32), PT_8(p, 40) }
|
||||
#elif NB_SMALL_SIZE_CLASSES <= 56
|
||||
# define _obmalloc_pools_INIT(p) \
|
||||
{ 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) }
|
||||
#elif NB_SMALL_SIZE_CLASSES <= 64
|
||||
# define _obmalloc_pools_INIT(p) \
|
||||
{ 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) }
|
||||
#else
|
||||
# error "NB_SMALL_SIZE_CLASSES should be less than 64"
|
||||
#endif
|
||||
|
||||
#define _obmalloc_state_INIT(obmalloc) \
|
||||
{ \
|
||||
.pools = { \
|
||||
.used = _obmalloc_pools_INIT(obmalloc.pools), \
|
||||
}, \
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // !Py_INTERNAL_OBMALLOC_INIT_H
|
Loading…
Add table
Add a link
Reference in a new issue