.. versionadded:: 3.4
-.. c:type:: PyMemAllocator
+.. c:type:: PyMemAllocatorEx
Structure used to describe a memory block allocator. The structure has
four fields:
+----------------------------------------------------------+---------------------------------------+
.. versionchanged:: 3.5
- Add a new field ``calloc``.
+ The :c:type:`PyMemAllocator` structure was renamed to
+ :c:type:`PyMemAllocatorEx` and a new ``calloc`` field was added.
+
.. c:type:: PyMemAllocatorDomain
:c:func:`PyObject_Realloc` and :c:func:`PyObject_Free`
-.. c:function:: void PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator)
+.. c:function:: void PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator)
Get the memory block allocator of the specified domain.
-.. c:function:: void PyMem_SetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator)
+.. c:function:: void PyMem_SetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator)
Set the memory block allocator of the specified domain.
Changes in the C API
--------------------
-* The :c:type:`PyMemAllocator` structure has a new ``calloc`` field.
+* The :c:type:`PyMemAllocator` structure was renamed to
+ :c:type:`PyMemAllocatorEx` and a new ``calloc`` field was added.
} PyMemAllocatorDomain;
typedef struct {
- /* user context passed as the first argument to the 3 functions */
+ /* user context passed as the first argument to the 4 functions */
void *ctx;
/* allocate a memory block */
/* release a memory block */
void (*free) (void *ctx, void *ptr);
-} PyMemAllocator;
+} PyMemAllocatorEx;
/* Get the memory block allocator of the specified domain. */
PyAPI_FUNC(void) PyMem_GetAllocator(PyMemAllocatorDomain domain,
- PyMemAllocator *allocator);
+ PyMemAllocatorEx *allocator);
/* Set the memory block allocator of the specified domain.
PyMem_SetupDebugHooks() function must be called to reinstall the debug hooks
on top on the new allocator. */
PyAPI_FUNC(void) PyMem_SetAllocator(PyMemAllocatorDomain domain,
- PyMemAllocator *allocator);
+ PyMemAllocatorEx *allocator);
/* Setup hooks to detect bugs in the following Python memory allocator
functions:
}
typedef struct {
- PyMemAllocator alloc;
+ PyMemAllocatorEx alloc;
size_t malloc_size;
size_t calloc_nelem;
PyObject *res = NULL;
const char *error_msg;
alloc_hook_t hook;
- PyMemAllocator alloc;
+ PyMemAllocatorEx alloc;
size_t size, size2, nelem, elsize;
void *ptr, *ptr2;
/* Protected by the GIL */
static struct {
- PyMemAllocator mem;
- PyMemAllocator raw;
- PyMemAllocator obj;
+ PyMemAllocatorEx mem;
+ PyMemAllocatorEx raw;
+ PyMemAllocatorEx obj;
} allocators;
static struct {
static void*
tracemalloc_alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
{
- PyMemAllocator *alloc = (PyMemAllocator *)ctx;
+ PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx;
void *ptr;
assert(elsize == 0 || nelem <= PY_SIZE_MAX / elsize);
static void*
tracemalloc_realloc(void *ctx, void *ptr, size_t new_size)
{
- PyMemAllocator *alloc = (PyMemAllocator *)ctx;
+ PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx;
void *ptr2;
ptr2 = alloc->realloc(alloc->ctx, ptr, new_size);
static void
tracemalloc_free(void *ctx, void *ptr)
{
- PyMemAllocator *alloc = (PyMemAllocator *)ctx;
+ PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx;
if (ptr == NULL)
return;
void *ptr;
if (get_reentrant()) {
- PyMemAllocator *alloc = (PyMemAllocator *)ctx;
+ PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx;
if (use_calloc)
return alloc->calloc(alloc->ctx, nelem, elsize);
else
Example: PyMem_RawRealloc() is called internally by pymalloc
(_PyObject_Malloc() and _PyObject_Realloc()) to allocate a new
arena (new_arena()). */
- PyMemAllocator *alloc = (PyMemAllocator *)ctx;
+ PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx;
ptr2 = alloc->realloc(alloc->ctx, ptr, new_size);
if (ptr2 != NULL && ptr != NULL) {
void *ptr;
if (get_reentrant()) {
- PyMemAllocator *alloc = (PyMemAllocator *)ctx;
+ PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx;
if (use_calloc)
return alloc->calloc(alloc->ctx, nelem, elsize);
else
if (get_reentrant()) {
/* Reentrant call to PyMem_RawRealloc(). */
- PyMemAllocator *alloc = (PyMemAllocator *)ctx;
+ PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx;
ptr2 = alloc->realloc(alloc->ctx, ptr, new_size);
static int
tracemalloc_start(int max_nframe)
{
- PyMemAllocator alloc;
+ PyMemAllocatorEx alloc;
size_t size;
if (tracemalloc_init() < 0)
typedef struct {
/* We tag each block with an API ID in order to tag API violations */
char api_id;
- PyMemAllocator alloc;
+ PyMemAllocatorEx alloc;
} debug_alloc_api_t;
static struct {
debug_alloc_api_t raw;
#define PYDBG_FUNCS _PyMem_DebugMalloc, _PyMem_DebugCalloc, _PyMem_DebugRealloc, _PyMem_DebugFree
#endif
-static PyMemAllocator _PyMem_Raw = {
+static PyMemAllocatorEx _PyMem_Raw = {
#ifdef PYMALLOC_DEBUG
&_PyMem_Debug.raw, PYDBG_FUNCS
#else
#endif
};
-static PyMemAllocator _PyMem = {
+static PyMemAllocatorEx _PyMem = {
#ifdef PYMALLOC_DEBUG
&_PyMem_Debug.mem, PYDBG_FUNCS
#else
#endif
};
-static PyMemAllocator _PyObject = {
+static PyMemAllocatorEx _PyObject = {
#ifdef PYMALLOC_DEBUG
&_PyMem_Debug.obj, PYDBG_FUNCS
#else
PyMem_SetupDebugHooks(void)
{
#ifdef PYMALLOC_DEBUG
- PyMemAllocator alloc;
+ PyMemAllocatorEx alloc;
alloc.malloc = _PyMem_DebugMalloc;
alloc.calloc = _PyMem_DebugCalloc;
}
void
-PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator)
+PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator)
{
switch(domain)
{
}
void
-PyMem_SetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator)
+PyMem_SetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator)
{
switch(domain)
{