-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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.) #81057
- Loading branch information
1 parent
55c96e8
commit 67807cf
Showing
14 changed files
with
1,104 additions
and
900 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#ifndef Py_INTERNAL_PYMEM_INIT_H | ||
#define Py_INTERNAL_PYMEM_INIT_H | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifndef Py_BUILD_CORE | ||
# error "this header requires Py_BUILD_CORE define" | ||
#endif | ||
|
||
#include "pycore_pymem.h" | ||
|
||
|
||
/********************************/ | ||
/* the allocators' initializers */ | ||
|
||
extern void * _PyMem_RawMalloc(void *, size_t); | ||
extern void * _PyMem_RawCalloc(void *, size_t, size_t); | ||
extern void * _PyMem_RawRealloc(void *, void *, size_t); | ||
extern void _PyMem_RawFree(void *, void *); | ||
#define PYRAW_ALLOC {NULL, _PyMem_RawMalloc, _PyMem_RawCalloc, _PyMem_RawRealloc, _PyMem_RawFree} | ||
|
||
#ifdef WITH_PYMALLOC | ||
extern void* _PyObject_Malloc(void *, size_t); | ||
extern void* _PyObject_Calloc(void *, size_t, size_t); | ||
extern void _PyObject_Free(void *, void *); | ||
extern void* _PyObject_Realloc(void *, void *, size_t); | ||
# define PYOBJ_ALLOC {NULL, _PyObject_Malloc, _PyObject_Calloc, _PyObject_Realloc, _PyObject_Free} | ||
#else | ||
# define PYOBJ_ALLOC PYRAW_ALLOC | ||
#endif // WITH_PYMALLOC | ||
|
||
#define PYMEM_ALLOC PYOBJ_ALLOC | ||
|
||
extern void* _PyMem_DebugRawMalloc(void *, size_t); | ||
extern void* _PyMem_DebugRawCalloc(void *, size_t, size_t); | ||
extern void* _PyMem_DebugRawRealloc(void *, void *, size_t); | ||
extern void _PyMem_DebugRawFree(void *, void *); | ||
|
||
extern void* _PyMem_DebugMalloc(void *, size_t); | ||
extern void* _PyMem_DebugCalloc(void *, size_t, size_t); | ||
extern void* _PyMem_DebugRealloc(void *, void *, size_t); | ||
extern void _PyMem_DebugFree(void *, void *); | ||
|
||
#define PYDBGRAW_ALLOC(runtime) \ | ||
{&(runtime).allocators.debug.raw, _PyMem_DebugRawMalloc, _PyMem_DebugRawCalloc, _PyMem_DebugRawRealloc, _PyMem_DebugRawFree} | ||
#define PYDBGMEM_ALLOC(runtime) \ | ||
{&(runtime).allocators.debug.mem, _PyMem_DebugMalloc, _PyMem_DebugCalloc, _PyMem_DebugRealloc, _PyMem_DebugFree} | ||
#define PYDBGOBJ_ALLOC(runtime) \ | ||
{&(runtime).allocators.debug.obj, _PyMem_DebugMalloc, _PyMem_DebugCalloc, _PyMem_DebugRealloc, _PyMem_DebugFree} | ||
|
||
extern void * _PyMem_ArenaAlloc(void *, size_t); | ||
extern void _PyMem_ArenaFree(void *, void *, size_t); | ||
|
||
#ifdef Py_DEBUG | ||
# define _pymem_allocators_standard_INIT(runtime) \ | ||
{ \ | ||
PYDBGRAW_ALLOC(runtime), \ | ||
PYDBGMEM_ALLOC(runtime), \ | ||
PYDBGOBJ_ALLOC(runtime), \ | ||
} | ||
#else | ||
# define _pymem_allocators_standard_INIT(runtime) \ | ||
{ \ | ||
PYRAW_ALLOC, \ | ||
PYMEM_ALLOC, \ | ||
PYOBJ_ALLOC, \ | ||
} | ||
#endif | ||
|
||
#define _pymem_allocators_debug_INIT \ | ||
{ \ | ||
{'r', PYRAW_ALLOC}, \ | ||
{'m', PYMEM_ALLOC}, \ | ||
{'o', PYOBJ_ALLOC}, \ | ||
} | ||
|
||
# define _pymem_allocators_obj_arena_INIT \ | ||
{ NULL, _PyMem_ArenaAlloc, _PyMem_ArenaFree } | ||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif // !Py_INTERNAL_PYMEM_INIT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Core and Builtins/2022-11-07-14-16-59.gh-issue-81057.3uKlLQ.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The 18 global C variables holding the state of the allocators have been | ||
moved to ``_PyRuntimeState``. This is a strictly internal change with no | ||
change in behavior. |
Oops, something went wrong.