[Python-checkins] r45505 - python/trunk/Modules/posixmodule.c

"Martin v. Löwis" martin at v.loewis.de
Tue Apr 18 08:34:50 CEST 2006


Neal Norwitz wrote:
>> -        if (len == 0) {
>> +       if (len == -1) {
> This code seems broken (both before and after this patch) based on:
> http://www.opengroup.org/onlinepubs/009695399/functions/confstr.html
> 
> The return type is size_t and cannot return -1.  Do we know if the
> previous code ever worked?  Is there any system that does return -1? 

It's now broken in a different way. Previously, it was broken because
it reset errno after the call. Now it is broken because it treats -1
as an error indication; the correct error indication is 0 (but 0
also indicates that there is no configuration-defined value, hence
errno must be set to 0 before the call).

Also, I suggest to use None as the return value for "no value
available"; it might be that the configured value is an empty
string (in which case confstr returns 1).

Also, the PyString_FromStringAndSize is wrong: the confstr result
includes the terminating \0, whereas PyString_FromStringAndSize
doesn't.

Also, for symmetry, it would be better if
PyString_FromStringAndSize is also used in the case without
resizing. This would also have the advantage of allowing for
results that include \0 (although I doubt they are actually
used).

Regards,
Martin


More information about the Python-checkins mailing list