[Python-checkins] CVS: python/dist/src/Include objimpl.h,2.46,2.47

Neil Schemenauer nascheme@users.sourceforge.net
Fri, 22 Mar 2002 07:25:20 -0800


Update of /cvsroot/python/python/dist/src/Include
In directory usw-pr-cvs1:/tmp/cvs-serv16615/Include

Modified Files:
	objimpl.h 
Log Message:
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_*).


Index: objimpl.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/objimpl.h,v
retrieving revision 2.46
retrieving revision 2.47
diff -C2 -d -r2.46 -r2.47
*** objimpl.h	18 Mar 2002 21:04:28 -0000	2.46
--- objimpl.h	22 Mar 2002 15:25:18 -0000	2.47
***************
*** 35,43 ****
  
  Note that objects created with PyObject_{New, NewVar} are allocated
! within the Python heap by an object allocator, the latter being
! implemented (by default) on top of the Python raw memory
! allocator. This ensures that Python keeps control on the user's
! objects regarding their memory management; for instance, they may be
! subject to automatic garbage collection.
  
  In case a specific form of memory management is needed, implying that
--- 35,42 ----
  
  Note that objects created with PyObject_{New, NewVar} are allocated
! within the Python heap by the raw memory allocator (usually the system
! malloc).  If you want to use the specialized Python allocator use
! PyMalloc_New and PyMalloc_NewVar to allocate the objects and
! PyMalloc_Del to free them.
  
  In case a specific form of memory management is needed, implying that
***************
*** 85,91 ****
  
  /* Macros */
! #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))
  
  /*
--- 84,90 ----
  
  /* Macros */
! #define PyObject_MALLOC(n)           PyMem_MALLOC(n)
! #define PyObject_REALLOC(op, n)      PyMem_REALLOC((void *)(op), (n))
! #define PyObject_FREE(op)            PyMem_FREE((void *)(op))
  
  /*
***************
*** 178,181 ****
--- 177,196 ----
     the 1st step is performed automatically for you, so in a C++ class
     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))
+ 
  
  /*