Dag Sverre Seljebotn wrote:
> Stefan Behnel wrote:
>> I find it easier to read
>>
>>     def dostuff(str text):
>>         cdef char* s = text.encode("UTF-8")
>>         # do UTF-8 handling stuff
>>         return s.decode("UTF-8")
>>
>> than anything you could do with internal magic.
>>
> Will this work though?

Sorry, my fault. As I described, what I use in lxml is a function that
actually returns an encoded Python byte string, that's what I had in mind.
The above will give you a compiler error about converting a temporary
result.


> I forgot one important case in my list though: Passing string constants
> to C libraries. With no conversion, one cannot at the same time keep
> nice language consistency and also allow
>
> cdef char* s = "asdf"

What is the problem here? Py2 semantics give you a byte string which,
given PEP 263, has a well defined byte sequence that is assigned to the
char*.

If you are referring to Py3 source code semantics, then yes, this will
hopefully raise a compile error. The right thing to do in Py3 Cython code
is to write b"asdf" (which could even be valid Cython code regardless of
the target code version).

Stefan

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

Reply via email to