Re: How to deal with a block of memory when pickling?

Simon Burton <[email protected]>
Newsgroups gmane.comp.python.pyrex
Message-ID <[email protected]>
On Thu, 20 Mar 2008 14:42:59 +0100 (CET)
Simon King <[email protected]> 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)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.