access string data from within cython

sturlamolden sturlamolden at yahoo.no
Wed Aug 5 15:23:16 EDT 2009


On 5 Aug, 19:16, "Diez B. Roggisch" <de... at nospam.web.de> wrote:

> void foo(void *data, size_t length)
>
> The wrapper is supposed to be called with a python (byte)string instance,
> which might contain more than one '\0'-character.
>
> So how do I access the raw data of a string?

cdef extern void foo(void *data, int length)
cdef char *data
cdef int length
bytestring = ... #whatever

rawdata = <char *> bytestring
length = <int> len(bytestring)

foo(data, length)





More information about the Python-list mailing list