[Python-checkins] CVS: python/dist/src/Include pymem.h,2.4,2.4.16.1 pyport.h,2.40,2.40.8.1
Michael Hudson
mwh@users.sourceforge.net
Tue, 05 Mar 2002 06:24:47 -0800
Update of /cvsroot/python/python/dist/src/Include
In directory usw-pr-cvs1:/tmp/cvs-serv12181
Modified Files:
Tag: release22-maint
pymem.h pyport.h
Log Message:
backport tim_one's checkin of
revision 2.5 of pymem.h
revision 2.44 of pyport.h
Whether platform malloc(0) returns NULL has nothing to do with whether
platform realloc(p, 0) returns NULL, so MALLOC_ZERO_RETURNS_NULL can
be correctly undefined yet realloc(p, 0) can return NULL anyway.
Prevent realloc(p, 0) doing free(p) and returning NULL via a different
hack. Would probably be better to get rid of MALLOC_ZERO_RETURNS_NULL
entirely.
Bugfix candidate.
Index: pymem.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/pymem.h,v
retrieving revision 2.4
retrieving revision 2.4.16.1
diff -C2 -d -r2.4 -r2.4.16.1
*** pymem.h 26 Jul 2001 21:34:59 -0000 2.4
--- pymem.h 5 Mar 2002 14:24:45 -0000 2.4.16.1
***************
*** 112,122 ****
#define PyMem_NEW(type, n) \
( (type *) PyMem_MALLOC(_PyMem_EXTRA + (n) * sizeof(type)) )
! #define PyMem_RESIZE(p, type, n) \
! if ((p) == NULL) \
! (p) = (type *)(PyMem_MALLOC( \
! _PyMem_EXTRA + (n) * sizeof(type))); \
! else \
! (p) = (type *)(PyMem_REALLOC((p), \
! _PyMem_EXTRA + (n) * sizeof(type)))
#define PyMem_DEL(p) PyMem_FREE(p)
--- 112,127 ----
#define PyMem_NEW(type, n) \
( (type *) PyMem_MALLOC(_PyMem_EXTRA + (n) * sizeof(type)) )
!
! /* See comment near MALLOC_ZERO_RETURNS_NULL in pyport.h. */
! #define PyMem_RESIZE(p, type, n) \
! do { \
! size_t _sum = (n) * sizeof(type); \
! if (!_sum) \
! _sum = 1; \
! (p) = (type *)((p) ? \
! PyMem_REALLOC(p, _sum) : \
! PyMem_MALLOC(_sum)); \
! } while (0)
!
#define PyMem_DEL(p) PyMem_FREE(p)
Index: pyport.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/pyport.h,v
retrieving revision 2.40
retrieving revision 2.40.8.1
diff -C2 -d -r2.40 -r2.40.8.1
*** pyport.h 27 Oct 2001 21:16:16 -0000 2.40
--- pyport.h 5 Mar 2002 14:24:45 -0000 2.40.8.1
***************
*** 365,370 ****
#ifdef MALLOC_ZERO_RETURNS_NULL
! /* XXX Always allocate one extra byte, since some malloc's return NULL
! XXX for malloc(0) or realloc(p, 0). */
#define _PyMem_EXTRA 1
#else
--- 365,378 ----
#ifdef MALLOC_ZERO_RETURNS_NULL
! /* Allocate an extra byte if the platform malloc(0) returns NULL.
! Caution: this bears no relation to whether realloc(p, 0) returns NULL
! when p != NULL. Even on platforms where malloc(0) does not return NULL,
! realloc(p, 0) may act like free(p) and return NULL. Examples include
! Windows, and Python's own obmalloc.c (as of 2-Mar-2002). For whatever
! reason, our docs promise that PyMem_Realloc(p, 0) won't act like
! free(p) or return NULL, so realloc() calls may have to be hacked
! too, but MALLOC_ZERO_RETURNS_NULL's state is irrelevant to realloc (it
! needs a different hack).
! */
#define _PyMem_EXTRA 1
#else