summaryrefslogtreecommitdiffstats
path: root/Include/mymalloc.h
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-07-10 22:40:54 (GMT)
committerGuido van Rossum <guido@python.org>1997-07-10 22:40:54 (GMT)
commit4b11c74f7c26038f94565a5b73d102bd96cc0e9f (patch)
treeccf203ec1a68c0146af2b3543fe945cc4fb01d1d /Include/mymalloc.h
parent5ca1b711b5dfe3de292330130987e06f65612cb9 (diff)
downloadcpython-4b11c74f7c26038f94565a5b73d102bd96cc0e9f.zip
cpython-4b11c74f7c26038f94565a5b73d102bd96cc0e9f.tar.gz
cpython-4b11c74f7c26038f94565a5b73d102bd96cc0e9f.tar.bz2
Only add 1 byte to all malloc calls when it is known that malloc(0) or
realloc(p, 0) returns NULL. See changes to configure script to be checked in later.
Diffstat (limited to 'Include/mymalloc.h')
-rw-r--r--Include/mymalloc.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/Include/mymalloc.h b/Include/mymalloc.h
index 2de5310..944a4dd 100644
--- a/Include/mymalloc.h
+++ b/Include/mymalloc.h
@@ -78,14 +78,22 @@ extern void free Py_PROTO((ANY *)); /* XXX sometimes int on Unix old systems */
#define NULL ((ANY *)0)
#endif
+#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_NEW(type, n) ( (type *) malloc(1 + (n) * sizeof(type)) )
+#define _PyMem_EXTRA 1
+#else
+#define _PyMem_EXTRA 0
+#endif
+
+#define PyMem_NEW(type, n) \
+ ( (type *) malloc(_PyMem_EXTRA + (n) * sizeof(type)) )
#define PyMem_RESIZE(p, type, n) \
if ((p) == NULL) \
- (p) = (type *) malloc(1 + (n) * sizeof(type)); \
+ (p) = (type *) malloc(_PyMem_EXTRA + (n) * sizeof(type)); \
else \
- (p) = (type *) realloc((ANY *)(p), 1 + (n) * sizeof(type))
+ (p) = (type *) realloc((ANY *)(p), \
+ _PyMem_EXTRA + (n) * sizeof(type))
#define PyMem_DEL(p) free((ANY *)p)
#define PyMem_XDEL(p) if ((p) == NULL) ; else PyMem_DEL(p)