Py-Extension Irregularity

Michael Wieher michael.wieher at gmail.com
Thu Mar 6 16:54:44 CET 2008


Observe.

Python Code Snippet:
====================
...
 66         while i < (self.nPCodes):
 67            # print "%s:%s" % (self.nPCodes,i)
 68             (c,l,sn,f,fn,sz) = tabmodule.getQuestion(i,self.mx3Path)
 69             if _debug and sz>0:
 70                 _newPtrLoc = tabmodule.getMx3Ptr()
 71                 _diff = _newPtrLoc-_oldPtrLoc
 72                 _oldPtrLoc = _newPtrLoc
 73                 if _diff>16:
 74                     print _diff
....

C++ Code Snippet:
---------------------------
189 static PyObject*
190 tabmodule_getMx3Ptr(PyObject * self, PyObject * args) {
191     int a;
192     a=mx3File.tellg();
193     return Py_BuildValue("i",a);
194 }
...

189 PyObject *
190 tabmodule_getQuestion(PyObject * self, PyObject * args) {
....
208    mx3File.read((char*)&m_mdx,16);
....
237     //if(m_mdx.size==0)
238         return Py_BuildValue("iiiiii",0,0,0,0,0,0);
239     //return Py_BuildValue("iiiiii",m_mdx.compression, m_mdx.location,
m_mdx.stacknotes, m_mdx.file, m_mdx.footnote, m_mdx.size);
}

Output==
michael at majw-m65:~/MRI/tabModule$ ./tabModule.py
michael at majw-m65:~/MRI/tabModule$

None.  (ie: the _diff is always 16 or less, which is what is SHOULD be, in
fact, it is always 16.)

Observe!!!!

237     if(m_mdx.size==0)
238         return Py_BuildValue("iiiiii",0,0,0,0,0,0);
239     return Py_BuildValue("iiiiii",m_mdx.compression, m_mdx.location,
m_mdx.stacknotes, m_mdx.file, m_mdx.footnote, m_mdx.size);

By uncommenting line 237 and 239, we see:
...
64
80
32
32
32
48
128
160
32
32
64
....

Most of the numbers are still 16, but _diff is often larger than 16, by some
multiple.

How in Buddah's name is returning a Py_BuildValue() affecting a file pointer
that isn't being used at all in the function????
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080306/1bbbca06/attachment.html>


More information about the Python-list mailing list