access string data from within cython

Philip Semanchuk philip at semanchuk.com
Wed Aug 5 17:30:22 EDT 2009


On Aug 5, 2009, at 5:19 PM, Diez B. Roggisch wrote:

> Philip Semanchuk schrieb:
>> On Aug 5, 2009, at 1:16 PM, Diez B. Roggisch wrote:
>>> Hi,
>>>
>>> I'm trying to wrap a C-API which has a call that takes a void* and  
>>> a size_t
>>> as arguments.
>>>
>>> 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? I tried looking into  
>>> the
>>> buffer-protocol, but to be honest - that's beyond me, I don't see  
>>> where
>>> that is actually giving me access to the real data.
>> Hi Diez,
>> Would ctypes.create_string_buffer() work for you?
>
> I'm not using ctypes because I want a distributable egg with static  
> linkage. ctypes can't help there afaik.

Sorry, I read cython as CPython.





More information about the Python-list mailing list