mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Drop the PyCore_* memory API.
This commit is contained in:
parent
08de92a267
commit
25f3dc21b5
4 changed files with 71 additions and 92 deletions
|
@ -56,43 +56,6 @@ form of memory management you're using).
|
|||
Unless you have specific memory management requirements, it is
|
||||
recommended to use PyObject_{New, NewVar, Del}. */
|
||||
|
||||
/*
|
||||
* Core object memory allocator
|
||||
* ============================
|
||||
*/
|
||||
|
||||
/* The purpose of the object allocator is to make the distinction
|
||||
between "object memory" and the rest within the Python heap.
|
||||
|
||||
Object memory is the one allocated by PyObject_{New, NewVar}, i.e.
|
||||
the one that holds the object's representation defined by its C
|
||||
type structure, *excluding* any object-specific memory buffers that
|
||||
might be referenced by the structure (for type structures that have
|
||||
pointer fields). By default, the object memory allocator is
|
||||
implemented on top of the raw memory allocator.
|
||||
|
||||
The PyCore_* macros can be defined to make the interpreter use a
|
||||
custom object memory allocator. They are reserved for internal
|
||||
memory management purposes exclusively. Both the core and extension
|
||||
modules should use the PyObject_* API. */
|
||||
|
||||
#ifdef WITH_PYMALLOC
|
||||
void *_PyCore_ObjectMalloc(size_t nbytes);
|
||||
void *_PyCore_ObjectRealloc(void *p, size_t nbytes);
|
||||
void _PyCore_ObjectFree(void *p);
|
||||
#define PyCore_OBJECT_MALLOC _PyCore_ObjectMalloc
|
||||
#define PyCore_OBJECT_REALLOC _PyCore_ObjectRealloc
|
||||
#define PyCore_OBJECT_FREE _PyCore_ObjectFree
|
||||
#endif /* !WITH_PYMALLOC */
|
||||
|
||||
#ifndef PyCore_OBJECT_MALLOC
|
||||
#undef PyCore_OBJECT_REALLOC
|
||||
#undef PyCore_OBJECT_FREE
|
||||
#define PyCore_OBJECT_MALLOC(n) PyCore_MALLOC(n)
|
||||
#define PyCore_OBJECT_REALLOC(p, n) PyCore_REALLOC((p), (n))
|
||||
#define PyCore_OBJECT_FREE(p) PyCore_FREE(p)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Raw object memory interface
|
||||
* ===========================
|
||||
|
@ -111,19 +74,19 @@ void _PyCore_ObjectFree(void *p);
|
|||
|
||||
/* Functions */
|
||||
|
||||
/* Wrappers around PyCore_OBJECT_MALLOC and friends; useful if you
|
||||
need to be sure that you are using the same object memory allocator
|
||||
as Python. These wrappers *do not* make sure that allocating 0
|
||||
bytes returns a non-NULL pointer. Returned pointers must be checked
|
||||
for NULL explicitly; no action is performed on failure. */
|
||||
/* Wrappers that useful if you need to be sure that you are using the
|
||||
same object memory allocator as Python. These wrappers *do not* make
|
||||
sure that allocating 0 bytes returns a non-NULL pointer. Returned
|
||||
pointers must be checked for NULL explicitly; no action is performed
|
||||
on failure. */
|
||||
extern DL_IMPORT(void *) PyObject_Malloc(size_t);
|
||||
extern DL_IMPORT(void *) PyObject_Realloc(void *, size_t);
|
||||
extern DL_IMPORT(void) PyObject_Free(void *);
|
||||
|
||||
/* Macros */
|
||||
#define PyObject_MALLOC(n) PyCore_OBJECT_MALLOC(n)
|
||||
#define PyObject_REALLOC(op, n) PyCore_OBJECT_REALLOC((void *)(op), (n))
|
||||
#define PyObject_FREE(op) PyCore_OBJECT_FREE((void *)(op))
|
||||
#define PyObject_MALLOC(n) _PyMalloc_MALLOC(n)
|
||||
#define PyObject_REALLOC(op, n) _PyMalloc_REALLOC((void *)(op), (n))
|
||||
#define PyObject_FREE(op) _PyMalloc_FREE((void *)(op))
|
||||
|
||||
/*
|
||||
* Generic object allocator interface
|
||||
|
|
|
@ -10,26 +10,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Core memory allocator
|
||||
* =====================
|
||||
*/
|
||||
|
||||
/* To make sure the interpreter is user-malloc friendly, all memory
|
||||
APIs are implemented on top of this one.
|
||||
|
||||
The PyCore_* macros can be defined to make the interpreter use a
|
||||
custom allocator. Note that they are for internal use only. Both
|
||||
the core and extension modules should use the PyMem_* API. */
|
||||
|
||||
#ifndef PyCore_MALLOC
|
||||
#undef PyCore_REALLOC
|
||||
#undef PyCore_FREE
|
||||
#define PyCore_MALLOC(n) malloc(n)
|
||||
#define PyCore_REALLOC(p, n) realloc((p), (n))
|
||||
#define PyCore_FREE(p) free(p)
|
||||
#endif
|
||||
|
||||
/* BEWARE:
|
||||
|
||||
Each interface exports both functions and macros. Extension modules
|
||||
|
@ -51,9 +31,12 @@ extern "C" {
|
|||
* ====================
|
||||
*/
|
||||
|
||||
/* To make sure the interpreter is user-malloc friendly, all memory
|
||||
APIs are implemented on top of this one. */
|
||||
|
||||
/* Functions */
|
||||
|
||||
/* Function wrappers around PyCore_MALLOC and friends; useful if you
|
||||
/* Function wrappers around PyMem_MALLOC and friends; useful if you
|
||||
need to be sure that you are using the same memory allocator as
|
||||
Python. Note that the wrappers make sure that allocating 0 bytes
|
||||
returns a non-NULL pointer, even if the underlying malloc
|
||||
|
@ -66,10 +49,12 @@ extern DL_IMPORT(void) PyMem_Free(void *);
|
|||
/* Starting from Python 1.6, the wrappers Py_{Malloc,Realloc,Free} are
|
||||
no longer supported. They used to call PyErr_NoMemory() on failure. */
|
||||
|
||||
/* Macros */
|
||||
#define PyMem_MALLOC(n) PyCore_MALLOC(n)
|
||||
#define PyMem_REALLOC(p, n) PyCore_REALLOC((void *)(p), (n))
|
||||
#define PyMem_FREE(p) PyCore_FREE((void *)(p))
|
||||
/* Macros (override these if you want to a different malloc */
|
||||
#ifndef PyMem_MALLOC
|
||||
#define PyMem_MALLOC(n) malloc(n)
|
||||
#define PyMem_REALLOC(p, n) realloc((void *)(p), (n))
|
||||
#define PyMem_FREE(p) free((void *)(p))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Type-oriented memory interface
|
||||
|
@ -104,6 +89,22 @@ extern DL_IMPORT(void) PyMem_Free(void *);
|
|||
it is recommended to write the test explicitly in the code.
|
||||
Note that according to ANSI C, free(NULL) has no effect. */
|
||||
|
||||
|
||||
/* pymalloc (private to the interpreter) */
|
||||
#ifdef WITH_PYMALLOC
|
||||
void *_PyMalloc_Malloc(size_t nbytes);
|
||||
void *_PyMalloc_Realloc(void *p, size_t nbytes);
|
||||
void _PyMalloc_Free(void *p);
|
||||
#define _PyMalloc_MALLOC _PyMalloc_Malloc
|
||||
#define _PyMalloc_REALLOC _PyMalloc_Realloc
|
||||
#define _PyMalloc_FREE _PyMalloc_Free
|
||||
#else
|
||||
#define _PyMalloc_MALLOC PyMem_MALLOC
|
||||
#define _PyMalloc_REALLOC PyMem_REALLOC
|
||||
#define _PyMalloc_FREE PyMem_FREE
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue