[Pyrex] How can I get Pyrex to put binary data into a Python string?

Bob Ippolito bob at redivi.com
Wed Feb 2 06:32:26 CET 2005


On Feb 1, 2005, at 11:34 PM, Parzival Herzog wrote:



> I have  some C code that produces binary data bytes at some location. 
> The
> number of bytes is not a constant. I want to transfer this data 
> unaltered as
> the contents of a Python string. This kind of string can be accessed 
> later
> by, e.g. a struct.umpack(...) call.
>
> Pyrex automatically converts a cdef char * variable to a Python 
> string, but
> the resultiong Python string ends at the first zero byte in the 
> buffer.  Is
> there a straightforward way in a pyrex module to transfer a binary 
> string,
> including null characters, to a Python string?
>
> If this is not possible directly with Pyrex, can anyone suggest a good 
> way to
> work around that limitiation?
>

You should be able to just cdef extern PyString_FromStringAndSize and 
call it from Pyrex...

-bob






More information about the Pyrex mailing list