Hi Olivier, Olivier Grisel wrote:
On my box (Ubuntu Linux Dapper Drake on i686 / python2.4) all tests pass but running the bench scripts yields some problems: [snip] append_element and replace_children triggers segmentation faults. The first one crashed after child <Element {bcd}zzzzz at -48285674>.
It took me a while to track down this bug, as it was absolutely not where the benchmark code suggested. The test case that triggers it is:
a = Element('a') b = copy.deepcopy(a) b.append( Element('c') ) del b
The problem lies in the modified Element.__copy__() method I wrote. Instead of creating a new document for the copied tree, it tried to copy the original document structure to keep its settings. I now found that this additionally requires copying the pointer to the parser dictionary also, otherwise libxml2 ends up freeing still-in-use entries from it when deallocating the copied nodes... Things like this tend to remind me of one of the major reasons for having lxml: *one* place to get this stuff right is just so enough... To prevent further bugs like this, I wrote a new helper function _copyDoc that copies the document and sets the dict, and a convenience function _copyDocRoot that makes a specific node the new root node in the copied document (using fakeRootDoc before copying). The bug is now fixed on the trunk. I also updated a couple of places in xslt.pxi where documents are copied, just in case... Stefan