More help with Object Caching

Brent Fulgham brent.fulgham at xpsystems.com
Tue Feb 29 12:54:05 EST 2000


Note:  I sent this mail yesterday, but problems at my ISP have
delayed it.  So you might see this come through again later today
(with more detail than I can give from memory here):

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?  I'm guessing that
PyObject_Length(code) is not returning the full size that needs to
be copied (i.e., cacheable to cacheable+length does not encompass
the entire object).  Is there some trailer information that is not
included in the "length" value?

But then, why does the first PyMarshal_ReadObjectFromString work,
since it is passed the same "size" variable.  Perhaps the strncpy
is not valid?  Or should everything be stored as "unsigned char"
instead of "char" for some reason?

Any help greatly appreciated.

Regards,

-Brent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20000229/6fe0807a/attachment.html>


More information about the Python-list mailing list