[Pyrex] How to deal with a block of memory when pickling?

Simon Burton simon at arrowtheory.com
Thu Mar 20 14:52:15 CET 2008


On Thu, 20 Mar 2008 14:42:59 +0100 (CET)
Simon King <king at mathematik.uni-jena.de> wrote:

> 
> I tried to make a type cast of p to char* and to read this as a string.
> In some cases it worked, and going the way back (string -> char*)
> reconstructed the memory block p was pointing at.
>  However, sometimes apparently it was not clear to python how long the 
> string is supposed to be; so i got an empty string, and the reconstruction 
> failed.
> 
> What can i do? 
> 
> Cheers
> 	Simon

Use these functions instead:

cdef extern from "Python.h":

    object PyString_FromStringAndSize(char *s, Py_ssize_t len)
    char* PyString_AsString(object string)






More information about the Pyrex mailing list