[xml] xmlInitParser/xmlCleanupParser


I have some concern about current implementation of Init/Clean.

So really when I init parser it set xmlParserInitialized flag and eats next attempts to initialize,

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

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.

Still xmlInitParser/xmlCleanupParser calls won’t be thread safe, by the matter of fact user should ensure atomic execution of

these functions, but this is fine and expected.


Any suggestions?





So code might look like that:

static unsigned int xmlParserInitialized = 0;


xmlInitParser(void) {


            if( !xmlParserInitialized ) {

                        ….//init here



            if ( xmlParserInitialized < UINT_MAX )





xmlCleanupParser(void) {

            if( xmlParserInitialized == 1 ) {

            …//clean up here



if( xmlParserInitialized )






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