[Python-Dev] List wisdom

Uche Ogbuji uche.ogbuji@fourthought.com
Mon, 14 Apr 2003 08:10:12 -0600


> >>         self.assertRaises(ValueError, range, 1e100, 1e101, 1e101)
> > ...
> > Given this, there's approximately no chance gc *caused* it.  Who's been
> > mucking with function calls (or maybe the eval loop) recently?
> 
> It appears to be a refcount error in recently-added C code that tries to
> generalize the builtin range() function, specifically here:
> 
>   Fail:
> 	Py_XDECREF(curnum);
> 	Py_XDECREF(istep);  <- here
> 	Py_XDECREF(zero);
> 
> Word to the wise:  don't ever try to reuse a variable whose address is
> passed to PyArg_ParseTuple for anything other than holding what
> PyArg_ParseTuple does or doesn't store into it.  You'll never get the
> decrefs straight (and even if you manage to at first, the next person to
> modify your code will break it).

This snippet sparked a little chain of events for me.  I'm sure I've violated 
the principle before (foolishly trying to avoid declaring yet more C 
variables: I've always known it's bad style, but never thought it dangerous).  
I wanted to know whether this wisdom could be found anywhere a Python/C 
programmer would be likely to browse.

So I dug through the Python Wiki, and found no such page of gems (just a lot 
of whimsical quotes from #python and a code-sharing page with some odd 
trinkets).  I also checked to see if #python had a chump (opt-in log) on which 
I could put the quote.  No dice.  I did chump it on the #4suite log:

http://uche.ogbuji.net/tech/akara/?xslt=irc.xslt&date=2003-04-14#14:03:38

I also created a Python Wiki page for useful notes and code snippets from this 
mailing list:

http://www.python.org/cgi-bin/moinmoin/PythonDevWisdom

Please feel free to use it if anything here seems especially important to 
highlight (in addition to Brett Cannon's tireless work, of course).

Thanks.

hoping-to-save-others-an-eight-hour-odyssey-ly y'rs


-- 
Uche Ogbuji                                    Fourthought, Inc.
http://uche.ogbuji.net    http://4Suite.org    http://fourthought.com
Gems From the [Python/XML] Archives - http://www.xml.com/pub/a/2003/04/09/py-xm
l.html
Introducing N-Triples - http://www-106.ibm.com/developerworks/xml/library/x-thi
nk17/index.html
Use internal references in XML vocabularies - http://www-106.ibm.com/developerw
orks/xml/library/x-tipvocab.html
EXSLT by example - http://www-106.ibm.com/developerworks/library/x-exslt.html
The worry about program wizards - http://www.adtmag.com/article.asp?id=7238
Use rdf:about and rdf:ID effectively in RDF/XML - http://www-106.ibm.com/develo
perworks/xml/library/x-tiprdfai.html