diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-06-02 21:57:10 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-06-02 21:57:10 +0200 |
commit | d8f0d922d53a8f7bb64c1fda26be386bd2e3d958 (patch) | |
tree | 66af4790c65423eb30cf83fbb35c06a3192bc55e | |
parent | aa0e7afa438d7586353a3338fd350449714e117a (diff) | |
download | cpython-git-d8f0d922d53a8f7bb64c1fda26be386bd2e3d958.tar.gz |
Issue #21233: Rename the C structure "PyMemAllocator" to "PyMemAllocatorEx" to
make sure that the code using it will be adapted for the new "calloc" field
(instead of crashing).
-rw-r--r-- | Doc/c-api/memory.rst | 10 | ||||
-rw-r--r-- | Doc/whatsnew/3.5.rst | 3 | ||||
-rw-r--r-- | Include/pymem.h | 8 | ||||
-rw-r--r-- | Modules/_testcapimodule.c | 4 | ||||
-rw-r--r-- | Modules/_tracemalloc.c | 22 | ||||
-rw-r--r-- | Objects/obmalloc.c | 14 |
6 files changed, 32 insertions, 29 deletions
diff --git a/Doc/c-api/memory.rst b/Doc/c-api/memory.rst index ec5f691ad3..5d78f385ee 100644 --- a/Doc/c-api/memory.rst +++ b/Doc/c-api/memory.rst @@ -232,7 +232,7 @@ Customize Memory Allocators .. versionadded:: 3.4 -.. c:type:: PyMemAllocator +.. c:type:: PyMemAllocatorEx Structure used to describe a memory block allocator. The structure has four fields: @@ -253,7 +253,9 @@ Customize Memory Allocators +----------------------------------------------------------+---------------------------------------+ .. 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 @@ -267,12 +269,12 @@ Customize Memory Allocators :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. diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst index 77a6f7c120..b879edece4 100644 --- a/Doc/whatsnew/3.5.rst +++ b/Doc/whatsnew/3.5.rst @@ -271,4 +271,5 @@ Changes in the Python API 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. diff --git a/Include/pymem.h b/Include/pymem.h index 7a8dd43fa8..043db64deb 100644 --- a/Include/pymem.h +++ b/Include/pymem.h @@ -128,7 +128,7 @@ typedef enum { } 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 */ @@ -142,11 +142,11 @@ typedef struct { /* 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. @@ -160,7 +160,7 @@ PyAPI_FUNC(void) PyMem_GetAllocator(PyMemAllocatorDomain 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: diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index c83a4c8ce5..05a27d61f6 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2756,7 +2756,7 @@ test_pymem_alloc0(PyObject *self) } typedef struct { - PyMemAllocator alloc; + PyMemAllocatorEx alloc; size_t malloc_size; size_t calloc_nelem; @@ -2802,7 +2802,7 @@ test_setallocators(PyMemAllocatorDomain domain) PyObject *res = NULL; const char *error_msg; alloc_hook_t hook; - PyMemAllocator alloc; + PyMemAllocatorEx alloc; size_t size, size2, nelem, elsize; void *ptr, *ptr2; diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 1e454144de..257ae1b57a 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -18,9 +18,9 @@ static void raw_free(void *ptr); /* Protected by the GIL */ static struct { - PyMemAllocator mem; - PyMemAllocator raw; - PyMemAllocator obj; + PyMemAllocatorEx mem; + PyMemAllocatorEx raw; + PyMemAllocatorEx obj; } allocators; static struct { @@ -475,7 +475,7 @@ tracemalloc_remove_trace(void *ptr) 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); @@ -501,7 +501,7 @@ tracemalloc_alloc(int use_calloc, void *ctx, size_t nelem, size_t 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); @@ -546,7 +546,7 @@ tracemalloc_realloc(void *ctx, void *ptr, size_t new_size) static void tracemalloc_free(void *ctx, void *ptr) { - PyMemAllocator *alloc = (PyMemAllocator *)ctx; + PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx; if (ptr == NULL) return; @@ -567,7 +567,7 @@ tracemalloc_alloc_gil(int use_calloc, void *ctx, size_t nelem, size_t elsize) void *ptr; if (get_reentrant()) { - PyMemAllocator *alloc = (PyMemAllocator *)ctx; + PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx; if (use_calloc) return alloc->calloc(alloc->ctx, nelem, elsize); else @@ -607,7 +607,7 @@ tracemalloc_realloc_gil(void *ctx, void *ptr, size_t new_size) 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) { @@ -639,7 +639,7 @@ tracemalloc_raw_alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize) void *ptr; if (get_reentrant()) { - PyMemAllocator *alloc = (PyMemAllocator *)ctx; + PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx; if (use_calloc) return alloc->calloc(alloc->ctx, nelem, elsize); else @@ -685,7 +685,7 @@ tracemalloc_raw_realloc(void *ctx, void *ptr, size_t new_size) if (get_reentrant()) { /* Reentrant call to PyMem_RawRealloc(). */ - PyMemAllocator *alloc = (PyMemAllocator *)ctx; + PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx; ptr2 = alloc->realloc(alloc->ctx, ptr, new_size); @@ -863,7 +863,7 @@ tracemalloc_deinit(void) static int tracemalloc_start(int max_nframe) { - PyMemAllocator alloc; + PyMemAllocatorEx alloc; size_t size; if (tracemalloc_init() < 0) diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index af2bab07b2..2036e37915 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -151,7 +151,7 @@ _PyObject_ArenaFree(void *ctx, void *ptr, size_t size) 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; @@ -166,7 +166,7 @@ static struct { #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 @@ -174,7 +174,7 @@ static PyMemAllocator _PyMem_Raw = { #endif }; -static PyMemAllocator _PyMem = { +static PyMemAllocatorEx _PyMem = { #ifdef PYMALLOC_DEBUG &_PyMem_Debug.mem, PYDBG_FUNCS #else @@ -182,7 +182,7 @@ static PyMemAllocator _PyMem = { #endif }; -static PyMemAllocator _PyObject = { +static PyMemAllocatorEx _PyObject = { #ifdef PYMALLOC_DEBUG &_PyMem_Debug.obj, PYDBG_FUNCS #else @@ -209,7 +209,7 @@ void PyMem_SetupDebugHooks(void) { #ifdef PYMALLOC_DEBUG - PyMemAllocator alloc; + PyMemAllocatorEx alloc; alloc.malloc = _PyMem_DebugMalloc; alloc.calloc = _PyMem_DebugCalloc; @@ -237,7 +237,7 @@ PyMem_SetupDebugHooks(void) } void -PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator) +PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator) { switch(domain) { @@ -255,7 +255,7 @@ PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator) } void -PyMem_SetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator) +PyMem_SetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator) { switch(domain) { |