<HTML dir=ltr><HEAD><TITLE>Re: [lxml-dev] Ref-counting bug returns in 1.3.1</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.6000.16481" name=GENERATOR></HEAD>
<BODY>
<DIV id=idOWAReplyText98872 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>If there's anything else I can do to help test/diagnose, let me know ...</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT face=Arial size=2>&nbsp;--Dave</FONT></DIV>
<DIV dir=ltr>&nbsp;</DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Stefan Behnel [mailto:stefan_ml@behnel.de]<BR><B>Sent:</B> Tue 7/3/2007 4:41 PM<BR><B>To:</B> Grimes, David<BR><B>Cc:</B> lxml-dev@codespeak.net<BR><B>Subject:</B> Re: [lxml-dev] Ref-counting bug returns in 1.3.1<BR></FONT><BR></DIV>
<DIV><BR>
<P><FONT size=2>David M. Grimes wrote:<BR>&gt;&nbsp;&nbsp; I posted a patch for what I believed to be a reference-counting bug in<BR>&gt; Attrib.pop() based on the 1.3 release.&nbsp; The patch was accepted, and is<BR>&gt; present in 1.3.1.&nbsp; The patch is included at the end of this message.<BR>&gt; Looking through the generated C code, I'm no longer sure my patch was<BR>&gt; correct - perhaps just masking the underlying problem in 1.3.&nbsp; I'm not<BR>&gt; fluent in Pyrex, so not sure if the python.Py_INCREF is really necessary<BR>&gt; for something which would be a "borrwed reference" in the C-API<BR>&gt; (PyTuple_GET_ITEM result).&nbsp; It looks like the Pyrex "return" is<BR>&gt; generating it's own INCREF ...<BR><BR>You can debug this kind of problem with<BR><BR>&nbsp;&nbsp;&nbsp; print sys.getrefcount(None)<BR><BR>When I run the following on 1.3.1:<BR><BR>&nbsp;&nbsp;&nbsp; et = etree.fromstring(xml)<BR>&nbsp;&nbsp;&nbsp; for i in range(10000):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print i<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print sys.getrefcount(None)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; et.attrib.pop('x', None)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print sys.getrefcount(None)<BR><BR>instead of your test, it shows me that the problem is not "pop()", as the<BR>ref-count is constant at each iteration. Trying to remove the Py_INCREF() from<BR>your patch makes it crash with a continuously decreasing ref-count. However,<BR>when I run your test:<BR><BR>&nbsp;&nbsp;&nbsp; for i in range(10000):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print i<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; et = etree.fromstring(xml)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print sys.getrefcount(None)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; et.attrib.pop('x', None)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print sys.getrefcount(None)<BR><BR>the ref-count keeps increasing until the garbage collector hits and then drops<BR>below the start value and finally crashes on the second GC run. So the problem<BR>is somewhere else. I'll investigate.<BR><BR>Thanks for the report,<BR>Stefan<BR></FONT></P></DIV><br><SPAN STYLE='FONT-SIZE: 8pt; FONT-FAMILY: Arial'><I>This e-mail is the property of NaviSite, Inc. It is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential, or otherwise protected from disclosure. Distribution or copying of this e-mail, or the information contained herein, to anyone other than the intended recipient is prohibited.</I></span><br></BODY></HTML>