[lxml-dev] Ref-counting bug returns in 1.3.1

Stefan Behnel stefan_ml at behnel.de
Tue Jul 3 23:24:03 CEST 2007



Stefan Behnel wrote:
> David M. Grimes wrote:
>>   I posted a patch for what I believed to be a reference-counting bug in
>> Attrib.pop() based on the 1.3 release.  The patch was accepted, and is
>> present in 1.3.1.
>
> the problem is somewhere else. I'll investigate.

Ok, the problem was actually in the new deallocation code. For those who want
to know: The GC calls tp_clear() before tp_dealloc(), so that Pyrex has
already set the _Document reference of the _Element to None when __dealloc__
is called on the _Element and tries to Py_DECREF the doc reference =>
deallocating None.

I worked around this by adding a redundant PyObject* to _Element that
references the document. Pyrex does not set it to None so that we can keep a
pointer in there when the Python reference is already None-ed and DECREF it
ourselves.

Obviously, that's a hack, but it works, so I'll leave it in and release a
1.3.2 with it...

Stefan


More information about the lxml-dev mailing list