Re: [xml] Support for Python



On Mon, 28 Jan 2002, Daniel Veillard wrote:

If we write the classes in Python then this is trivial -- call xmlFreeDoc
in the XmlDocumentClass's destructor and let Python's garbage collector
work out when to do it.

Interesting idea.  Because of your suggestion, I looked at the
generated code.  And, I can modify the SWIG generated code so that
the Python __del__ method in the Doc class will call a C delete
method and I can modify the C delete method so that it calls
xmlFreeDoc.

  Really dangerous. As you pointed out too as soon as Python will loose
a pointer to the root it would then deallocate the full subtree. Too
dangerous to be allowed. I started toying with the idea but as soon
as I tried to build an example I realized it would really make a big problem.
  I don't think we can have garbage collectable xmlDoc, though nearly
every other classes exposed should be garbageable.

We do this with a proxy object in the Perl interface - the proxy simply
makes sure that the refcount doesn't get lost, and then DESTROY
(equivalent of __del__) does the xmlFree stuff. Works mostly quite well,
though it's a bit tricky to debug.

-- 
<!-- Matt -->
<:->Get a smart net</:->




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]