<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2650.12">
<TITLE>More help with Object Caching</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>Note: I sent this mail yesterday, but problems at my ISP have</FONT>
<BR><FONT SIZE=2>delayed it. So you might see this come through again later today</FONT>
<BR><FONT SIZE=2>(with more detail than I can give from memory here):</FONT>
</P>
<P><FONT SIZE=2>I've discovered that when I put one of my 'stringified' objects</FONT>
<BR><FONT SIZE=2>into my Cache, they don't come back out. Take for example:</FONT>
</P>
<P><FONT SIZE=2>// Note: 'code' is a valid PyCodeObject*</FONT>
<BR><FONT SIZE=2>char* cacheable = PyMarshal_WriteObjectToString(code);</FONT>
<BR><FONT SIZE=2>long size = PyObject_Length(code);</FONT>
</P>
<P><FONT SIZE=2>// This works</FONT>
<BR><FONT SIZE=2>PyObject* test1 = PyMarshal_ReadObjectFromString(cacheable, size);</FONT>
<BR><FONT SIZE=2>PyCodeObject* codeTest1 = (PyCodeObject*)test1;</FONT>
</P>
<P><FONT SIZE=2>// This fails</FONT>
<BR><FONT SIZE=2>char* newCache = malloc(length*sizeof(char));</FONT>
<BR><FONT SIZE=2>strncpy(newCache, cacheable, size);</FONT>
</P>
<P><FONT SIZE=2>PyObject* test2 = PyMarshal_ReadObjectFromString(newCache, size);</FONT>
<BR><FONT SIZE=2>// Fails -- test2 is NULL.</FONT>
</P>
<P><FONT SIZE=2>Can anyone suggest what I am doing wrong here? I'm guessing that</FONT>
<BR><FONT SIZE=2>PyObject_Length(code) is not returning the full size that needs to</FONT>
<BR><FONT SIZE=2>be copied (i.e., cacheable to cacheable+length does not encompass</FONT>
<BR><FONT SIZE=2>the entire object). Is there some trailer information that is not</FONT>
<BR><FONT SIZE=2>included in the "length" value?</FONT>
</P>
<P><FONT SIZE=2>But then, why does the first PyMarshal_ReadObjectFromString work,</FONT>
<BR><FONT SIZE=2>since it is passed the same "size" variable. Perhaps the strncpy</FONT>
<BR><FONT SIZE=2>is not valid? Or should everything be stored as "unsigned char"</FONT>
<BR><FONT SIZE=2>instead of "char" for some reason?</FONT>
</P>
<P><FONT SIZE=2>Any help greatly appreciated.</FONT>
</P>
<P><FONT SIZE=2>Regards,</FONT>
</P>
<P><FONT SIZE=2>-Brent</FONT>
</P>
</BODY>
</HTML>