[Python-checkins] cpython: Issue #21233: Rename the C structure "PyMemAllocator" to "PyMemAllocatorEx" to
victor.stinner
python-checkins at python.org
Mon Jun 2 21:57:41 CEST 2014
http://hg.python.org/cpython/rev/6374c2d957a9
changeset: 90980:6374c2d957a9
user: Victor Stinner <victor.stinner at gmail.com>
date: Mon Jun 02 21:57:10 2014 +0200
summary:
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).
files:
Doc/c-api/memory.rst | 10 ++++++----
Doc/whatsnew/3.5.rst | 3 ++-
Include/pymem.h | 8 ++++----
Modules/_testcapimodule.c | 4 ++--
Modules/_tracemalloc.c | 22 +++++++++++-----------
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
--- a/Doc/c-api/memory.rst
+++ b/Doc/c-api/memory.rst
@@ -232,7 +232,7 @@
.. 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 @@
+----------------------------------------------------------+---------------------------------------+
.. 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 @@
: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
--- a/Doc/whatsnew/3.5.rst
+++ b/Doc/whatsnew/3.5.rst
@@ -271,4 +271,5 @@
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
--- a/Include/pymem.h
+++ b/Include/pymem.h
@@ -128,7 +128,7 @@
} 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 @@
/* 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 @@
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
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2756,7 +2756,7 @@
}
typedef struct {
- PyMemAllocator alloc;
+ PyMemAllocatorEx alloc;
size_t malloc_size;
size_t calloc_nelem;
@@ -2802,7 +2802,7 @@
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
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -18,9 +18,9 @@
/* 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 @@
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 @@
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 @@
static void
tracemalloc_free(void *ctx, void *ptr)
{
- PyMemAllocator *alloc = (PyMemAllocator *)ctx;
+ PyMemAllocatorEx *alloc = (PyMemAllocatorEx *)ctx;
if (ptr == NULL)
return;
@@ -567,7 +567,7 @@
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 @@
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 @@
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 @@
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 @@
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
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -151,7 +151,7 @@
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 @@
#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 @@
#endif
};
-static PyMemAllocator _PyMem = {
+static PyMemAllocatorEx _PyMem = {
#ifdef PYMALLOC_DEBUG
&_PyMem_Debug.mem, PYDBG_FUNCS
#else
@@ -182,7 +182,7 @@
#endif
};
-static PyMemAllocator _PyObject = {
+static PyMemAllocatorEx _PyObject = {
#ifdef PYMALLOC_DEBUG
&_PyMem_Debug.obj, PYDBG_FUNCS
#else
@@ -209,7 +209,7 @@
PyMem_SetupDebugHooks(void)
{
#ifdef PYMALLOC_DEBUG
- PyMemAllocator alloc;
+ PyMemAllocatorEx alloc;
alloc.malloc = _PyMem_DebugMalloc;
alloc.calloc = _PyMem_DebugCalloc;
@@ -237,7 +237,7 @@
}
void
-PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator)
+PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator)
{
switch(domain)
{
@@ -255,7 +255,7 @@
}
void
-PyMem_SetAllocator(PyMemAllocatorDomain domain, PyMemAllocator *allocator)
+PyMem_SetAllocator(PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator)
{
switch(domain)
{
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list