1 /*
2  * libxml2_globals.c: definition and handling of the set of global variables
3  *                    of the library
4  *
5  * The bottom of this file is automatically generated by build_glob.py
6  * based on the description file global.data
7  *
8  * See Copyright for the status of this software.
9  *
10  * Gary Pennington <Gary.Pennington@uk.sun.com>
11  * daniel@veillard.com
12  * Portion Copyright � 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
13  */
14 #define IN_LIBXML
15 #define UNDEF_IMPORT_C_IN_DATA
16 
17 #include <assert.h>
18 #include <errno.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <stdio.h>
22 #include <stdarg.h>
23 
24 #include "xmlenglibxml.h"
25 
26 #include <libxml2_globals.h>
27 #include "libxml2_xmlschemastypes.h"
28 
29 
30 
31 
32 const xeGlobalConstData xeGlobalConsts =
33     {
34     LIBXML_VERSION_STRING // xmlParserVersion field
35     };
36 
xeGetGlobalConsts()37 const xeGlobalConstData* xeGetGlobalConsts()
38 {
39     return &xeGlobalConsts;
40 }
41 
42 /**
43  * xmlParserVersion:
44  *
45  * Constant string describing the internal version of the library
46  */
47 XMLPUBFUNEXPORT const char* const xmlParserVersion = LIBXML_VERSION_STRING;
48 
49 
50 /*
51 This function creates and initializes new xmlGlobalState structure
52 and stores pointer to it into Thread-Local Storage of this DLL.
53 
54 If TLS is not NULL, then nothing happens and pointer to existing global data is returned
55 
56 This function is used once prior any use of libxml2 code!
57 It called from XmlEngine::XmlEngineAttachL() function
58 and must be called by any other client of libxml2's API if XmlEngineAttachL()
59 is not used.
60 */
xmlCreateAndInitializeGlobalState()61 XMLPUBFUNEXPORT xmlGlobalStatePtr xmlCreateAndInitializeGlobalState()
62 {
63     xmlGlobalStatePtr gs = xeGetTLS();
64     if(gs)
65         return gs; // already initialized;
66 
67     gs = (xmlGlobalStatePtr) malloc(sizeof(xmlGlobalState));
68     if(gs)
69     {
70         memset(gs, 0, sizeof(xmlGlobalState));
71         xeSetTLS(gs);
72         xmlInitializeGlobalState(gs);
73     }
74     return gs;
75 }
76 
77 /*
78 Performs complete cleanup of the resource allocated for Libxml2.
79 Global state data is destroyed.
80 
81 On Symbian:
82   Thread-Local Storage is set to NULL after the cleanup finished.
83 
84  @note XmlEngine::XmlEngineCleanup(TAny*) calls this function
85        as part of XML Engine shutdown sequence; but it also adds
86        counter for multi-user (within one thread) processing support.
87 
88  @note This function should not be directly used by Symbian applications;
89        the only exception for this rule is usage of libxml2 by other
90        open-source libraries [XmlEngine::XmlEngineCleanup(TAny*) is preferred]
91 */
xmlCleanupGlobalData()92 XMLPUBFUNEXPORT void xmlCleanupGlobalData()
93 {
94     DEFINE_GS_PROXY /* NOTE: Initialize GS proxy initialize before using any GS member */
95     xmlGlobalStatePtr gs = xeGetTLS();
96 
97     if(!gs)
98         return;
99     SET_GS_PROXY(gs);
100 
101     xmlSchemaCleanupTypes();
102     xmlResetLastError();
103     xmlCleanupCharEncodingHandlers();
104     xmlCleanupParser();
105     xeXPathCleanup();
106     xeCleanupDOMStringConverter();
107 #ifdef XMLENGINE_XSLT
108     if(xsltGlobalsCleanupFunc)
109         ((void(*)())xsltGlobalsCleanupFunc)();
110 #endif
111     free(gs); //using xmlFree(gs) is not right:  GS was not initialized with xmlMalloc() !
112     xeSetTLS(NULL);
113 }
114 
115 
116 
117 
118 
xmlOOMFlag()119 XMLPUBFUNEXPORT int xmlOOMFlag()
120     {
121     LOAD_GS_DIRECT
122 #ifdef _DEBUG
123     int f = OOM_FLAG;
124     if(f)
125         {
126         f |= 0; // SET BREAKPOINT HERE
127         }
128     return f;
129 #else
130     return OOM_FLAG;
131 #endif
132     }
133 
xeCheckErrno()134 void XMLCALL xeCheckErrno()
135     {
136     int err = errno;
137     if (err == ENOMEM)
138         {
139         SET_OOM_FLAG;
140         }
141 #ifdef _DEBUG
142     else if (err)
143         {
144         // some other error!!!
145         err ^=err;
146         }
147 #endif
148     }
149 
xmlSetOOM()150 XMLPUBFUNEXPORT void xmlSetOOM()
151     {
152     DEFINE_GS_PROXY //note: ensure GS proxy initialize before any GS member access
153     xmlGlobalStatePtr gs = xeGetTLS();
154     SET_GS_PROXY(gs)
155     // Should be sure that globals state (contains the OOM flag) is initialized
156     if(gs)
157         {
158         OOM_FLAG = 1;
159         }
160     }
161 
xmlResetOOM()162 XMLPUBFUNEXPORT void xmlResetOOM()
163     {
164     DEFINE_GS_PROXY //note: ensure GS proxy initialize before any GS member access
165     xmlGlobalStatePtr gs = xeGetTLS();
166     SET_GS_PROXY(gs)
167     // We need this in case OOM happened during initialization of the 'global state'
168     if (!gs)
169         return;
170     OOM_FLAG = 0;
171     }
172 
173 
174 #define __lookup_ALLOC_ADDRES_  0
175 
176 #ifdef XMLENGINE_MEM_DEBUG
__catchAllocatedAddress()177 void __catchAllocatedAddress()
178     {
179     // Set breakpoint here
180     }
__catchFreedAddress()181 void __catchFreedAddress()
182     {
183     // Set breakpoint here
184     }
185 #endif
186 
187 #ifdef XMLENGINE_MEM_DEBUG
188 //#define XMLENGINE_MEM_DEBUG_SIZE
189 #endif
190 
191 /*
192  NOTE: XMLENGINE_MEM_DEBUG option is defined only in debug builds
193 */
malloc_impl(size_t size)194 XMLPUBFUNEXPORT void* XMLCALL malloc_impl(size_t size)
195 {
196 #ifdef XMLENGINE_MEM_DEBUG
197     LOAD_GS_DIRECT
198 #endif
199 #ifndef XMLENGINE_MEM_DEBUG_SIZE
200     void* mem = malloc(size);
201 
202 #ifdef XMLENGINE_MEM_DEBUG
203     if((int)mem == __lookup_ALLOC_ADDRES_) {
204         __catchAllocatedAddress();
205     }
206 #endif
207 #else
208     // when defined XMLENGINE_MEM_DEBUG_SIZE
209     //
210     // the previous 4 bytes before returned pointer is the size of a block
211     void *hdr;
212     void *mem;
213 
214     hdr = malloc(size + sizeof(size_t));
215     if(hdr)
216     {
217         mem = ((char*)hdr) + sizeof(size_t);
218         *((size_t*)hdr) = size;
219     }
220     else
221         mem = NULL;
222 
223     if((int)hdr == __lookup_ALLOC_ADDRES_) {
224         __catchAllocatedAddress();
225     }
226 #endif
227 
228     if(mem)
229         {
230 #ifdef XMLENGINE_MEM_DEBUG
231         xmlGlobalStatePtr gs = xeGetTLS();
232         if(gs && !xmlOOM) // do not count "after allocations" during error-handling
233             {
234             gs->allocCount++;
235             gs->allocTotal += size;
236 #ifdef XMLENGINE_MEM_DEBUG_SIZE
237             gs->allocMemSize += size;
238             if(gs->allocMemSize > gs->allocMemSizeMax)
239                 gs->allocMemSizeMax = gs->allocMemSize;
240 #endif
241             }
242 #endif
243         return mem;
244         }
245     else
246         {
247         SET_OOM_FLAG;
248         return NULL; // NULL
249         }
250 }
251 
realloc_impl(void * ptr,size_t size)252 XMLPUBFUNEXPORT void* XMLCALL realloc_impl(void *ptr, size_t size)
253 {
254 #ifdef XMLENGINE_MEM_DEBUG
255     LOAD_GS_DIRECT
256 #endif
257 #ifndef XMLENGINE_MEM_DEBUG_SIZE
258     void* mem = realloc(ptr, size);
259 
260 #   ifdef XMLENGINE_MEM_DEBUG
261     if((int)mem == __lookup_ALLOC_ADDRES_) {
262         __catchAllocatedAddress();
263     }
264 #   endif
265 #else
266     // XMLENGINE_MEM_DEBUG_SIZE is defined
267     void* hdr;
268     void* mem;
269     size_t prevSize;
270 
271     hdr = (((size_t*)ptr) - 1);
272     prevSize = *((size_t*)hdr);
273 
274     hdr = realloc(hdr, size + sizeof(size_t));
275     if(hdr)
276     {
277         mem = ((size_t*)hdr) + 1;
278         *((size_t*)hdr) = size;
279     }
280     else
281         mem = NULL;
282 
283     if((int)hdr == __lookup_ALLOC_ADDRES_) {
284         __catchAllocatedAddress();
285     }
286 #endif /* XMLENGINE_MEM_DEBUG_SIZE */
287 
288     if(mem)
289         {
290 #ifdef XMLENGINE_MEM_DEBUG
291         xmlGlobalStatePtr gs = xeGetTLS();
292         if(gs && !xmlOOM) // do not count "after allocations" during error-handling
293             {
294             gs->reallocCount++;
295 #ifdef XMLENGINE_MEM_DEBUG_SIZE
296             gs->allocMemSize += size - prevSize;
297             if(gs->allocMemSize > gs->allocMemSizeMax)
298                 gs->allocMemSizeMax = gs->allocMemSize;
299 #endif
300             }
301 #endif
302         return mem;
303         }
304     else
305         {
306         SET_OOM_FLAG;
307         return NULL;
308         }
309 }
310 
311 //
312 // NOTE: in release builds  free() is used directly
free_debug(void * mem)313 void free_debug(void* mem)
314 {
315 #ifdef XMLENGINE_MEM_DEBUG
316     xmlGlobalStatePtr gs;
317 
318 #ifndef XMLENGINE_MEM_DEBUG_SIZE
319     if((int)mem == __lookup_ALLOC_ADDRES_) {
320         __catchFreedAddress();
321     }
322 
323     free(mem);
324 #else
325     void*  hdr;
326     size_t size;
327 
328     hdr = (((size_t*)mem) - 1);
329 
330     if((int)hdr == __lookup_ALLOC_ADDRES_) {
331         __catchFreedAddress();
332     }
333     size = *((size_t*)hdr);
334     free(hdr);
335 #endif /* XMLENGINE_MEM_DEBUG_SIZE */
336 
337     gs = xeGetTLS();
338     if(gs)
339         {
340         gs->deallocCount++;
341 #ifdef XMLENGINE_MEM_DEBUG_SIZE
342         gs->allocMemSize -=size;
343 #endif
344         }
345 #endif /* XMLENGINE_MEM_DEBUG */
346 }
347 //
348 
349 #ifdef XMLENGINE_EXCLUDE_EMBED_MSG
350 const char* const __embedded_errtxt_replacement = "DISABLED ERROR STRING\n";
351 #endif
352 
xeCleanupDOMStringConverter()353 void xeCleanupDOMStringConverter()
354 {
355     DOMStringConverterData* data = &xmlGetGlobalState()->xeStringArgs;
356     char** buf;
357     int i;
358     for(i=0; i<4; i++){
359         buf = &data->cleanupItem[i];
360         if(*buf){
361             xmlFree(*buf);
362             *buf = 0;
363         }
364     }
365 }
366 
symbian_vsnprintf(char * str,size_t size,const char * format,va_list ap)367 int symbian_vsnprintf(char *str, size_t size, const char *format, va_list ap)
368 {
369     int ret = 0;
370 
371     ret = vsprintf(str, format, ap);
372 
373     assert((size_t)ret < size);
374     return ret;
375 }
376 
symbian_snprintf(char * str,size_t size,const char * format,...)377 int symbian_snprintf(char *str, size_t size, const char *format, ...)
378 {
379     int ret = 0;
380     va_list args;
381     va_start(args, format);
382     symbian_vsnprintf(str, size, format, args);
383     va_end(args);
384 
385     assert((size_t)ret < size);
386 
387     return ret;
388 }
389 
390 #include <libxml2_sax.h>
391 
392 /**
393  * xmlTreeIndentString:
394  *
395  * The string used to do one-level indent. By default is equal to "  " (two spaces)
396  */
397 XMLPUBFUNEXPORT const char* const xmlTreeIndentString = "  ";
398 const char* const xmlTreeIndentStringThrDef = "  ";
399 
400 
401 XMLPUBFUNEXPORT xmlRegisterNodeFunc
xmlRegisterNodeDefault(xmlRegisterNodeFunc func)402 xmlRegisterNodeDefault(xmlRegisterNodeFunc func)
403 {
404 	LOAD_GS_DIRECT
405     xmlRegisterNodeFunc old = xmlRegisterNodeDefaultValue;
406 
407     __xmlRegisterCallbacks = 1;
408     xmlRegisterNodeDefaultValue = func;
409     return(old);
410 }
411 
412 XMLPUBFUNEXPORT xmlDeregisterNodeFunc
xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func)413 xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func)
414 {
415 	LOAD_GS_DIRECT
416     xmlDeregisterNodeFunc old = xmlDeregisterNodeDefaultValue;
417 
418     __xmlRegisterCallbacks = 1;
419     xmlDeregisterNodeDefaultValue = func;
420     return(old);
421 }
422 
423 
424 #define xmlBufferAllocSchemeThrDef XML_BUFFER_ALLOC_EXACT
425 #define xmlDefaultBufferSizeThrDef BASE_BUFFER_SIZE
426 #define xmlParserDebugEntitiesThrDef 0
427 #define xmlDoValidityCheckingDefaultValueThrDef 0
428 #define xmlGetWarningsDefaultValueThrDef 1
429 #define xmlLoadExtDtdDefaultValueThrDef 0
430 #define xmlPedanticParserDefaultValueThrDef 0
431 #define xmlLineNumbersDefaultValueThrDef 0
432 #define xmlKeepBlanksDefaultValueThrDef 1
433 #define xmlSubstituteEntitiesDefaultValueThrDef 0
434 #define xmlRegisterNodeDefaultValueThrDef NULL
435 #define xmlDeregisterNodeDefaultValueThrDef NULL
436 
437 void xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED, const char *msg, ...);
438 
439 #define xmlGenericErrorThrDef  xmlGenericErrorDefaultFunc
440 #define xmlStructuredErrorThrDef  NULL
441 #define xmlGenericErrorContextThrDef NULL
442 #define xmlIndentTreeOutputThrDef 1
443 #define xmlTreeIndentStringThrDef "  "
444 #define xmlSaveNoEmptyTagsThrDef 0
445 
446 #undef  docbDefaultSAXHandler
447 #undef  htmlDefaultSAXHandler
448 #undef  xmlBufferAllocScheme
449 #undef  xmlDefaultBufferSize
450 #undef  xmlDefaultSAXHandler
451 #undef  xmlDefaultSAXLocator
452 #undef  xmlDoValidityCheckingDefaultValue
453 #undef  xmlGenericError
454 #undef  xmlStructuredError
455 #undef  xmlGenericErrorContext
456 #undef  xmlGetWarningsDefaultValue
457 #undef  xmlIndentTreeOutput
458 //#undef  xmlTreeIndentString
459 #undef  xmlKeepBlanksDefaultValue
460 #undef  xmlLineNumbersDefaultValue
461 #undef  xmlLoadExtDtdDefaultValue
462 #undef  xmlParserDebugEntities
463 #undef  xmlPedanticParserDefaultValue
464 #undef  xmlSaveNoEmptyTags
465 #undef  xmlSubstituteEntitiesDefaultValue
466 #undef  xmlRegisterNodeDefaultValue
467 #undef  xmlDeregisterNodeDefaultValue
468 #undef  xmlLastError
469 
470 #undef  xmlFree
471 #undef  xmlMalloc
472 #undef  xmlMallocAtomic
473 #undef  xmlMemStrdup
474 #undef  xmlRealloc
475 
476 /* html */
477 #undef  htmlStartCloseIndex
478 #undef  htmlStartCloseIndexinitialized
479 
480 /* tree */
481 #undef __xmlRegisterCallbacks
482 #undef xmlCompressMode
483 #undef xmlCheckDTD
484 
485 /* xmlmemory */
486 #undef xmlMemInitialized
487 #undef debugMemSize
488 #undef debugMaxMemSize
489 #undef xmlMemMutex
490 #undef g_block
491 #undef xmlMemStopAtBlock
492 #undef xmlMemTraceBlockAt
493 
494 /* catalog */
495 #undef  xmlDebugCatalogs
496 #undef  xmlCatalogDefaultAllow
497 #undef  xmlCatalogDefaultPrefer
498 #undef  xmlCatalogXMLFiles
499 #undef  xmlDefaultCatalog
500 #undef  xmlCatalogMutex
501 #undef  xmlCatalogInitialized
502 
503 #undef  xmlInputCallbackTable
504 #undef  xmlInputCallbackNr
505 #undef  xmlInputCallbackInitialized
506 #undef  xmlOutputCallbackTable
507 #undef  xmlOutputCallbackNr
508 #undef  xmlOutputCallbackInitialized
509 #undef xmlCurrentExternalEntityLoader
510 
511 #undef xmlSAX2DefaultVersionValue
512 
513 #undef xmlParserMaxDepth
514 #undef xmlW3CPIs
515 #undef xmlParserInitialized
516 #undef xeStackLimit
517 // Now these are global constants
518 //#undef xmlEntityLt
519 //#undef xmlEntityGt
520 //#undef xmlEntityAmp
521 //#undef xmlEntityQuot
522 //#undef xmlEntityApos
523 
524 #undef xmlUTF16LEHandler
525 #undef xmlUTF16BEHandler
526 #undef xmlCharEncodingAliases
527 #undef xmlCharEncodingAliasesNb
528 #undef xmlCharEncodingAliasesMax
529 #undef xmlLittleEndian
530 #undef handlers
531 #undef nbCharEncodingHandler
532 #undef xmlDefaultCharEncodingHandler
533 
534 #undef xmlXPathNAN
535 #undef xmlXPathPINF
536 #undef xmlXPathNINF
537 #undef xmlXPathNZERO
538 #undef xmlXPathInitialized
539 
540 #ifndef LIBXML_THREAD_ENABLED
541 #   undef xmlXPathDisableOptimizer
542 #endif
543 
544 #undef xmlXPathDefineExtensionFunctionsGlobally
545 #undef xmlXPathDefaultFunctionsHash
546 #undef xmlXPathIntermediaryExtensionFunctionsHash
547 
548 #undef xlinkDefaultHandler
549 #undef xlinkDefaultDetect
550 
551 #undef had_info
552 #undef xmlInputStreamId
553 
554 #undef xeUserCount
555 
556 /* XMLENGINE_XSLT */
557 #undef g_calibration
558 //#undef default_token
559 #undef xsltExtensionsHash
560 #undef xsltFunctionsHash
561 #undef xsltElementsHash
562 #undef xsltGlobalsCleanupFunc
563 #undef xsltTopLevelsHash
564 #undef xsltDebuggerCurrentCallbacks
565 
566 #ifdef LIBXML_SAX1_ENABLED
567 /**
568  * xmlDefaultSAXHandler:
569  *
570  * Default SAX version1 handler for XML, builds the DOM tree
571  */
572 const xmlSAXHandlerV1 xmlDefaultSAXHandler = {
573     xmlSAX2InternalSubset,
574     xmlSAX2IsStandalone,
575     xmlSAX2HasInternalSubset,
576     xmlSAX2HasExternalSubset,
577     xmlSAX2ResolveEntity,
578     xmlSAX2GetEntity,
579     xmlSAX2EntityDecl,
580     xmlSAX2NotationDecl,
581     xmlSAX2AttributeDecl,
582     xmlSAX2ElementDecl,
583     xmlSAX2UnparsedEntityDecl,
584     xmlSAX2SetDocumentLocator,
585     xmlSAX2StartDocument,
586     xmlSAX2EndDocument,
587     xmlSAX2StartElement,
588     xmlSAX2EndElement,
589     xmlSAX2Reference,
590     xmlSAX2Characters,
591     xmlSAX2Characters,
592     xmlSAX2ProcessingInstruction,
593     xmlSAX2Comment,
594     xmlParserWarning,
595     xmlParserError,
596     xmlParserError,
597     xmlSAX2GetParameterEntity,
598     xmlSAX2CDataBlock,
599     xmlSAX2ExternalSubset,
600     0,
601 };
602 #endif /* LIBXML_SAX1_ENABLED */
603 
604 /**
605  * xmlDefaultSAXLocator:
606  *
607  * The default SAX Locator
608  * { getPublicId, getSystemId, getLineNumber, getColumnNumber}
609  */
610 const xmlSAXLocator xmlDefaultSAXLocator = {
611     xmlSAX2GetPublicId,
612     xmlSAX2GetSystemId,
613     xmlSAX2GetLineNumber,
614     xmlSAX2GetColumnNumber
615 };
616 
617 #ifdef LIBXML_HTML_ENABLED
618 /**
619  * htmlDefaultSAXHandler:
620  *
621  * Default old SAX v1 handler for HTML, builds the DOM tree
622  */
623 const xmlSAXHandlerV1 htmlDefaultSAXHandler = {
624     xmlSAX2InternalSubset,
625     NULL,
626     NULL,
627     NULL,
628     NULL,
629     xmlSAX2GetEntity,
630     NULL,
631     NULL,
632     NULL,
633     NULL,
634     NULL,
635     xmlSAX2SetDocumentLocator,
636     xmlSAX2StartDocument,
637     xmlSAX2EndDocument,
638     xmlSAX2StartElement,
639     xmlSAX2EndElement,
640     NULL,
641     xmlSAX2Characters,
642     xmlSAX2IgnorableWhitespace,
643     NULL,
644     xmlSAX2Comment,
645     xmlParserWarning,
646     xmlParserError,
647     xmlParserError,
648     xmlSAX2GetParameterEntity,
649     xmlSAX2CDataBlock,
650     NULL,
651     0,
652 };
653 #endif /* LIBXML_HTML_ENABLED */
654 
655 #ifdef LIBXML_DOCB_ENABLED
656 /**
657  * docbDefaultSAXHandler:
658  *
659  * Default old SAX v1 handler for SGML DocBook, builds the DOM tree
660  */
661 const xmlSAXHandlerV1 docbDefaultSAXHandler = {
662     xmlSAX2InternalSubset,
663     xmlSAX2IsStandalone,
664     xmlSAX2HasInternalSubset,
665     xmlSAX2HasExternalSubset,
666     xmlSAX2ResolveEntity,
667     xmlSAX2GetEntity,
668     xmlSAX2EntityDecl,
669     NULL,
670     NULL,
671     NULL,
672     NULL,
673     xmlSAX2SetDocumentLocator,
674     xmlSAX2StartDocument,
675     xmlSAX2EndDocument,
676     xmlSAX2StartElement,
677     xmlSAX2EndElement,
678     xmlSAX2Reference,
679     xmlSAX2Characters,
680     xmlSAX2IgnorableWhitespace,
681     NULL,
682     xmlSAX2Comment,
683     xmlParserWarning,
684     xmlParserError,
685     xmlParserError,
686     xmlSAX2GetParameterEntity,
687     NULL,
688     NULL,
689     0,
690 };
691 #endif /* LIBXML_DOCB_ENABLED */
692 
693 
694 
695 /**
696  * xmlInitializeGlobalState:
697  * @param gs a pointer to a newly allocated global state
698  *
699  * xmlInitializeGlobalState() initialize a global state with all the
700  * default values of the library.
701  */
702 XMLPUBFUNEXPORT void
xmlInitializeGlobalState(xmlGlobalStatePtr gs)703 xmlInitializeGlobalState(xmlGlobalStatePtr gs)
704 {
705 
706 #ifdef DEBUG_GLOBALS
707     fprintf(stderr, "Initializing globals at %lu for thread %d\n",
708         (unsigned long) gs, xmlGetThreadId());
709 #endif
710 
711     /*
712      * Perform initialization as required by libxml
713      */
714     if (xmlThrDefMutex == NULL)
715         xmlInitGlobals();
716 
717     xmlMutexLock(xmlThrDefMutex);
718 
719 #ifdef LIBXML_DOCB_ENABLED
720     xmlSAX2InitDocbDefaultSAXHandler(&gs->docbDefaultSAXHandler);
721 #endif
722 #ifdef LIBXML_HTML_ENABLED
723 
724     //xmlSAX2InitHtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler);
725 #endif
726 // merge: agathe: I had removed this code for libxslt...
727 //#ifdef LIBXML_DOCB_ENABLED
728 //    initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler);
729 //#endif
730 
731 //#ifdef LIBXML_HTML_ENABLED
732     //inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler);
733 //#endif
734 
735     gs->xmlBufferAllocScheme = xmlBufferAllocSchemeThrDef;
736     gs->xmlDefaultBufferSize = xmlDefaultBufferSizeThrDef;
737 #ifdef LIBXML_SAX1_ENABLED
738     initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
739 #endif /* LIBXML_SAX1_ENABLED */
740     gs->xmlDefaultSAXLocator.getPublicId = xmlSAX2GetPublicId;
741     gs->xmlDefaultSAXLocator.getSystemId = xmlSAX2GetSystemId;
742     gs->xmlDefaultSAXLocator.getLineNumber = xmlSAX2GetLineNumber;
743     gs->xmlDefaultSAXLocator.getColumnNumber = xmlSAX2GetColumnNumber;
744     gs->xmlDoValidityCheckingDefaultValue = xmlDoValidityCheckingDefaultValueThrDef;
745 
746     gs->xeStackLimit = xeStackLimitAddress();
747 
748     gs->xmlGetWarningsDefaultValue = xmlGetWarningsDefaultValueThrDef;
749     gs->xmlIndentTreeOutput = xmlIndentTreeOutputThrDef;
750 
751     gs->xmlKeepBlanksDefaultValue = xmlKeepBlanksDefaultValueThrDef;
752 #ifdef LIBXML_ENABLE_NODE_LINEINFO
753     gs->xmlLineNumbersDefaultValue = xmlLineNumbersDefaultValueThrDef;
754 #endif
755     gs->xmlLoadExtDtdDefaultValue = xmlLoadExtDtdDefaultValueThrDef;
756     gs->xmlParserDebugEntities = xmlParserDebugEntitiesThrDef;
757     gs->xmlPedanticParserDefaultValue = xmlPedanticParserDefaultValueThrDef;
758     gs->xmlSaveNoEmptyTags = xmlSaveNoEmptyTagsThrDef;
759     gs->xmlSubstituteEntitiesDefaultValue = xmlSubstituteEntitiesDefaultValueThrDef;
760 
761     gs->xmlGenericError = xmlGenericErrorThrDef;
762     gs->xmlStructuredError = xmlStructuredErrorThrDef;
763     gs->xmlGenericErrorContext = xmlGenericErrorContextThrDef;
764     gs->xmlRegisterNodeDefaultValue = xmlRegisterNodeDefaultValueThrDef;
765     gs->xmlDeregisterNodeDefaultValue = xmlDeregisterNodeDefaultValueThrDef;
766     memset(&gs->xmlLastError, 0, sizeof(xmlError));
767 
768 // ==================================================
769 // XMLENEGINE: NOTE: All zero values are commented,
770 //  since the whole structure is set to zeros prior
771 //  initialization
772 // ==================================================
773 
774 //  gs->had_info = 0;
775 
776 //  gs->xmlInputStreamId = 0;
777 
778 //  gs->xmlUTF16LEHandler = NULL;
779 //  gs->xmlUTF16BEHandler = NULL;
780 //  gs->xmlCharEncodingAliases = NULL;
781 //  gs->xmlCharEncodingAliasesNb = 0;
782 //  gs->xmlCharEncodingAliasesMax = 0;
783     gs->xmlLittleEndian = 1;
784 //  gs->handlers = NULL;
785 //  gs->nbCharEncodingHandler = 0;
786 //  gs->xmlDefaultCharEncodingHandler = NULL;
787 
788     gs->xmlParserMaxDepth = 1024;
789     gs->xmlW3CPIs[0] = "xml-stylesheet";
790     gs->xmlW3CPIs[1] = NULL;
791 //  gs->xmlParserInitialized = 0;
792 
793     gs->xmlSAX2DefaultVersionValue = 2;
794 
795 //  gs->xmlInputCallbackNr = 0;
796 //  gs->xmlInputCallbackInitialized = 0;
797 
798 #ifdef LIBXML_OUTPUT_ENABLED
799 //  gs->xmlOutputCallbackNr = 0;
800 //  gs->xmlOutputCallbackInitialized = 0;
801 #endif /* LIBXML_OUTPUT_ENABLED*/
802 
803     gs->xmlCurrentExternalEntityLoader = xmlDefaultExternalEntityLoader;
804 
805 //  gs->xmlMemInitialized = 0;
806 //  gs->debugMemSize = 0;
807 //  gs->debugMaxMemSize = 0;
808 //  gs->xmlMemMutex = NULL;
809 //  gs->block = 0;
810 //  gs->xmlMemStopAtBlock = 0;
811 //  gs->xmlMemTraceBlockAt = NULL;
812 
813 //#ifdef LIBXML_TREE_ENABLED
814 //  gs->__xmlRegisterCallbacks = 0;
815 //#endif
816 #ifdef LIBXML_TREE_ENABLED
817 
818 //  gs->xmlCompressMode = 0;
819     gs->xmlCheckDTD = 1;
820 #endif
821 
822 #ifdef LIBXML_CATALOG_ENABLED
823 //  gs->xmlDebugCatalogs = 0;
824     gs->xmlCatalogDefaultAllow = XML_CATA_ALLOW_ALL;
825     gs->xmlCatalogDefaultPrefer = XML_CATA_PREFER_PUBLIC;
826 //  gs->xmlCatalogXMLFiles = NULL;
827 //  gs->xmlDefaultCatalog = NULL;
828 //  xmlCatalogMutex = NULL;
829 //  gs->xmlCatalogInitialized = 0;
830 #endif
831 
832 #ifdef LIBXML_XPATH_ENABLED
833 //  gs->xmlXPathNAN = 0;
834     gs->xmlXPathPINF = 1;
835     gs->xmlXPathNINF = -1;
836 //  gs->xmlXPathNZERO = 0;
837 //  gs->xmlXPathInitialized = 0;
838 #ifndef LIBXML_THREAD_ENABLED
839 //  gs->xmlXPathDisableOptimizer = 0;
840 #endif
841     gs->xmlXPathDefineExtensionFunctionsGlobally = 1;
842 //  gs->xmlXPathDefaultFunctionsHash = NULL;
843 //  gs->xmlXPathIntermediaryExtensionFunctionsHash = NULL;
844 #endif /* LIBXML_XPATH_ENABLED */
845 
846 #ifdef LIBXML_XPTR_ENABLED
847 //  gs->xlinkDefaultHandler = NULL;
848 //  gs->xlinkDefaultDetect = NULL;
849 #endif
850 
851     xmlMutexUnlock(xmlThrDefMutex);
852 
853     // gs->xmlOOM = gs->xeUserCount = 0; //
854 }
855