Mailing List Archive

python/dist/src/Include objimpl.h,2.48,2.49
Update of /cvsroot/python/python/dist/src/Include
In directory usw-pr-cvs1:/tmp/cvs-serv12203/Include

Modified Files:
objimpl.h
Log Message:
Remove PyMalloc_* symbols. PyObject_Malloc now uses pymalloc if
it's enabled. To avoid breaking extension modules that allocate using
PyObject_{NEW,New} and deallocate with PyMem_{Del,DEL}, PyMem_DEL has
been changed to call pymalloc's free.

Allow PyObject_Del, PyObject_Free, and PyObject_GC_Del to be used as
function designators. Provide source compatibility macros.

Make PyObject_GC_Track and PyObject_GC_UnTrack functions instead of
trivial macros wrapping functions.


Index: objimpl.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/objimpl.h,v
retrieving revision 2.48
retrieving revision 2.49
diff -C2 -d -r2.48 -r2.49
*** objimpl.h 28 Mar 2002 21:06:16 -0000 2.48
--- objimpl.h 12 Apr 2002 02:38:45 -0000 2.49
***************
*** 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
--- 35,39 ----

Note that objects created with PyObject_{New, NewVar} are allocated
! using the specialized Python allocator (implemented in obmalloc.c).

In case a specific form of memory management is needed, implying that
***************
*** 83,90 ****
extern DL_IMPORT(void) PyObject_Free(void *);

/* 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))

/*
--- 80,117 ----
extern DL_IMPORT(void) PyObject_Free(void *);

+
/* Macros */
! #ifdef WITH_PYMALLOC
! #ifdef PYMALLOC_DEBUG
! DL_IMPORT(void *) _PyObject_DebugMalloc(size_t nbytes);
! DL_IMPORT(void *) _PyObject_DebugRealloc(void *p, size_t nbytes);
! DL_IMPORT(void) _PyObject_DebugFree(void *p);
! DL_IMPORT(void) _PyObject_DebugDumpAddress(const void *p);
! DL_IMPORT(void) _PyObject_DebugCheckAddress(const void *p);
! DL_IMPORT(void) _PyObject_DebugDumpStats(void);
! #define PyObject_MALLOC _PyObject_DebugMalloc
! #define PyObject_Malloc _PyObject_DebugMalloc
! #define PyObject_REALLOC _PyObject_DebugRealloc
! #define PyObject_Realloc _PyObject_DebugRealloc
! #define PyObject_FREE _PyObject_DebugFree
! #define PyObject_Free _PyObject_DebugFree
!
! #else /* WITH_PYMALLOC && ! PYMALLOC_DEBUG */
! #define PyObject_MALLOC PyObject_Malloc
! #define PyObject_REALLOC PyObject_Realloc
! #define PyObject_FREE PyObject_Free
! #endif
!
! #else /* ! WITH_PYMALLOC */
! #define PyObject_MALLOC PyMem_MALLOC
! #define PyObject_REALLOC PyMem_REALLOC
! #define PyObject_FREE PyMem_FREE
! #endif /* WITH_PYMALLOC */
!
! #define PyObject_Del PyObject_Free
! #define PyObject_DEL PyObject_FREE
!
! /* for source compatibility with 2.2 */
! #define _PyObject_Del PyObject_Free

