]> granicus.if.org Git - python/commitdiff
PyObject_Malloc: make a tiny bit faster for platforms where malloc(0)
authorTim Peters <tim.peters@gmail.com>
Thu, 18 Apr 2002 21:58:56 +0000 (21:58 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 18 Apr 2002 21:58:56 +0000 (21:58 +0000)
doesn't return NULL.

PyObject_Realloc:  better comment for why we don't call PyObject_Malloc(0).

Objects/obmalloc.c

index 5948e522fe46df9748d52e6da33a3f36921c640c..602b3c3b2c25792f2bea9945da9df76f6a2070b2 100644 (file)
@@ -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);