Re: [xml] Support for Python



On Mon, 28 Jan 2002, Gary Benson wrote:


On Mon, 28 Jan 2002, Dave Kuhlman wrote:

_But_, I worry about code like the following:

doc = p.xmlParseFile('test1.xml')
root = doc.children
doc = p.xmlParseFile('test1.xml')

Now, root contains a reference to a Python object that contains a
reference to an underlying C object (a libxml node) that has gone
away.  Am I right about this?  If so it seems very dangerous.
xmlFreeDoc frees the nodes in the doc, too, doesn't it?

Hmmm, if xmlNodes in doc.children have references to the parent (ie the
xmlDoc) then this _should_ work -- the first doc won't be garbage
collected because root.parent is referencing it. On the other hand, it
might have created an undeletable object.

No, because root.parent is a C pointer, not a python one. So python would
see no reference to doc any more. That is unless you use proxy objects
like XML::LibXML.

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




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