Re: [xml] xmlInitParser/xmlCleanupParser



On Mon, Aug 25, 2003 at 12:41:33AM -0700, maksim likharev com wrote:
So really when I init parser it set xmlParserInitialized flag and eats
next attempts to initialize,

  right,

For cleanup it checks xmlParserInitialized, and clean up global state,

  right,

But problem is for some sort of addins  ( modules that do not know when
they loaded/unloaded ) as well as 

COM like DLLs ( Win32 ), it is highly possible to call
xmlInitParser/xmlCleanupParser several times,

and without any order, so call of xmlInitParser in one thread might be
corresponding to call xmlCleanupParser in other thread

which effectively screws everything up. 

Proposal is following, use reference count instead, like increment it
every time  xmlInitParser called and init only during first attempt,

And decrement it on every xmlCleanupParser call and cleanup only during
last call.

  I don't like this for the very simple reason that it changes the
semantic of those two calls. This may solve your problem but will
as well generate troubles for those relying on the fact that 
xmlInitParser() call is idempotent in case it already was initialized.
An that may break simpler code, without dynamic loading or threading
or any of the complex interactions you seems to have. Even libxml2/libxslt
internal code has been designed that way and may actually call
xmlInitParser() multiple times, which means that the subsequent
xmlCleanupParser() will not free the memory. No it's really a too
serious breakage of API to be considered.

  If you need a special semantic, I really don't see why you can't put
the global semaphore in your program and call both routines only 
when appropriate. Why put the special semantic within libxml2 itself ?

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.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]