This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lemburg
Recipients belopolsky, georg.brandl, jcea, lemburg, mark.dickinson, ncoghlan, pitrou
Date 2011-02-23.11:31:58
SpamBayes Score 4.7032933e-12
Marked as misclassified No
Message-id <4D64F02D.3010504@egenix.com>
In-reply-to <1298459807.3710.15.camel@localhost.localdomain>
Content
Antoine Pitrou wrote:
> 
> Antoine Pitrou <pitrou@free.fr> added the comment:
> 
>> PyUnicode_Decode() et al. are conversion functions and these
>> require valid content to work on. Passing in a NULL pointer
>> does not fit that specification and so allowing for this
>> would hide programming errors.
> 
> "Valid content" doesn't mean a lot when the length is 0.
> What is a valid 0-length string compared to an invalid one?
> What if the pointer is non-NULL but segfaults when trying to dereference
> it? Is it "valid"?
> 
> Moreover, malloc() is allowed by POSIX to return NULL when called with a
> 0 length:
> 
>         If size is 0, either a null pointer or a unique pointer that can
>         be successfully passed to free() shall be returned.
> 
> (http://www.opengroup.org/onlinepubs/007904875/functions/malloc.html)
> 
> ... which means that such a pointer can then, depending on the platform,
> get passed (legitimately) to PyUnicode_Decode().

... and Python has for years made sure that PyMem_Malloc() et al.
return a non-NULL pointer when passed a size 0 value (see pymem.h for
details), since the above was a really poor design choice.

A lot of Python code relies on those functions returning NULL only
in case of an error.

> So, IMO, practicality beats purity here. Especially since it is bound to
> land in a bugfix release (3.2.1), which users don't expect to produce
> regressions in their own code.

Nope. Your suggestion would be a new feature and those are not
allowed in patch level releases.

I'm -1 on the idea for the reasons already stated.
History
Date User Action Args
2011-02-23 11:32:02lemburgsetrecipients: + lemburg, georg.brandl, jcea, mark.dickinson, ncoghlan, belopolsky, pitrou
2011-02-23 11:31:58lemburglinkissue11286 messages
2011-02-23 11:31:58lemburgcreate