[Python-Dev] Problem with the memory docs
Fri, 05 Apr 2002 05:12:56 -0500
>> I'm not following this at all. Calling malloc(1) does exactly
>> what Guido wants. "malloc(1)" isn't a broken Unix manpage reference,
>> if that's how you're reading it; it means call malloc with an argument
>> of 1.
> I think I'm now getting to the root of your confusion. Calling
> malloc(1) is *not* what Guido wants. Instead, he wants that
> py_malloc(0) returns a non-null pointer "normally".
And there's no better way to be 100% clear about what that means than to
specify a trivial implementation that satisfies it. It doesn't need a pile
of words like this:
> Now, there are some C libraries which normally return a NULL pointer
> for malloc(0); as you point out, C gives them the freedom to do so. To
> work-around this under-specification, one can call malloc(1) -
> standards mandate that this does attempt to allocate something. It may
> be possible to find different work-arounds, but this is the most
> straight-forward one.
Writing an essay on malloc() isn't going to make the docs clearer than
saying PyMem_Malloc(0) acts like malloc(1). Even the C standard is reduced
to saying "the behavior is as if the size were some nonzero value" when a
platform chooses not to return NULL every time malloc(0) is called. I'm
saying straight out that Python's choice for "some nonzero value" is always
1. It couldn't be clearer or briefer than that: both rigorously correct
and intuitively clear with one shot.
If there's something you want to see done here, please say what it is, or
suggest the exact words you want to see in the docs.