Py-Extension Irregularity

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Mar 6 15:25:04 EST 2008


En Thu, 06 Mar 2008 13:54:44 -0200, Michael Wieher  
<michael.wieher at gmail.com> escribi�:

> 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.)

Why do you assert that? With those commented out lines, the last item  
returned by getQuestion (sz) is always 0; nothing is printed because sz==0  
and the python code never enters the outer if. From that evidence I can't  
say anything about _diff.

> 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.

I'd print m_mdx values in the C++ source.

> How in Buddah's name is returning a Py_BuildValue() affecting a file  
> pointer
> that isn't being used at all in the function????

I don't think this is the cause...

-- 
Gabriel Genellina




More information about the Python-list mailing list