Re: libxml2 application data
Petr Pajas <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Organization | UFAL MFF UK |
| Message-ID | <[email protected]> |
Dne Monday 22 December 2008 13:24:11 Robin Berjon napsal(a): > On Dec 22, 2008, at 12:55 , Shlomi Fish wrote: > > On Monday 22 December 2008, Petr Pajas wrote: > >> No, XML::LibXML uses the _private slot for its own purposes. I'd > >> suggest using a Perl hash and $$node as key ($$node is an integer > >> that uniquely identifies a libxml2's node). > > > > As a future extension to XML::LibXML, wouldn't it be possible to put a > > user_data (or whatever) accessor for attaching some Perl data to a > > node which > > will be contained in XML::LibXML's representation of _private? What > > Philippe > > describes sounds like a useful and common use-case. > > And it even is part of DOM 3: > > http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-setUserData Sure. But it should be noted that ATM, XML::LibXML is very far from implementing DOM Layer 3 and some things proposed there seem very hard to implement without modifying libxml2 itself. The problem with _private slot is that in XML::LibXML it has a very peculiar life cycle. If a Perl scalar contains a node, the node's _private structure is maintained by XML::LibXML. If not, node->_private is NULL. Typically only a few nodes are contained in Perl scalars. So the current memory management would have to be modified in order to maintain _private also for nodes with user data even in if the nodes are not contained in Perl scalars (they may still be accessible via DOM or XPath API). And XML::LibXML would have to take special care to decrement user data's refcount before any libxml2 call that might free some node (e.g. xmlFreeDoc or xmlFreeNodeList). Having presently no time to implement that, I'd gladly take patches provided they are complemented by a set of tests with reasonable coverage. -- Petr _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs