Hello,

First the problem that i have. Right now, when i get a string back from a C function, i have to do 2 copies of it:

ffi.cdef("""
const char *getString(...);
""")

tmp = ffi.string(clib.getString(...)) # 1st copy
pystring = tmp.decode('utf-8')      # 2nd copy

So i thought why not use an ffi.buffer on it and do the decoding directly on the buffer:

cstr = ffi.new('char []', 'abcd')
b = unicode(ffi.buffer(cstr), 'utf-8')

Above works.

But the problem is that in C a function that returns an array cannot be declared. So i cannot do a:

b = unicode( ffi.buffer( clib.getString(...) ) ,'utf-8')

because it'll only return the first character of getString, due to being declared as a 'char*'.

Is there any way in CFFI to declare a function as returning a 'char[]' so as a buffer can be directly used on its results?

Thank you.

l.



_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to