I don't know if libxml2 provides such callbacks, but I don't see how
this would work anyway.  The xmlNode has no idea what ruby objects are
referencing it.

Right - you have to add in mapping between Ruby objects and libxml objects (its a hash table keyed on the C pointer having pointers to the Ruby objects as values). Its easy to do, just tedious.

 Instead of trying to ensure that we free the ruby
object when the xmlNode is freed, we have to ensure that such nodes
referenced by ruby objects are not freed at all by xmlFree.

Boy - that's tough in a tree. What if you have a reference to a leaf node, but no longer to the root. How are you supposed to free the whole tree when you are done with the leaf?


I don't think it requires any more mapping than is in place now, with
each ruby object knowing the xmlNode it represents.  Beyond that the
reference counting should be enough.

Not if libxml frees the memory from under you. So your point of view is that Ruby entirely controls the memory allocation/deallocation. But see my point above for why that could be tough.

Right now, each xmlNode knows how many ruby objects it is referenced
from (assuming the reference counting works).  When a ruby object is
freed, it decrements the reference count and if it is the last object
referencing the xmlNode, and that xmlNode is not referenced by parent
nodes, then the xmlNode is freed using xmlFree.  The problem is that
xmlFree will free child nodes without checking whether they are
referenced from ruby.  That's why I think we need to walk the tree and
remove such nodes prior to letting xmlFree do its stuff.

Walk what tree? The Ruby tree (thereby creating a bunch of new ruby objects and unneeded references)? The libxml c tree? If so, you are back to having to know which Ruby objects point to which libxml object.

I don't see how this would be possible.  My target documents are built
one node at a time from ruby objects.  I think ruby needs to own those
objects.

When you add the Ruby objects to a tree, the Ruby objects can give up ownership (that's simple, set the free method to nil).

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