diff options
author | Tim Peters <tim.peters@gmail.com> | 2002-04-18 21:58:56 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2002-04-18 21:58:56 (GMT) |
commit | 64d80c9f40465f9bed18712bc2b792f28dcac162 (patch) | |
tree | 9dfa396f3a15563c63fc494c51227e04ecc297cd /Objects/obmalloc.c | |
parent | 3e12071dbe18958528f481807102bfdb0f4c054f (diff) | |
download | cpython-64d80c9f40465f9bed18712bc2b792f28dcac162.zip cpython-64d80c9f40465f9bed18712bc2b792f28dcac162.tar.gz cpython-64d80c9f40465f9bed18712bc2b792f28dcac162.tar.bz2 |
PyObject_Malloc: make a tiny bit faster for platforms where malloc(0)
doesn't return NULL.
PyObject_Realloc: better comment for why we don't call PyObject_Malloc(0).
Diffstat (limited to 'Objects/obmalloc.c')
-rw-r--r-- | Objects/obmalloc.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 5948e52..602b3c3 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -685,7 +685,11 @@ redirect: * last chance to serve the request) or when the max memory limit * has been reached. */ - return (void *)malloc(nbytes ? nbytes : 1); +#ifdef MALLOC_ZERO_RETURNS_NULL + if (nbytes == 0) + nbytes = 1; +#endif + return (void *)malloc(nbytes); } /* free */ @@ -803,7 +807,10 @@ PyObject_Realloc(void *p, size_t nbytes) } /* We're not managing this block. */ if (nbytes <= SMALL_REQUEST_THRESHOLD) { - /* Take over this block. */ + /* Take over this block -- ask for at least one byte so + * we really do take it over (PyObject_Malloc(0) goes to + * the system malloc). + */ bp = PyObject_Malloc(nbytes ? nbytes : 1); if (bp != NULL) { memcpy(bp, p, nbytes); |