| 1 |
#ifndef Py_INTERNAL_PYMEM_INIT_H |
| 2 |
#define Py_INTERNAL_PYMEM_INIT_H |
| 3 |
#ifdef __cplusplus |
| 4 |
extern "C" { |
| 5 |
#endif |
| 6 |
|
| 7 |
#ifndef Py_BUILD_CORE |
| 8 |
# error "this header requires Py_BUILD_CORE define" |
| 9 |
#endif |
| 10 |
|
| 11 |
|
| 12 |
/********************************/ |
| 13 |
/* the allocators' initializers */ |
| 14 |
|
| 15 |
extern void * _PyMem_RawMalloc(void *, size_t); |
| 16 |
extern void * _PyMem_RawCalloc(void *, size_t, size_t); |
| 17 |
extern void * _PyMem_RawRealloc(void *, void *, size_t); |
| 18 |
extern void _PyMem_RawFree(void *, void *); |
| 19 |
#define PYRAW_ALLOC {NULL, _PyMem_RawMalloc, _PyMem_RawCalloc, _PyMem_RawRealloc, _PyMem_RawFree} |
| 20 |
|
| 21 |
#ifdef Py_GIL_DISABLED |
| 22 |
// Py_GIL_DISABLED requires mimalloc |
| 23 |
extern void* _PyObject_MiMalloc(void *, size_t); |
| 24 |
extern void* _PyObject_MiCalloc(void *, size_t, size_t); |
| 25 |
extern void _PyObject_MiFree(void *, void *); |
| 26 |
extern void* _PyObject_MiRealloc(void *, void *, size_t); |
| 27 |
# define PYOBJ_ALLOC {NULL, _PyObject_MiMalloc, _PyObject_MiCalloc, _PyObject_MiRealloc, _PyObject_MiFree} |
| 28 |
extern void* _PyMem_MiMalloc(void *, size_t); |
| 29 |
extern void* _PyMem_MiCalloc(void *, size_t, size_t); |
| 30 |
extern void _PyMem_MiFree(void *, void *); |
| 31 |
extern void* _PyMem_MiRealloc(void *, void *, size_t); |
| 32 |
# define PYMEM_ALLOC {NULL, _PyMem_MiMalloc, _PyMem_MiCalloc, _PyMem_MiRealloc, _PyMem_MiFree} |
| 33 |
#elif defined(WITH_PYMALLOC) |
| 34 |
extern void* _PyObject_Malloc(void *, size_t); |
| 35 |
extern void* _PyObject_Calloc(void *, size_t, size_t); |
| 36 |
extern void _PyObject_Free(void *, void *); |
| 37 |
extern void* _PyObject_Realloc(void *, void *, size_t); |
| 38 |
# define PYOBJ_ALLOC {NULL, _PyObject_Malloc, _PyObject_Calloc, _PyObject_Realloc, _PyObject_Free} |
| 39 |
# define PYMEM_ALLOC PYOBJ_ALLOC |
| 40 |
#else |
| 41 |
# define PYOBJ_ALLOC PYRAW_ALLOC |
| 42 |
# define PYMEM_ALLOC PYOBJ_ALLOC |
| 43 |
#endif // WITH_PYMALLOC |
| 44 |
|
| 45 |
|
| 46 |
extern void* _PyMem_DebugRawMalloc(void *, size_t); |
| 47 |
extern void* _PyMem_DebugRawCalloc(void *, size_t, size_t); |
| 48 |
extern void* _PyMem_DebugRawRealloc(void *, void *, size_t); |
| 49 |
extern void _PyMem_DebugRawFree(void *, void *); |
| 50 |
|
| 51 |
extern void* _PyMem_DebugMalloc(void *, size_t); |
| 52 |
extern void* _PyMem_DebugCalloc(void *, size_t, size_t); |
| 53 |
extern void* _PyMem_DebugRealloc(void *, void *, size_t); |
| 54 |
extern void _PyMem_DebugFree(void *, void *); |
| 55 |
|
| 56 |
#define PYDBGRAW_ALLOC(runtime) \ |
| 57 |
{&(runtime).allocators.debug.raw, _PyMem_DebugRawMalloc, _PyMem_DebugRawCalloc, _PyMem_DebugRawRealloc, _PyMem_DebugRawFree} |
| 58 |
#define PYDBGMEM_ALLOC(runtime) \ |
| 59 |
{&(runtime).allocators.debug.mem, _PyMem_DebugMalloc, _PyMem_DebugCalloc, _PyMem_DebugRealloc, _PyMem_DebugFree} |
| 60 |
#define PYDBGOBJ_ALLOC(runtime) \ |
| 61 |
{&(runtime).allocators.debug.obj, _PyMem_DebugMalloc, _PyMem_DebugCalloc, _PyMem_DebugRealloc, _PyMem_DebugFree} |
| 62 |
|
| 63 |
extern void * _PyMem_ArenaAlloc(void *, size_t); |
| 64 |
extern void _PyMem_ArenaFree(void *, void *, size_t); |
| 65 |
|
| 66 |
#ifdef Py_DEBUG |
| 67 |
# define _pymem_allocators_standard_INIT(runtime) \ |
| 68 |
{ \ |
| 69 |
PYDBGRAW_ALLOC(runtime), \ |
| 70 |
PYDBGMEM_ALLOC(runtime), \ |
| 71 |
PYDBGOBJ_ALLOC(runtime), \ |
| 72 |
} |
| 73 |
# define _pymem_is_debug_enabled_INIT 1 |
| 74 |
#else |
| 75 |
# define _pymem_allocators_standard_INIT(runtime) \ |
| 76 |
{ \ |
| 77 |
PYRAW_ALLOC, \ |
| 78 |
PYMEM_ALLOC, \ |
| 79 |
PYOBJ_ALLOC, \ |
| 80 |
} |
| 81 |
# define _pymem_is_debug_enabled_INIT 0 |
| 82 |
#endif |
| 83 |
|
| 84 |
#define _pymem_allocators_debug_INIT \ |
| 85 |
{ \ |
| 86 |
{'r', PYRAW_ALLOC}, \ |
| 87 |
{'m', PYMEM_ALLOC}, \ |
| 88 |
{'o', PYOBJ_ALLOC}, \ |
| 89 |
} |
| 90 |
|
| 91 |
# define _pymem_allocators_obj_arena_INIT \ |
| 92 |
{ NULL, _PyMem_ArenaAlloc, _PyMem_ArenaFree } |
| 93 |
|
| 94 |
|
| 95 |
#define _Py_mem_free_queue_INIT(queue) \ |
| 96 |
{ \ |
| 97 |
.head = LLIST_INIT(queue.head), \ |
| 98 |
} |
| 99 |
|
| 100 |
#ifdef __cplusplus |
| 101 |
} |
| 102 |
#endif |
| 103 |
#endif // !Py_INTERNAL_PYMEM_INIT_H |