]> granicus.if.org Git - python/commitdiff
Issue #21233: Rename the C structure "PyMemAllocator" to "PyMemAllocatorEx" to
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 2 Jun 2014 19:57:10 +0000 (21:57 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 2 Jun 2014 19:57:10 +0000 (21:57 +0200)
make sure that the code using it will be adapted for the new "calloc" field
(instead of crashing).

Doc/c-api/memory.rst
Doc/whatsnew/3.5.rst
Include/pymem.h
Modules/_testcapimodule.c
Modules/_tracemalloc.c
Objects/obmalloc.c

index ec5f691ad3a4966015ed6086fbf2b3b3d2bf655d..5d78f385ee098c01c2ed0902230ec5ceee3dd407 100644 (file)
@@ -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.
 
index 77a6f7c12020c759c181700c570f55e3ef178adb..b879edece4c26c210d49eb4e87a1b4d59cca9f31 100644 (file)
@@ -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.
index 7a8dd43fa8bacef292cc4df434495667f2c1855d..043db64deb89df70d875712e61308d7ea8196697 100644 (file)
@@ -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:
index c83a4c8ce5d6ac192d5ca5193ede56d6c534f978..05a27d61f6765b399db4d431a204c8ec8a2a5719 100644 (file)
@@ -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;
 
index 1e454144de12293ff58932e0bd33bd886da4e8a3..257ae1b57a2c7df01dd4b2857e7ebf37908433d2 100644 (file)
@@ -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)
index af2bab07b294b23890046481d1d5a59343f13e8d..2036e379157aac637297b2d6908c9fa60a787d77 100644 (file)
@@ -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)
     {