Re: [xml] Threads and statically linked libxml2 in a plugin



On Thu, Mar 30, 2006 at 02:14:49PM +0200, Gregoire Banderet wrote:
Hello,

I use the libxml2 in my multi-threaded app (let's say MYAPP).
MYAPP runs on Linux-ppc and links libxml2 statically (libxml2.a).
MYAPP is able to load plugins, and one of these plugins uses libxml2 
too. This plugin also links statically libxml2.

  Never ever move tree strcutures between both, it will crash !

My question: Should I call xmlInitParser() and xmlCleanupParser() in the 
plugin code?

  xmlInitParser() yes, xmlCleanupParser() never, you don't care about a 
few KBytes left per lib.

The doc says that xmlInitParser() should be called once per process, so 
the answer should be "no".

  usually there is one instance of the library per process hence the guideline.

But as the code of libxml2 is duplicated in the plugin (because of 
static link), will all the libxml2 variables initialized?
  of course not. How could the two instances of libxml2 linked statically
be aware of each other, clearly not possible.

core on pthred_exit. The crash is in xmlFreeGlobalState(). I guess 
because of the pthread_key_create(&globalkey, xmlFreeGlobalState) done 
in xmlOnceInit(void).

  Patch your libraries to avoid it. You put yourself in a corner by doing
static dual inclusion. No way the lib can detect or handle that behaviour
since you're static you will need to mainatin a local patch.

PS: I can't use libxml2 as a shared lib.

  And I can't handle your corner case, sorry ...

Daniel

-- 
Daniel Veillard      | Red Hat http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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