More help with Object Caching

Gordon McMillan gmcm at hypernet.com
Tue Feb 29 13:55:24 EST 2000


Brent Fulgham writes:

> I've discovered that when I put one of my 'stringified' objects
> into my Cache, they don't come back out.  Take for example:
> 
> // Note:  'code' is a valid PyCodeObject*
> char* cacheable = PyMarshal_WriteObjectToString(code);
> long size = PyObject_Length(code);
> 
> // This works
> PyObject* test1 = PyMarshal_ReadObjectFromString(cacheable, size);
> PyCodeObject* codeTest1 = (PyCodeObject*)test1;
> 
> // This fails
> char* newCache = malloc(length*sizeof(char));
> strncpy(newCache, cacheable, size);
> 
> PyObject* test2 = PyMarshal_ReadObjectFromString(newCache, size);
> // Fails -- test2 is NULL.
> 
> Can anyone suggest what I am doing wrong here? 

Thinking that a Python string (which can contain null bytes) 
can be copied like a C string?



- Gordon




More information about the Python-list mailing list