Sean Chittenden wrote:
A "real" solution would involve XPath objects registering themselves with documents, and documents checking them when freed. The reason is that Ruby calls free functions in random order. See discussion here:

http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-core/17725?17500-17840+split-mode-vertical

XPathObjects should have a custom mark function that marks their dependent XML Document object. XPathObjects need to have that reference in their structure. -sc

They do - that's not the problem. The problem is that Ruby ignores mark functions on process shutdown. In other words, free functions are called in a random order. For more details see the above thread.

I view this as a shortcoming in Ruby's GC. To work around requires implementing our own custom mark implementation. Basically an xpath object would register a pointer to itself with its parent document. When the document is freed, the document checks its list of xpath object pointers. In a normal running program, this will always be none because of mark/sweep. In a terminating process, there may be some. In that case, the document calls back to the xpath object to tell it to free its underlying c data. Then when the xpath object's free function is called a few milliseconds later, its already freed its c data so no segmentation fault takes place.

I can't decide if its worth the bother or not...Its clearly easier in Ruby to set the xpath object to nil and force a GC, but then you are forcing a c idiom onto a Ruby programmer.

Charlie

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to