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?

Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to