Re: Coexistence of libxml++ and libxml2 in the same process



On Thursday 04 November 2010 17:28:18 Murray Cumming wrote:
> On Thu, 2010-11-04 at 17:12 +0100, Alessandro Pignotti wrote:
> > I've delved a bit more into the issue and the handlers are completely non
> > thread safe, being saved inside global data in the library address space.
> 
> Is anything else in libxml thread safe anyway?
> 
> > I think the only sane approach would be purgin away the specialized
> > handlers and:
> > 
> > -) Allocate C++ instances Just in time (checking for _private being NULL)
> 
> I don't understand what you are suggesting in these previous two
> sentences. Sorry.
> 
> > -) Deallocate the instances by traversing the children of nodes before
> > calling xmlFree*
> > 
> > What do you think?
> > 
> > Alessandro

The init becomes

Document::Init::Init()
{
  xmlInitParser(); //Not always necessary, but necessary for thread safety.
}

so the handlers are not set to the libxml++ one. So now we must create and 
delete the corresponding C++ instances for each node manually. I'm proposing 
creating them just before their use. Take for example

Element* Document::get_root_node() const
{
  xmlNode* root = xmlDocGetRootElement(impl_);
  if(root == 0)
    return 0;
  else
  {
//    if(root->_private==NULL)
//            on_libxml_construct(root);
    return reinterpret_cast<Element*>(root->_private);
  }
}

The commented lines are the one added by me. _private will be NULL the first 
time and so we can allocate the instance before the first usage.

If you want to discuss this you can find me online in the #lightspark IRC 
channel on freenode

Alessandro

Attachment: signature.asc
Description: This is a digitally signed message part.



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