/*
***************
*** 99,103 ****
extern DL_IMPORT(PyObject *) _PyObject_New(PyTypeObject *);
extern DL_IMPORT(PyVarObject *) _PyObject_NewVar(PyTypeObject *, int);
- extern DL_IMPORT(void) _PyObject_Del(PyObject *);

#define PyObject_New(type, typeobj) \
--- 126,129 ----
***************
*** 105,109 ****
#define PyObject_NewVar(type, typeobj, n) \
( (type *) _PyObject_NewVar((typeobj), (n)) )
- #define PyObject_Del(op) _PyObject_Del((PyObject *)(op))

/* Macros trading binary compatibility for speed. See also pymem.h.
--- 131,134 ----
***************
*** 147,152 ****
(typeobj), (n)) )

- #define PyObject_DEL(op) PyObject_FREE(op)
-
/* This example code implements an object constructor with a custom
allocator, where PyObject_New is inlined, and shows the important
--- 172,175 ----
***************
*** 179,198 ****

/*
- * 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
* ==========================
--- 202,205 ----
***************
*** 210,224 ****
((o)->ob_type->tp_is_gc == NULL || (o)->ob_type->tp_is_gc(o)))

- extern DL_IMPORT(PyObject *) _PyObject_GC_Malloc(PyTypeObject *, int);
extern DL_IMPORT(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, int);
-
#define PyObject_GC_Resize(type, op, n) \
( (type *) _PyObject_GC_Resize((PyVarObject *)(op), (n)) )

! extern DL_IMPORT(PyObject *) _PyObject_GC_New(PyTypeObject *);
! extern DL_IMPORT(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, int);
! extern DL_IMPORT(void) _PyObject_GC_Del(PyObject *);
! extern DL_IMPORT(void) _PyObject_GC_Track(PyObject *);
! extern DL_IMPORT(void) _PyObject_GC_UnTrack(PyObject *);

#ifdef WITH_CYCLE_GC
--- 217,226 ----
((o)->ob_type->tp_is_gc == NULL || (o)->ob_type->tp_is_gc(o)))

extern DL_IMPORT(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, int);
#define PyObject_GC_Resize(type, op, n) \
( (type *) _PyObject_GC_Resize((PyVarObject *)(op), (n)) )

! /* for source compatibility with 2.2 */
! #define _PyObject_GC_Del PyObject_GC_Del

#ifdef WITH_CYCLE_GC
***************
*** 258,264 ****
} while (0);

! #define PyObject_GC_Track(op) _PyObject_GC_Track((PyObject *)op)
! #define PyObject_GC_UnTrack(op) _PyObject_GC_UnTrack((PyObject *)op)
!

#define PyObject_GC_New(type, typeobj) \
--- 260,269 ----
} while (0);

! extern DL_IMPORT(PyObject *) _PyObject_GC_Malloc(size_t);
! extern DL_IMPORT(PyObject *) _PyObject_GC_New(PyTypeObject *);
! extern DL_IMPORT(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, int);
! extern DL_IMPORT(void) PyObject_GC_Track(void *);
! extern DL_IMPORT(void) PyObject_GC_UnTrack(void *);
! extern DL_IMPORT(void) PyObject_GC_Del(void *);

#define PyObject_GC_New(type, typeobj) \
***************
*** 266,273 ****
#define PyObject_GC_NewVar(type, typeobj, n) \
( (type *) _PyObject_GC_NewVar((typeobj), (n)) )
! #define PyObject_GC_Del(op) _PyObject_GC_Del((PyObject *)(op))

#else /* !WITH_CYCLE_GC */

#define PyObject_GC_New PyObject_New
#define PyObject_GC_NewVar PyObject_NewVar
--- 271,279 ----
#define PyObject_GC_NewVar(type, typeobj, n) \
( (type *) _PyObject_GC_NewVar((typeobj), (n)) )
!

#else /* !WITH_CYCLE_GC */

+ #define _PyObject_GC_Malloc PyObject_Malloc
#define PyObject_GC_New PyObject_New
#define PyObject_GC_NewVar PyObject_NewVar
RE: python/dist/src/Include objimpl.h,2.48,2.49 [ In reply to ]
[nascheme@sourceforge.net]
> Modified Files:
> objimpl.h
> Log Message:
> ...
> To avoid breaking extension modules that allocate using
> PyObject_{NEW,New} and deallocate with PyMem_{Del,DEL}, PyMem_DEL has
> been changed to call pymalloc's free.

Neil, I didn't see any code to that effect in this patch (or the others).
I've since moved pymem.h closer to supporting that, but if you enable it the
compiler gripes about something (probably shallow).
Re: python/dist/src/Include objimpl.h,2.48,2.49 [ In reply to ]
Tim Peters wrote:
> Neil, I didn't see any code to that effect in this patch (or the others).

Oops. That part is not finished yet. I've fixed the cvs comment for
rev 2.49.

Neil