Py-Extension Irregularity

Michael Wieher michael.wieher at gmail.com
Thu Mar 6 15:34:45 EST 2008


Ah.  Well, that is true =)

Still, the fact of the file-pointer shifting more than 16-increments to the
right is insane.  Its a simple read(&struct,16) command.

but you're right, the problem might lie elsewhere.  I forgot that using 0
for a sentinel value in two places can confuse a complier (let alone me.)

I ended up fixing it by resetting the file-pointer to zero on re-entry, and
then manually fseeking() to the correct location each time.  Its one extra
command per iteration, but not a huge speed issue.
I feel bad using a global file object, but its that or I open/close it every
time I call the funct.

Thanks for pointing out that bit of confusion =)

2008/3/6, Gabriel Genellina <gagsl-py2 at yahoo.com.ar>:
>
> 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
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080306/70c02765/attachment-0001.html>


More information about the Python-list mailing list