What about changing PyMem_MALLOC malloc to #define PyMem_MALLOC(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.