[Python-Dev] check for PyUnicode_READY look backwards

Victor Stinner victor.stinner at haypocalc.com
Fri Oct 7 09:56:51 CEST 2011


Le 07/10/2011 00:20, "Martin v. Löwis" a écrit :
> Am 06.10.11 14:57, schrieb Amaury Forgeot d'Arc:
>> Hi,
>>
>> with the new Unicode API, there are many checks like:
>> + if (PyUnicode_READY(*filename))
>> + goto handle_error;
>
> I think you are misinterpreting what you are seeing.
> There are not *many* such checks. Of the PyUnicode_READY
> checks, 106 take the form
>
> if (PyUnicode_READY(foo) == -1)
> return NULL;
>
> 30 tests take the form that you mention.
>
> I believe all of those have been added by Victor, who
> just didn't follow the convention.

Yes, I wrote if (PyUnicode_READY(foo)), but I agree that it is confusing 
when you read the code, especially because we have also a 
PyUnicode_IS_READY(foo) macro!

if (!PyUnicode_READY(foo)) is not better, also because of 
PyUnicode_IS_READY(foo).

I prefer  PyUnicode_IS_READY(foo) < 0 over PyUnicode_IS_READY(foo) == -1.

Victor


More information about the Python-Dev mailing list