On Oct 17, 2009, at 1:02 AM, Stefan Behnel wrote: > Hi, > > Dag stumbled over a problem with the str/bytes/unicode split. > > http://trac.cython.org/cython_trac/ticket/412 > > Since str literals no longer start out as char*, the following no > longer works: > > cdef int i = 'x' # this works > > if i == 'x': # this doesn't > print True > > The problem is that the comparison considers 'x' a Python string and > thus > coerces i to a Python int for comparison, which obviously fails. > > There are a a couple of ways to deal with this: > > 1) disallow unprefixed char literals also in a C context and require > users > to write > > cdef int i = c'x' > > if i == c'x': > > 2) special case this everywhere we need it, i.e. currently in > StringNode.coerce_to(<C int>) and then also in BinopNode > > 3) let single-char str literals start out as C 'char' type and only > coerce > to Python str at need > > > Personally, I would prefer either 1) or 3), the latter likely being > more > convenient but potentially introducing new pitfalls elsewhere (to be > seen). > > Comments?
I'm for (2) or (3), with a preference for (2). Option (1) will break code (which I'm strongly against) and (3) seems prone to pitfalls as you mention. - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
