[Cython] PyUnicode_Tailmatch

Stefan Behnel stefan_ml at behnel.de
Tue Jul 7 21:07:52 CEST 2015


Robert Bradshaw schrieb am 07.07.2015 um 19:05:
> On Tue, Jul 7, 2015 at 8:11 AM, Josh Ayers wrote:
>> In the function __Pyx_PyUnicode_Tailmatch, the return type of
>> PyUnicode_Tailmatch is assumed to be in int.  See line 543 of
>> Cython/Utility/StringTools.c.
>>
>> PyUnicode_Tailmatch actually returns a Py_ssize_t.  See:
>> https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_Tailmatch.
>>
>> For reference, there was previously an error in the Python documentation
>> of this function.  The documentation mistakenly said it returned an int.
>>  This was fixed via Python issue 22580:
>> https://bugs.python.org/issue22580.
>
> Fixed (though I'm inclined to agree with the assessment that this
> choice of return type was a bug in the first place).
> 
> https://github.com/cython/cython/commit/0a5890216d29d7bce941c9ab5cb0cb818eed643d

That's not a complete fix, though, because it would also be necessary to
widen the types wherever these functions are called. I therefore prefer an
explicit and local downcast to "int" over letting this API quirk spread.

https://github.com/cython/cython/commit/9962ade0f048dac953b974ff9dddf087ed2b8fab

Stefan



More information about the cython-devel mailing list