Hi Alexy,I'm not familiar with the libxml binding code, but have worked a fair bit on the SWIG ruby bindings in the past.
Unless you try hard not to - you'll always end with multiple Ruby objects referencing the same C object. Just think of a C object that has some property. Say a node has attributes. Every time you call:
node->attributesYou'll create a new wrapper object. To avoid that, you need to cache the previous wrapper object you created and reuse it. That makes the code uglier and more complex. But the payoff is that it seems more natural from the Ruby side, and it makes memory management a whole lot easier.
From reading previous posts in this mailing list, it seems like libxml probably hast this issue in spades.
Would be interesting to see how Hpricot avoids it. Charlie Alexy Khrabrov wrote:
I've written some simple routines to walk an XML ontology with xml/ libxml, and noticed that putting XML::Node objects into lists and returning them may lead to a situation where two lists contain the same node with different object_id's. Here's an exmple, funstion ancestors:require 'xml/libxml' # extend XML::Node with helper methods class XML::Node def ancestors(node_type=nil) #print "=>" res = [] p = self while p = p.parent and p.name do next if node_type and p.name != node_type res << p if p #puts "added #{p.name}" end res.reverse end # ... -- more methods endNow I found that if I call it on some tree and get at least two nodes, and then compare the first elements of each list, which should be the root in both cases, I get different object_id's. But == returns equality. What's going on here? Hpricot used to maintain the same object_id across assignments, which is usually the case in Ruby... Are there any think objects created for XML::Node's here?Cheers,Alexy _______________________________________________libxml-devel mailing list [email protected] http://rubyforge.org/mailman/listinfo/libxml-devel
smime.p7s
Description: S/MIME Cryptographic Signature
_______________________________________________ libxml-devel mailing list [email protected] http://rubyforge.org/mailman/listinfo/libxml-devel
