[Python-Dev] Problem with the memory docs
Guido van Rossum
Thu, 04 Apr 2002 09:54:08 -0500
> The docs for PyMem_Malloc say:
> Requesting zero bytes returns a non-NULL pointer.
> I can't guarantee this without insane effort, and our code has never
> guaranteed this. If pymalloc or the platform allocator can't even allocate
> one byte in this case, nothing can be done to guarantee it except to return
> "an address" fabricated out of thin air, and guaranteed not to match any
> legitimate address. Then realloc and free would have to special-case the
> snot out of those fabricated addresses to avoid going insane. Note that C
> does not guarantee malloc(0) will return a non-NULL pointer, even on
> platforms where malloc(0) *tries* to return a non-NULL pointer. It doesn't
> have a choice about this: since all non-NULL addresses returned by a
> conforming C malloc() have to be pairwise distinct so long as none are
> free()'ed, you can provoke any C implementation into returning NULL for
> malloc(0) just by calling malloc(0) often enough without doing any free()s.
> I vote to change the docs. If you vote for something else, you implement it
The whole post is a joke, right? You just mean that it can still
return NULL when it runs out of memory, so the docs should say that?
--Guido van Rossum (home page: http://www.python.org/~guido/)