[Cython] Bug in ord(Py_UNICODE) optimization
Stefan Behnel
stefan_ml at behnel.de
Sat May 28 01:16:25 CEST 2011
John Ehresman, 27.05.2011 21:55:
> ord() applied to a Py_UNICODE typed variable seems to yield a 1 character
> unicode string rather than an integer. The following doctest fails when
> added to unicodefunction.pyx:
>
> def Py_UNICODE_ord(unicode s):
> """
> >>> Py_UNICODE_ord(u' ')
> 32
> """
> cdef Py_UNICODE u
> u = s[0]
> return ord(u)
ord() is actually unpacked in this case (see Optimise.py), but the result
type is incorrect. It's Py_UNICODE (which coerces back to a unicode
string), whereas it should be int (thus coercing to a Python integer object).
I pushed a fix, and also the obvious optimisation for calling ord() on
single character string literals.
Thanks for the report.
Stefan
More information about the cython-devel
mailing list