8000 Move the allocator groupings to pycore_allocators.h. · python/cpython@73f8991 · GitHub
[go: up one dir, main page]

Skip to content

Commit 73f8991

Browse files
Move the allocator groupings to pycore_allocators.h.
1 parent df690bd commit 73f8991

File tree

3 files changed

+40
-36
lines changed

3 files changed

+40
-36
lines changed

Include/internal/pycore_allocators.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,43 @@ _PyMem_RawFree(void *Py_UNUSED(ctx), void *ptr)
5454
free(ptr);
5555
}
5656

57+
#ifdef WITH_PYMALLOC
58+
void* _PyObject_Malloc(void *ctx, size_t size);
59+
void* _PyObject_Calloc(void *ctx, size_t nelem, size_t elsize);
60+
void _PyObject_Free(void *ctx, void *p);
61+
void* _PyObject_Realloc(void *ctx, void *ptr, size_t size);
62+
#endif
63+
64+
#define MALLOC_ALLOC {NULL, _PyMem_RawMalloc, _PyMem_RawCalloc, _PyMem_RawRealloc, _PyMem_RawFree}
65+
#ifdef WITH_PYMALLOC
66+
# define PYMALLOC_ALLOC {NULL, _PyObject_Malloc, _PyObject_Calloc, _PyObject_Realloc, _PyObject_Free}
67+
#endif
68+
69+
#define PYRAW_ALLOC MALLOC_ALLOC
70+
#ifdef WITH_PYMALLOC
71+
# define PYOBJ_ALLOC PYMALLOC_ALLOC
72+
#else
73+
# define PYOBJ_ALLOC MALLOC_ALLOC
74+
#endif
75+
#define PYMEM_ALLOC PYOBJ_ALLOC
76+
77+
void* _PyMem_DebugRawMalloc(void *ctx, size_t size);
78+
void* _PyMem_DebugRawCalloc(void *ctx, size_t nelem, size_t elsize);
79+
void* _PyMem_DebugRawRealloc(void *ctx, void *ptr, size_t size);
80+
void _PyMem_DebugRawFree(void *ctx, void *ptr);
81+
82+
void* _PyMem_DebugMalloc(void *ctx, size_t size);
83+
void* _PyMem_DebugCalloc(void *ctx, size_t nelem, size_t elsize);
84+
void* _PyMem_DebugRealloc(void *ctx, void *ptr, size_t size);
85+
void _PyMem_DebugFree(void *ctx, void *p);
86+
87+
#define PYDBGRAW_ALLOC \
88+
{&_PyRuntime.allocators.debug.raw, _PyMem_DebugRawMalloc, _PyMem_DebugRawCalloc, _PyMem_DebugRawRealloc, _PyMem_DebugRawFree}
89+
#define PYDBGMEM_ALLOC \
90+
{&_PyRuntime.allocators.debug.mem, _PyMem_DebugMalloc, _PyMem_DebugCalloc, _PyMem_DebugRealloc, _PyMem_DebugFree}
91+
#define PYDBGOBJ_ALLOC \
92+
{&_PyRuntime.allocators.debug.obj, _PyMem_DebugMalloc, _PyMem_DebugCalloc, _PyMem_DebugRealloc, _PyMem_DebugFree}
93+
5794

5895
/***************************************/
5996
/* the object allocator implementation */

Include/internal/pycore_pymem_init.h

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,9 @@ extern "C" {
1010

1111
#include "pycore_allocators.h"
1212

13-
#ifdef WITH_PYMALLOC
14-
void* _PyObject_Malloc(void *ctx, size_t size);
15-
void* _PyObject_Calloc(void *ctx, size_t nelem, size_t elsize);
16-
void _PyObject_Free(void *ctx, void *p);
17-
void* _PyObject_Realloc(void *ctx, void *ptr, size_t size);
18-
#endif
19-
20-
#define MALLOC_ALLOC {NULL, _PyMem_RawMalloc, _PyMem_RawCalloc, _PyMem_RawRealloc, _PyMem_RawFree}
21-
#ifdef WITH_PYMALLOC
22-
# define PYMALLOC_ALLOC {NULL, _PyObject_Malloc, _PyObject_Calloc, _PyObject_Realloc, _PyObject_Free}
23-
#endif
24-
25-
#define PYRAW_ALLOC MALLOC_ALLOC
26-
#ifdef WITH_PYMALLOC
27-
# define PYOBJ_ALLOC PYMALLOC_ALLOC
28-
#else
29-
# define PYOBJ_ALLOC MALLOC_ALLOC
30-
#endif
31-
#define PYMEM_ALLOC PYOBJ_ALLOC
32-
33-
void* _PyMem_DebugRawMalloc(void *ctx, size_t size);
34-
void* _PyMem_DebugRawCalloc(void *ctx, size_t nelem, size_t elsize);
35-
void* _PyMem_DebugRawRealloc(void *ctx, void *ptr, size_t size);
36-
void _PyMem_DebugRawFree(void *ctx, void *ptr);
37-
38-
void* _PyMem_DebugMalloc(void *ctx, size_t size);
39-
void* _PyMem_DebugCalloc(void *ctx, size_t nelem, size_t elsize);
40-
void* _PyMem_DebugRealloc(void *ctx, void *ptr, size_t size);
41-
void _PyMem_DebugFree(void *ctx, void *p);
4213

43-
#define PYDBGRAW_ALLOC \
44-
{&_PyRuntime.allocators.debug.raw, _PyMem_DebugRawMalloc, _PyMem_DebugRawCalloc, _PyMem_DebugRawRealloc, _PyMem_DebugRawFree}
45-
#define PYDBGMEM_ALLOC \
46-
{&_PyRuntime.allocators.debug.mem, _PyMem_DebugMalloc, _PyMem_DebugCalloc, _PyMem_DebugRealloc, _PyMem_DebugFree}
47-
#define PYDBGOBJ_ALLOC \
48-
{&_PyRuntime.allocators.debug.obj, _PyMem_DebugMalloc, _PyMem_DebugCalloc, _PyMem_DebugRealloc, _PyMem_DebugFree}
14+
/********************************/
15+
/* the allocators' initializers */
4916

5017
#ifdef Py_DEBUG
5118
#define _pymem_allocators_standard_INIT \

Objects/obmalloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "pycore_code.h" // stats
44
#include "pycore_pystate.h" // _PyInterpreterState_GET
55
#include "pycore_pymem.h"
6-
#include "pycore_pymem_init.h"
6+
#include "pycore_allocators.h"
77

88
#include <stdbool.h>
99

0 commit comments

Comments
 (0)
0