Bugs item #16214, was opened at 2007-12-10 08:29 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=1971&aid=16214&group_id=494
Category: memory Group: v0.5 >Status: Closed Resolution: None Priority: 4 Submitted By: Dan Janowski (danj) >Assigned to: Charlie Savage (cfis) Summary: SEGV when add the cloned/copied node Initial Comment: Originally appeared on mail list by optyk (2007-11-27). segv appears when use clone and copy methods, what's interesting, with clone segv is thrown in div1.child_add(c) line (see script) but when use copy I get it in printf root statement, moreover copy seems to work wrong only for text nodes, when use 't3' div everything works fine I get this error on 0.5.2.0, 0.5.2.1 and 0.5.2.2 (latest svn) version it looks like fix is required in ruby-libxml code, BTW. it looks also like ruby_xml_node_copy() in ruby_xml_node.c calls xmlCopyNode() with wrong attributes, it should be 2 for shallow copy and 1 for deep copy -------------------- SCRIPT --------------------- require 'xml/libxml' str = <<-STR <html> <body> <div class="textarea" id="t1" style="STATIC">werwerwerwerwer </div> <div class="textarea" id="t2" style="STATIC"> Quisque et diam dapibus nisi bibendum blandit. </div> <div class="textarea" id="t3" style="STATIC"> <p>aaaaaaaaa</p> </div> </body> </html> STR XML::Parser.default_keep_blanks = false xp = XML::Parser.new xp.string = str doc = xp.parse xpath = "//[EMAIL PROTECTED]'t1']" div1 = doc.find(xpath).to_a[0] printf "xxx div1: #{div1}\n" xpath = "//[EMAIL PROTECTED]'t2']" div2 = doc.find(xpath).to_a[0] printf "xxx div2: #{div2}\n" div2.each do |child| #c = child.clone c = child.copy(false) div1.child_add(c) end printf "xxx root: #{doc.root}\n" ---------------------------------------------------------------------- >Comment By: Charlie Savage (cfis) Date: 2008-07-01 03:05 Message: Dan - this seems to work fine now, I imagine due to your changes. I added it as a test case, and am now closing. ---------------------------------------------------------------------- Comment By: Dan Janowski (danj) Date: 2007-12-10 08:37 Message: keisuke fukuda submitted a patch for this problem which I have carefully examined. The given patcch fixes the problem by creating an unintended consequence, by always copying text nodes. However, the real cause of the problem is more subtle and has to do with merging of text nodes when the parent node already has an associated text node. Since we cannot have a text node that is mapped into ruby simply disappear, they do always need to be copied. However, a few additional conditions needed to be handled. ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=1971&aid=16214&group_id=494 _______________________________________________ libxml-devel mailing list libxml-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/libxml-devel