mirror of
https://github.com/python/cpython.git
synced 2025-08-28 20:56:54 +00:00
Make PyObject_{NEW,New,Del,DEL} always use the standard malloc (PyMem_*)
and not pymalloc. Add the functions PyMalloc_New, PyMalloc_NewVar, and PyMalloc_Del that will use pymalloc if it's enabled. If pymalloc is not enabled then they use the standard malloc (PyMem_*).
This commit is contained in:
parent
150ed6113c
commit
ffd5399728
1 changed files with 23 additions and 8 deletions
|
@ -34,11 +34,10 @@ You must first include "object.h".
|
||||||
allocator) and initialize its object header fields.
|
allocator) and initialize its object header fields.
|
||||||
|
|
||||||
Note that objects created with PyObject_{New, NewVar} are allocated
|
Note that objects created with PyObject_{New, NewVar} are allocated
|
||||||
within the Python heap by an object allocator, the latter being
|
within the Python heap by the raw memory allocator (usually the system
|
||||||
implemented (by default) on top of the Python raw memory
|
malloc). If you want to use the specialized Python allocator use
|
||||||
allocator. This ensures that Python keeps control on the user's
|
PyMalloc_New and PyMalloc_NewVar to allocate the objects and
|
||||||
objects regarding their memory management; for instance, they may be
|
PyMalloc_Del to free them.
|
||||||
subject to automatic garbage collection.
|
|
||||||
|
|
||||||
In case a specific form of memory management is needed, implying that
|
In case a specific form of memory management is needed, implying that
|
||||||
the objects would not reside in the Python heap (for example standard
|
the objects would not reside in the Python heap (for example standard
|
||||||
|
@ -84,9 +83,9 @@ extern DL_IMPORT(void *) PyObject_Realloc(void *, size_t);
|
||||||
extern DL_IMPORT(void) PyObject_Free(void *);
|
extern DL_IMPORT(void) PyObject_Free(void *);
|
||||||
|
|
||||||
/* Macros */
|
/* Macros */
|
||||||
#define PyObject_MALLOC(n) _PyMalloc_MALLOC(n)
|
#define PyObject_MALLOC(n) PyMem_MALLOC(n)
|
||||||
#define PyObject_REALLOC(op, n) _PyMalloc_REALLOC((void *)(op), (n))
|
#define PyObject_REALLOC(op, n) PyMem_REALLOC((void *)(op), (n))
|
||||||
#define PyObject_FREE(op) _PyMalloc_FREE((void *)(op))
|
#define PyObject_FREE(op) PyMem_FREE((void *)(op))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic object allocator interface
|
* Generic object allocator interface
|
||||||
|
@ -178,6 +177,22 @@ extern DL_IMPORT(void) _PyObject_Del(PyObject *);
|
||||||
the 1st step is performed automatically for you, so in a C++ class
|
the 1st step is performed automatically for you, so in a C++ class
|
||||||
constructor you would start directly with PyObject_Init/InitVar. */
|
constructor you would start directly with PyObject_Init/InitVar. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The PyMalloc Object Allocator
|
||||||
|
* =============================
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern DL_IMPORT(PyObject *) _PyMalloc_New(PyTypeObject *);
|
||||||
|
extern DL_IMPORT(PyVarObject *) _PyMalloc_NewVar(PyTypeObject *, int);
|
||||||
|
extern DL_IMPORT(void) _PyMalloc_Del(PyObject *);
|
||||||
|
|
||||||
|
#define PyMalloc_New(type, typeobj) \
|
||||||
|
( (type *) _PyMalloc_New(typeobj) )
|
||||||
|
#define PyMalloc_NewVar(type, typeobj, n) \
|
||||||
|
( (type *) _PyMalloc_NewVar((typeobj), (n)) )
|
||||||
|
#define PyMalloc_Del(op) _PyMalloc_Del((PyObject *)(op))
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Garbage Collection Support
|
* Garbage Collection Support
|
||||||
* ==========================
|
* ==========================
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue