@@ -34,11 +34,10 @@ You must first include "object.h".
3434 allocator) and initialize its object header fields.
3535
3636Note that objects created with PyObject_{New, NewVar} are allocated
37- within the Python heap by an object allocator, the latter being
38- implemented (by default) on top of the Python raw memory
39- allocator. This ensures that Python keeps control on the user's
40- objects regarding their memory management; for instance, they may be
41- subject to automatic garbage collection.
37+ within the Python heap by the raw memory allocator (usually the system
38+ malloc). If you want to use the specialized Python allocator use
39+ PyMalloc_New and PyMalloc_NewVar to allocate the objects and
40+ PyMalloc_Del to free them.
4241
4342In case a specific form of memory management is needed, implying that
4443the objects would not reside in the Python heap (for example standard
@@ -84,9 +83,9 @@ extern DL_IMPORT(void *) PyObject_Realloc(void *, size_t);
8483extern DL_IMPORT (void ) PyObject_Free (void * );
8584
8685/* Macros */
87- #define PyObject_MALLOC (n ) _PyMalloc_MALLOC (n)
88- #define PyObject_REALLOC (op , n ) _PyMalloc_REALLOC ((void *)(op), (n))
89- #define PyObject_FREE (op ) _PyMalloc_FREE ((void *)(op))
86+ #define PyObject_MALLOC (n ) PyMem_MALLOC (n)
87+ #define PyObject_REALLOC (op , n ) PyMem_REALLOC ((void *)(op), (n))
88+ #define PyObject_FREE (op ) PyMem_FREE ((void *)(op))
9089
9190/*
9291 * Generic object allocator interface
@@ -178,6 +177,22 @@ extern DL_IMPORT(void) _PyObject_Del(PyObject *);
178177 the 1st step is performed automatically for you, so in a C++ class
179178 constructor you would start directly with PyObject_Init/InitVar. */
180179
180+ /*
181+ * The PyMalloc Object Allocator
182+ * =============================
183+ */
184+
185+ extern DL_IMPORT (PyObject * ) _PyMalloc_New (PyTypeObject * );
186+ extern DL_IMPORT (PyVarObject * ) _PyMalloc_NewVar (PyTypeObject * , int );
187+ extern DL_IMPORT (void ) _PyMalloc_Del (PyObject * );
188+
189+ #define PyMalloc_New (type , typeobj ) \
190+ ( (type *) _PyMalloc_New(typeobj) )
191+ #define PyMalloc_NewVar (type , typeobj , n ) \
192+ ( (type *) _PyMalloc_NewVar((typeobj), (n)) )
193+ #define PyMalloc_Del (op ) _PyMalloc_Del((PyObject *)(op))
194+
195+
181196/*
182197 * Garbage Collection Support
183198 * ==========================
0 commit comments