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

Tim Peters tim.one@comcast.net
Fri, 22 Nov 2002 12:45:49 -0500


[Marc Recht]

What about changing PyMemMALLOC malloc to #define PyMemMALLOC(n) n ? malloc(n) : NULL

No, but expanding to malloc(n || 1) or malloc(n ? n : 1) would be fine. Code in Python uses a NULL return as an indication that a memory operation failed, so returning NULL is never appropriate for a PyMem_Malloc(0) call -- the Python API guarantees that its memory functions return NULL to mean out-of-memory, and that 0 is an OK argument.

The configuration cruft should go away here. It's proven itself too brittle too many times. That is, we should pretend that all platforms are insane, and never pass 0 to any platform's malloc or realloc.