Hi,

having issues with cython/python3 I found the thread
http://www.mail-archive.com/[email protected]/msg02346.html

Actually, I have the same problem:
As *all* strings in cython code get converted to bytes, nothing works out.

I my case I have a c function like:

void foo(char *)

cdef c_foo "foo"(char *)


cdef class A:
   def __init__(self,arg0):
     c_foo(arg0)


calling from python with
x = A('test')

in python the argument 'test' is of type str, cython expects the
argument for c_foo to be of type bytes as char * is mapped to bytes.

Now, as I do not want to change all calls to all functions which take
str arguments, I tried to convert 'test' from str to bytes.

arg0 = arg0.encode("ascii")

Result:
TypeError: encode() argument 1 must be string, not bytes.

Even worse:
if isinstance(arg0, str):

actually checks if arg0 is of type bytes ...

Thats really bad, you can neither create nor recognize or convert
python3 str's in cython.


Maybe mapping "char *" to PyString_Type as a default for all internal
strings, and "unsigned char *" to PyBytes_Type?

Any other suggestions?


MfG
Markus

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

Reply via email to