PyMem_MALLOC (was [Python-Dev] Snake farm) (original) (raw)

Marc Recht marc@informatik.uni-bremen.de
Fri, 22 Nov 2002 17:11:39 +0100


The problem seems to be in the FreeBSD malloc implementation. malloc(0) returns 0x800 in all my tests. malloc(1) and up seems to work properly.. Maybe we have to relax the configure test a bit and set the MALLOCZERORETURNSNULL #define not only on NULL returns, but on returns < 0x1000 as well ?! (or add something to pyport.h along these lines specific to FreeBSD)...

I've just got an answer on the FreeBSD-current list:

Feature in malloc and bug in third-party code. C99 says:

If the size of the space requested is zero, the behavior
is implimentation defined: either a null pointer is returned,
or the behavior is as if the size were some nonzero value,
except that the returned pointer shall not be used to access
an object.

So, if it's correct, then this isn't a FreeBSD specific problem and 0x800 could possibly something else on ther systems. Even above 0x1000. Maybe the part that wraps malloc could be changed to return NULL for malloc(0) (without calling malloc).

Regards, Marc