PyMem_MALLOC (was [Python-Dev] Snake farm)

Martin v. Loewis martin@v.loewis.de
22 Nov 2002 19:20:48 +0100


Guido van Rossum <guido@python.org> writes:

> This can be solved (as MAL suggested) by fixing configure so that
> malloc(0) returning 0x800 is treated the same as malloc(0) returning
> NULL.  That way, pymalloc's free code doesn't have to special-case
> this.

This is nearly as bad as hard-coding the system on which it
happens. If system developers come to like this trick, they may decide
to return 0xFFFF0000 for malloc(0) (system developers, when confronted
with a non-conformity in their implementation, always love to find a
conforming but surprising implementation).

Given that this is quite hard to debug if it happens, I'd rather like
to see a better test. It's not easy to find one, though.

One would be to do MALLOC_ZERO_RETURNS_ALWAYS_THE_SAME_THING, which
would cover this and similar implementations (i.e. you test malloc(0)
== malloc(0)).

Another test would be MALLOC_ZERO_RETURNS_NO_MEMORY: malloc(0), round
down to the page beginning, read a word there, expect a crash. This
tests precisely the functionality that pymalloc needs.

Regards,
Martin