1 /*
2  * 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  */
13 
14 #define IN_LIBXML
15 #include "libxml.h"
16 
17 #ifdef HAVE_STDLIB_H
18 #include <stdlib.h>
19 #endif
20 #include <string.h>
21 
22 #include <libxml/globals.h>
23 #include <libxml/xmlmemory.h>
24 #include <libxml/threads.h>
25 
26 /* #define DEBUG_GLOBALS */
27 
28 /*
29  * Helpful Macro
30  */
31 #ifdef LIBXML_THREAD_ENABLED
32 #define IS_MAIN_THREAD (xmlIsMainThread())
33 #else
34 #define IS_MAIN_THREAD 1
35 #endif
36 
37 /*
38  * Mutex to protect "ForNewThreads" variables
39  */
40 static xmlMutexPtr xmlThrDefMutex = NULL;
41 
42 /**
43  * xmlInitGlobals:
44  *
45  * Additional initialisation for multi-threading
46  */
xmlInitGlobals(void)47 void xmlInitGlobals(void)
48 {
49     if (xmlThrDefMutex == NULL)
50         xmlThrDefMutex = xmlNewMutex();
51 }
52 
53 /**
54  * xmlCleanupGlobals:
55  *
56  * Additional cleanup for multi-threading
57  */
xmlCleanupGlobals(void)58 void xmlCleanupGlobals(void)
59 {
60     if (xmlThrDefMutex != NULL) {
61 	xmlFreeMutex(xmlThrDefMutex);
62 	xmlThrDefMutex = NULL;
63     }
64     __xmlGlobalInitMutexDestroy();
65 }
66 
67 /************************************************************************
68  *									*
69  *	All the user accessible global variables of the library		*
70  *									*
71  ************************************************************************/
72 
73 /*
74  * Memory allocation routines
75  */
76 #undef	xmlFree
77 #undef	xmlMalloc
78 #undef	xmlMallocAtomic
79 #undef	xmlMemStrdup
80 #undef	xmlRealloc
81 
82 #if defined(DEBUG_MEMORY_LOCATION) || defined(DEBUG_MEMORY)
83 xmlFreeFunc xmlFree = (xmlFreeFunc) xmlMemFree;
84 xmlMallocFunc xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
85 xmlMallocFunc xmlMallocAtomic = (xmlMallocFunc) xmlMemMalloc;
86 xmlReallocFunc xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
87 xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
88 #else
89 /**
90  * xmlFree:
91  * @mem: an already allocated block of memory
92  *
93  * The variable holding the libxml free() implementation
94  */
95 xmlFreeFunc xmlFree = free;
96 /**
97  * xmlMalloc:
98  * @size:  the size requested in bytes
99  *
100  * The variable holding the libxml malloc() implementation
101  *
102  * Returns a pointer to the newly allocated block or NULL in case of error
103  */
104 xmlMallocFunc xmlMalloc = malloc;
105 /**
106  * xmlMallocAtomic:
107  * @size:  the size requested in bytes
108  *
109  * The variable holding the libxml malloc() implementation for atomic
110  * data (i.e. blocks not containing pointers), useful when using a
111  * garbage collecting allocator.
112  *
113  * Returns a pointer to the newly allocated block or NULL in case of error
114  */
115 xmlMallocFunc xmlMallocAtomic = malloc;
116 /**
117  * xmlRealloc:
118  * @mem: an already allocated block of memory
119  * @size:  the new size requested in bytes
120  *
121  * The variable holding the libxml realloc() implementation
122  *
123  * Returns a pointer to the newly reallocated block or NULL in case of error
124  */
125 xmlReallocFunc xmlRealloc = realloc;
126 /**
127  * xmlPosixStrdup
128  * @cur:  the input char *
129  *
130  * a strdup implementation with a type signature matching POSIX
131  *
132  * Returns a new xmlChar * or NULL
133  */
134 static char *
xmlPosixStrdup(const char * cur)135 xmlPosixStrdup(const char *cur) {
136     return((char*) xmlCharStrdup(cur));
137 }
138 /**
139  * xmlMemStrdup:
140  * @str: a zero terminated string
141  *
142  * The variable holding the libxml strdup() implementation
143  *
144  * Returns the copy of the string or NULL in case of error
145  */
146 xmlStrdupFunc xmlMemStrdup = xmlPosixStrdup;
147 #endif /* DEBUG_MEMORY_LOCATION || DEBUG_MEMORY */
148 
149 #include <libxml/threads.h>
150 #include <libxml/globals.h>
151 #include <libxml/SAX.h>
152 
153 #undef	docbDefaultSAXHandler
154 #undef	htmlDefaultSAXHandler
155 #undef	oldXMLWDcompatibility
156 #undef	xmlBufferAllocScheme
157 #undef	xmlDefaultBufferSize
158 #undef	xmlDefaultSAXHandler
159 #undef	xmlDefaultSAXLocator
160 #undef	xmlDoValidityCheckingDefaultValue
161 #undef	xmlGenericError
162 #undef	xmlStructuredError
163 #undef	xmlGenericErrorContext
164 #undef	xmlStructuredErrorContext
165 #undef	xmlGetWarningsDefaultValue
166 #undef	xmlIndentTreeOutput
167 #undef  xmlTreeIndentString
168 #undef	xmlKeepBlanksDefaultValue
169 #undef	xmlLineNumbersDefaultValue
170 #undef	xmlLoadExtDtdDefaultValue
171 #undef	xmlParserDebugEntities
172 #undef	xmlParserVersion
173 #undef	xmlPedanticParserDefaultValue
174 #undef	xmlSaveNoEmptyTags
175 #undef	xmlSubstituteEntitiesDefaultValue
176 #undef	xmlRegisterNodeDefaultValue
177 #undef	xmlDeregisterNodeDefaultValue
178 #undef	xmlLastError
179 
180 #undef  xmlParserInputBufferCreateFilenameValue
181 #undef  xmlOutputBufferCreateFilenameValue
182 /**
183  * xmlParserVersion:
184  *
185  * Constant string describing the internal version of the library
186  */
187 const char *xmlParserVersion = LIBXML_VERSION_STRING LIBXML_VERSION_EXTRA;
188 
189 /**
190  * xmlBufferAllocScheme:
191  *
192  * Global setting, default allocation policy for buffers, default is
193  * XML_BUFFER_ALLOC_EXACT
194  */
195 xmlBufferAllocationScheme xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
196 static xmlBufferAllocationScheme xmlBufferAllocSchemeThrDef = XML_BUFFER_ALLOC_EXACT;
197 /**
198  * xmlDefaultBufferSize:
199  *
200  * Global setting, default buffer size. Default value is BASE_BUFFER_SIZE
201  */
202 int xmlDefaultBufferSize = BASE_BUFFER_SIZE;
203 static int xmlDefaultBufferSizeThrDef = BASE_BUFFER_SIZE;
204 
205 /*
206  * Parser defaults
207  */
208 
209 /**
210  * oldXMLWDcompatibility:
211  *
212  * Global setting, DEPRECATED.
213  */
214 int oldXMLWDcompatibility = 0; /* DEPRECATED */
215 /**
216  * xmlParserDebugEntities:
217  *
218  * Global setting, asking the parser to print out debugging information.
219  * while handling entities.
220  * Disabled by default
221  */
222 int xmlParserDebugEntities = 0;
223 static int xmlParserDebugEntitiesThrDef = 0;
224 /**
225  * xmlDoValidityCheckingDefaultValue:
226  *
227  * Global setting, indicate that the parser should work in validating mode.
228  * Disabled by default.
229  */
230 int xmlDoValidityCheckingDefaultValue = 0;
231 static int xmlDoValidityCheckingDefaultValueThrDef = 0;
232 /**
233  * xmlGetWarningsDefaultValue:
234  *
235  * Global setting, indicate that the parser should provide warnings.
236  * Activated by default.
237  */
238 int xmlGetWarningsDefaultValue = 1;
239 static int xmlGetWarningsDefaultValueThrDef = 1;
240 /**
241  * xmlLoadExtDtdDefaultValue:
242  *
243  * Global setting, indicate that the parser should load DTD while not
244  * validating.
245  * Disabled by default.
246  */
247 int xmlLoadExtDtdDefaultValue = 0;
248 static int xmlLoadExtDtdDefaultValueThrDef = 0;
249 /**
250  * xmlPedanticParserDefaultValue:
251  *
252  * Global setting, indicate that the parser be pedantic
253  * Disabled by default.
254  */
255 int xmlPedanticParserDefaultValue = 0;
256 static int xmlPedanticParserDefaultValueThrDef = 0;
257 /**
258  * xmlLineNumbersDefaultValue:
259  *
260  * Global setting, indicate that the parser should store the line number
261  * in the content field of elements in the DOM tree.
262  * Disabled by default since this may not be safe for old classes of
263  * application.
264  */
265 int xmlLineNumbersDefaultValue = 0;
266 static int xmlLineNumbersDefaultValueThrDef = 0;
267 /**
268  * xmlKeepBlanksDefaultValue:
269  *
270  * Global setting, indicate that the parser should keep all blanks
271  * nodes found in the content
272  * Activated by default, this is actually needed to have the parser
273  * conformant to the XML Recommendation, however the option is kept
274  * for some applications since this was libxml1 default behaviour.
275  */
276 int xmlKeepBlanksDefaultValue = 1;
277 static int xmlKeepBlanksDefaultValueThrDef = 1;
278 /**
279  * xmlSubstituteEntitiesDefaultValue:
280  *
281  * Global setting, indicate that the parser should not generate entity
282  * references but replace them with the actual content of the entity
283  * Disabled by default, this should be activated when using XPath since
284  * the XPath data model requires entities replacement and the XPath
285  * engine does not handle entities references transparently.
286  */
287 int xmlSubstituteEntitiesDefaultValue = 0;
288 static int xmlSubstituteEntitiesDefaultValueThrDef = 0;
289 
290 xmlRegisterNodeFunc xmlRegisterNodeDefaultValue = NULL;
291 static xmlRegisterNodeFunc xmlRegisterNodeDefaultValueThrDef = NULL;
292 xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue = NULL;
293 static xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValueThrDef = NULL;
294 
295 xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue = NULL;
296 static xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValueThrDef = NULL;
297 
298 xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue = NULL;
299 static xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValueThrDef = NULL;
300 
301 /*
302  * Error handling
303  */
304 
305 /* xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc; */
306 /* Must initialize xmlGenericError in xmlInitParser */
307 void XMLCDECL xmlGenericErrorDefaultFunc	(void *ctx ATTRIBUTE_UNUSED,
308 				 const char *msg,
309 				 ...);
310 /**
311  * xmlGenericError:
312  *
313  * Global setting: function used for generic error callbacks
314  */
315 xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc;
316 static xmlGenericErrorFunc xmlGenericErrorThrDef = xmlGenericErrorDefaultFunc;
317 /**
318  * xmlStructuredError:
319  *
320  * Global setting: function used for structured error callbacks
321  */
322 xmlStructuredErrorFunc xmlStructuredError = NULL;
323 static xmlStructuredErrorFunc xmlStructuredErrorThrDef = NULL;
324 /**
325  * xmlGenericErrorContext:
326  *
327  * Global setting passed to generic error callbacks
328  */
329 void *xmlGenericErrorContext = NULL;
330 static void *xmlGenericErrorContextThrDef = NULL;
331 /**
332  * xmlStructuredErrorContext:
333  *
334  * Global setting passed to structured error callbacks
335  */
336 void *xmlStructuredErrorContext = NULL;
337 static void *xmlStructuredErrorContextThrDef = NULL;
338 xmlError xmlLastError;
339 
340 /*
341  * output defaults
342  */
343 /**
344  * xmlIndentTreeOutput:
345  *
346  * Global setting, asking the serializer to indent the output tree by default
347  * Enabled by default
348  */
349 int xmlIndentTreeOutput = 1;
350 static int xmlIndentTreeOutputThrDef = 1;
351 
352 /**
353  * xmlTreeIndentString:
354  *
355  * The string used to do one-level indent. By default is equal to "  " (two spaces)
356  */
357 const char *xmlTreeIndentString = "  ";
358 static const char *xmlTreeIndentStringThrDef = "  ";
359 
360 /**
361  * xmlSaveNoEmptyTags:
362  *
363  * Global setting, asking the serializer to not output empty tags
364  * as <empty/> but <empty></empty>. those two forms are indistinguishable
365  * once parsed.
366  * Disabled by default
367  */
368 int xmlSaveNoEmptyTags = 0;
369 static int xmlSaveNoEmptyTagsThrDef = 0;
370 
371 #ifdef LIBXML_SAX1_ENABLED
372 /**
373  * xmlDefaultSAXHandler:
374  *
375  * Default SAX version1 handler for XML, builds the DOM tree
376  */
377 xmlSAXHandlerV1 xmlDefaultSAXHandler = {
378     xmlSAX2InternalSubset,
379     xmlSAX2IsStandalone,
380     xmlSAX2HasInternalSubset,
381     xmlSAX2HasExternalSubset,
382     xmlSAX2ResolveEntity,
383     xmlSAX2GetEntity,
384     xmlSAX2EntityDecl,
385     xmlSAX2NotationDecl,
386     xmlSAX2AttributeDecl,
387     xmlSAX2ElementDecl,
388     xmlSAX2UnparsedEntityDecl,
389     xmlSAX2SetDocumentLocator,
390     xmlSAX2StartDocument,
391     xmlSAX2EndDocument,
392     xmlSAX2StartElement,
393     xmlSAX2EndElement,
394     xmlSAX2Reference,
395     xmlSAX2Characters,
396     xmlSAX2Characters,
397     xmlSAX2ProcessingInstruction,
398     xmlSAX2Comment,
399     xmlParserWarning,
400     xmlParserError,
401     xmlParserError,
402     xmlSAX2GetParameterEntity,
403     xmlSAX2CDataBlock,
404     xmlSAX2ExternalSubset,
405     0,
406 };
407 #endif /* LIBXML_SAX1_ENABLED */
408 
409 /**
410  * xmlDefaultSAXLocator:
411  *
412  * The default SAX Locator
413  * { getPublicId, getSystemId, getLineNumber, getColumnNumber}
414  */
415 xmlSAXLocator xmlDefaultSAXLocator = {
416     xmlSAX2GetPublicId,
417     xmlSAX2GetSystemId,
418     xmlSAX2GetLineNumber,
419     xmlSAX2GetColumnNumber
420 };
421 
422 #ifdef LIBXML_HTML_ENABLED
423 /**
424  * htmlDefaultSAXHandler:
425  *
426  * Default old SAX v1 handler for HTML, builds the DOM tree
427  */
428 xmlSAXHandlerV1 htmlDefaultSAXHandler = {
429     xmlSAX2InternalSubset,
430     NULL,
431     NULL,
432     NULL,
433     NULL,
434     xmlSAX2GetEntity,
435     NULL,
436     NULL,
437     NULL,
438     NULL,
439     NULL,
440     xmlSAX2SetDocumentLocator,
441     xmlSAX2StartDocument,
442     xmlSAX2EndDocument,
443     xmlSAX2StartElement,
444     xmlSAX2EndElement,
445     NULL,
446     xmlSAX2Characters,
447     xmlSAX2IgnorableWhitespace,
448     xmlSAX2ProcessingInstruction,
449     xmlSAX2Comment,
450     xmlParserWarning,
451     xmlParserError,
452     xmlParserError,
453     xmlSAX2GetParameterEntity,
454     xmlSAX2CDataBlock,
455     NULL,
456     0,
457 };
458 #endif /* LIBXML_HTML_ENABLED */
459 
460 #ifdef LIBXML_DOCB_ENABLED
461 /**
462  * docbDefaultSAXHandler:
463  *
464  * Default old SAX v1 handler for SGML DocBook, builds the DOM tree
465  */
466 xmlSAXHandlerV1 docbDefaultSAXHandler = {
467     xmlSAX2InternalSubset,
468     xmlSAX2IsStandalone,
469     xmlSAX2HasInternalSubset,
470     xmlSAX2HasExternalSubset,
471     xmlSAX2ResolveEntity,
472     xmlSAX2GetEntity,
473     xmlSAX2EntityDecl,
474     NULL,
475     NULL,
476     NULL,
477     NULL,
478     xmlSAX2SetDocumentLocator,
479     xmlSAX2StartDocument,
480     xmlSAX2EndDocument,
481     xmlSAX2StartElement,
482     xmlSAX2EndElement,
483     xmlSAX2Reference,
484     xmlSAX2Characters,
485     xmlSAX2IgnorableWhitespace,
486     NULL,
487     xmlSAX2Comment,
488     xmlParserWarning,
489     xmlParserError,
490     xmlParserError,
491     xmlSAX2GetParameterEntity,
492     NULL,
493     NULL,
494     0,
495 };
496 #endif /* LIBXML_DOCB_ENABLED */
497 
498 /**
499  * xmlInitializeGlobalState:
500  * @gs: a pointer to a newly allocated global state
501  *
502  * xmlInitializeGlobalState() initialize a global state with all the
503  * default values of the library.
504  */
505 void
xmlInitializeGlobalState(xmlGlobalStatePtr gs)506 xmlInitializeGlobalState(xmlGlobalStatePtr gs)
507 {
508 #ifdef DEBUG_GLOBALS
509     fprintf(stderr, "Initializing globals at %lu for thread %d\n",
510 	    (unsigned long) gs, xmlGetThreadId());
511 #endif
512 
513     /*
514      * Perform initialization as required by libxml
515      */
516     if (xmlThrDefMutex == NULL)
517         xmlInitGlobals();
518 
519     xmlMutexLock(xmlThrDefMutex);
520 
521 #if defined(LIBXML_DOCB_ENABLED) && defined(LIBXML_LEGACY_ENABLED) && defined(LIBXML_SAX1_ENABLED)
522     initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler);
523 #endif
524 #if defined(LIBXML_HTML_ENABLED) && defined(LIBXML_LEGACY_ENABLED) && defined(LIBXML_SAX1_ENABLED)
525     inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler);
526 #endif
527 
528     gs->oldXMLWDcompatibility = 0;
529     gs->xmlBufferAllocScheme = xmlBufferAllocSchemeThrDef;
530     gs->xmlDefaultBufferSize = xmlDefaultBufferSizeThrDef;
531 #if defined(LIBXML_SAX1_ENABLED) && defined(LIBXML_LEGACY_ENABLED)
532     initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
533 #endif /* LIBXML_SAX1_ENABLED */
534     gs->xmlDefaultSAXLocator.getPublicId = xmlSAX2GetPublicId;
535     gs->xmlDefaultSAXLocator.getSystemId = xmlSAX2GetSystemId;
536     gs->xmlDefaultSAXLocator.getLineNumber = xmlSAX2GetLineNumber;
537     gs->xmlDefaultSAXLocator.getColumnNumber = xmlSAX2GetColumnNumber;
538     gs->xmlDoValidityCheckingDefaultValue =
539          xmlDoValidityCheckingDefaultValueThrDef;
540 #if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
541     gs->xmlFree = (xmlFreeFunc) xmlMemFree;
542     gs->xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
543     gs->xmlMallocAtomic = (xmlMallocFunc) xmlMemMalloc;
544     gs->xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
545     gs->xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
546 #else
547     gs->xmlFree = (xmlFreeFunc) free;
548     gs->xmlMalloc = (xmlMallocFunc) malloc;
549     gs->xmlMallocAtomic = (xmlMallocFunc) malloc;
550     gs->xmlRealloc = (xmlReallocFunc) realloc;
551     gs->xmlMemStrdup = (xmlStrdupFunc) xmlStrdup;
552 #endif
553     gs->xmlGetWarningsDefaultValue = xmlGetWarningsDefaultValueThrDef;
554     gs->xmlIndentTreeOutput = xmlIndentTreeOutputThrDef;
555     gs->xmlTreeIndentString = xmlTreeIndentStringThrDef;
556     gs->xmlKeepBlanksDefaultValue = xmlKeepBlanksDefaultValueThrDef;
557     gs->xmlLineNumbersDefaultValue = xmlLineNumbersDefaultValueThrDef;
558     gs->xmlLoadExtDtdDefaultValue = xmlLoadExtDtdDefaultValueThrDef;
559     gs->xmlParserDebugEntities = xmlParserDebugEntitiesThrDef;
560     gs->xmlParserVersion = LIBXML_VERSION_STRING;
561     gs->xmlPedanticParserDefaultValue = xmlPedanticParserDefaultValueThrDef;
562     gs->xmlSaveNoEmptyTags = xmlSaveNoEmptyTagsThrDef;
563     gs->xmlSubstituteEntitiesDefaultValue =
564         xmlSubstituteEntitiesDefaultValueThrDef;
565 
566     gs->xmlGenericError = xmlGenericErrorThrDef;
567     gs->xmlStructuredError = xmlStructuredErrorThrDef;
568     gs->xmlGenericErrorContext = xmlGenericErrorContextThrDef;
569     gs->xmlStructuredErrorContext = xmlStructuredErrorContextThrDef;
570     gs->xmlRegisterNodeDefaultValue = xmlRegisterNodeDefaultValueThrDef;
571     gs->xmlDeregisterNodeDefaultValue = xmlDeregisterNodeDefaultValueThrDef;
572 
573 	gs->xmlParserInputBufferCreateFilenameValue = xmlParserInputBufferCreateFilenameValueThrDef;
574 	gs->xmlOutputBufferCreateFilenameValue = xmlOutputBufferCreateFilenameValueThrDef;
575     memset(&gs->xmlLastError, 0, sizeof(xmlError));
576 
577     xmlMutexUnlock(xmlThrDefMutex);
578 }
579 
580 /**
581  * DOC_DISABLE : we ignore missing doc for the xmlThrDef functions,
582  *               those are really internal work
583  */
584 void
xmlThrDefSetGenericErrorFunc(void * ctx,xmlGenericErrorFunc handler)585 xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
586     xmlMutexLock(xmlThrDefMutex);
587     xmlGenericErrorContextThrDef = ctx;
588     if (handler != NULL)
589 	xmlGenericErrorThrDef = handler;
590     else
591 	xmlGenericErrorThrDef = xmlGenericErrorDefaultFunc;
592     xmlMutexUnlock(xmlThrDefMutex);
593 }
594 
595 void
xmlThrDefSetStructuredErrorFunc(void * ctx,xmlStructuredErrorFunc handler)596 xmlThrDefSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
597     xmlMutexLock(xmlThrDefMutex);
598     xmlStructuredErrorContextThrDef = ctx;
599     xmlStructuredErrorThrDef = handler;
600     xmlMutexUnlock(xmlThrDefMutex);
601 }
602 
603 /**
604  * xmlRegisterNodeDefault:
605  * @func: function pointer to the new RegisterNodeFunc
606  *
607  * Registers a callback for node creation
608  *
609  * Returns the old value of the registration function
610  */
611 xmlRegisterNodeFunc
xmlRegisterNodeDefault(xmlRegisterNodeFunc func)612 xmlRegisterNodeDefault(xmlRegisterNodeFunc func)
613 {
614     xmlRegisterNodeFunc old = xmlRegisterNodeDefaultValue;
615 
616     __xmlRegisterCallbacks = 1;
617     xmlRegisterNodeDefaultValue = func;
618     return(old);
619 }
620 
621 xmlRegisterNodeFunc
xmlThrDefRegisterNodeDefault(xmlRegisterNodeFunc func)622 xmlThrDefRegisterNodeDefault(xmlRegisterNodeFunc func)
623 {
624     xmlRegisterNodeFunc old;
625 
626     xmlMutexLock(xmlThrDefMutex);
627     old = xmlRegisterNodeDefaultValueThrDef;
628 
629     __xmlRegisterCallbacks = 1;
630     xmlRegisterNodeDefaultValueThrDef = func;
631     xmlMutexUnlock(xmlThrDefMutex);
632 
633     return(old);
634 }
635 
636 /**
637  * xmlDeregisterNodeDefault:
638  * @func: function pointer to the new DeregisterNodeFunc
639  *
640  * Registers a callback for node destruction
641  *
642  * Returns the previous value of the deregistration function
643  */
644 xmlDeregisterNodeFunc
xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func)645 xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func)
646 {
647     xmlDeregisterNodeFunc old = xmlDeregisterNodeDefaultValue;
648 
649     __xmlRegisterCallbacks = 1;
650     xmlDeregisterNodeDefaultValue = func;
651     return(old);
652 }
653 
654 xmlDeregisterNodeFunc
xmlThrDefDeregisterNodeDefault(xmlDeregisterNodeFunc func)655 xmlThrDefDeregisterNodeDefault(xmlDeregisterNodeFunc func)
656 {
657     xmlDeregisterNodeFunc old;
658 
659     xmlMutexLock(xmlThrDefMutex);
660     old = xmlDeregisterNodeDefaultValueThrDef;
661 
662     __xmlRegisterCallbacks = 1;
663     xmlDeregisterNodeDefaultValueThrDef = func;
664     xmlMutexUnlock(xmlThrDefMutex);
665 
666     return(old);
667 }
668 
669 xmlParserInputBufferCreateFilenameFunc
xmlThrDefParserInputBufferCreateFilenameDefault(xmlParserInputBufferCreateFilenameFunc func)670 xmlThrDefParserInputBufferCreateFilenameDefault(xmlParserInputBufferCreateFilenameFunc func)
671 {
672     xmlParserInputBufferCreateFilenameFunc old;
673 
674     xmlMutexLock(xmlThrDefMutex);
675     old = xmlParserInputBufferCreateFilenameValueThrDef;
676     if (old == NULL) {
677 		old = __xmlParserInputBufferCreateFilename;
678 	}
679 
680     xmlParserInputBufferCreateFilenameValueThrDef = func;
681     xmlMutexUnlock(xmlThrDefMutex);
682 
683     return(old);
684 }
685 
686 xmlOutputBufferCreateFilenameFunc
xmlThrDefOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func)687 xmlThrDefOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func)
688 {
689     xmlOutputBufferCreateFilenameFunc old;
690 
691     xmlMutexLock(xmlThrDefMutex);
692     old = xmlOutputBufferCreateFilenameValueThrDef;
693 #ifdef LIBXML_OUTPUT_ENABLED
694     if (old == NULL) {
695 		old = __xmlOutputBufferCreateFilename;
696 	}
697 #endif
698     xmlOutputBufferCreateFilenameValueThrDef = func;
699     xmlMutexUnlock(xmlThrDefMutex);
700 
701     return(old);
702 }
703 
704 #ifdef LIBXML_DOCB_ENABLED
705 #undef	docbDefaultSAXHandler
706 xmlSAXHandlerV1 *
__docbDefaultSAXHandler(void)707 __docbDefaultSAXHandler(void) {
708     if (IS_MAIN_THREAD)
709 	return (&docbDefaultSAXHandler);
710     else
711 	return (&xmlGetGlobalState()->docbDefaultSAXHandler);
712 }
713 #endif
714 
715 #ifdef LIBXML_HTML_ENABLED
716 #undef	htmlDefaultSAXHandler
717 xmlSAXHandlerV1 *
__htmlDefaultSAXHandler(void)718 __htmlDefaultSAXHandler(void) {
719     if (IS_MAIN_THREAD)
720 	return (&htmlDefaultSAXHandler);
721     else
722 	return (&xmlGetGlobalState()->htmlDefaultSAXHandler);
723 }
724 #endif
725 
726 #undef xmlLastError
727 xmlError *
__xmlLastError(void)728 __xmlLastError(void) {
729     if (IS_MAIN_THREAD)
730 	return (&xmlLastError);
731     else
732 	return (&xmlGetGlobalState()->xmlLastError);
733 }
734 
735 /*
736  * The following memory routines were apparently lost at some point,
737  * and were re-inserted at this point on June 10, 2004.  Hope it's
738  * the right place for them :-)
739  */
740 #if defined(LIBXML_THREAD_ALLOC_ENABLED) && defined(LIBXML_THREAD_ENABLED)
741 #undef xmlMalloc
742 xmlMallocFunc *
__xmlMalloc(void)743 __xmlMalloc(void){
744     if (IS_MAIN_THREAD)
745         return (&xmlMalloc);
746     else
747 	return (&xmlGetGlobalState()->xmlMalloc);
748 }
749 
750 #undef xmlMallocAtomic
751 xmlMallocFunc *
__xmlMallocAtomic(void)752 __xmlMallocAtomic(void){
753     if (IS_MAIN_THREAD)
754         return (&xmlMallocAtomic);
755     else
756         return (&xmlGetGlobalState()->xmlMallocAtomic);
757 }
758 
759 #undef xmlRealloc
760 xmlReallocFunc *
__xmlRealloc(void)761 __xmlRealloc(void){
762     if (IS_MAIN_THREAD)
763         return (&xmlRealloc);
764     else
765         return (&xmlGetGlobalState()->xmlRealloc);
766 }
767 
768 #undef xmlFree
769 xmlFreeFunc *
__xmlFree(void)770 __xmlFree(void){
771     if (IS_MAIN_THREAD)
772         return (&xmlFree);
773     else
774         return (&xmlGetGlobalState()->xmlFree);
775 }
776 
777 xmlStrdupFunc *
__xmlMemStrdup(void)778 __xmlMemStrdup(void){
779     if (IS_MAIN_THREAD)
780         return (&xmlMemStrdup);
781     else
782         return (&xmlGetGlobalState()->xmlMemStrdup);
783 }
784 
785 #endif
786 
787 /*
788  * Everything starting from the line below is
789  * Automatically generated by build_glob.py.
790  * Do not modify the previous line.
791  */
792 
793 
794 #undef	oldXMLWDcompatibility
795 int *
__oldXMLWDcompatibility(void)796 __oldXMLWDcompatibility(void) {
797     if (IS_MAIN_THREAD)
798 	return (&oldXMLWDcompatibility);
799     else
800 	return (&xmlGetGlobalState()->oldXMLWDcompatibility);
801 }
802 
803 #undef	xmlBufferAllocScheme
804 xmlBufferAllocationScheme *
__xmlBufferAllocScheme(void)805 __xmlBufferAllocScheme(void) {
806     if (IS_MAIN_THREAD)
807 	return (&xmlBufferAllocScheme);
808     else
809 	return (&xmlGetGlobalState()->xmlBufferAllocScheme);
810 }
xmlThrDefBufferAllocScheme(xmlBufferAllocationScheme v)811 xmlBufferAllocationScheme xmlThrDefBufferAllocScheme(xmlBufferAllocationScheme v) {
812     xmlBufferAllocationScheme ret;
813     xmlMutexLock(xmlThrDefMutex);
814     ret = xmlBufferAllocSchemeThrDef;
815     xmlBufferAllocSchemeThrDef = v;
816     xmlMutexUnlock(xmlThrDefMutex);
817     return ret;
818 }
819 
820 #undef	xmlDefaultBufferSize
821 int *
__xmlDefaultBufferSize(void)822 __xmlDefaultBufferSize(void) {
823     if (IS_MAIN_THREAD)
824 	return (&xmlDefaultBufferSize);
825     else
826 	return (&xmlGetGlobalState()->xmlDefaultBufferSize);
827 }
xmlThrDefDefaultBufferSize(int v)828 int xmlThrDefDefaultBufferSize(int v) {
829     int ret;
830     xmlMutexLock(xmlThrDefMutex);
831     ret = xmlDefaultBufferSizeThrDef;
832     xmlDefaultBufferSizeThrDef = v;
833     xmlMutexUnlock(xmlThrDefMutex);
834     return ret;
835 }
836 
837 #ifdef LIBXML_SAX1_ENABLED
838 #undef	xmlDefaultSAXHandler
839 xmlSAXHandlerV1 *
__xmlDefaultSAXHandler(void)840 __xmlDefaultSAXHandler(void) {
841     if (IS_MAIN_THREAD)
842 	return (&xmlDefaultSAXHandler);
843     else
844 	return (&xmlGetGlobalState()->xmlDefaultSAXHandler);
845 }
846 #endif /* LIBXML_SAX1_ENABLED */
847 
848 #undef	xmlDefaultSAXLocator
849 xmlSAXLocator *
__xmlDefaultSAXLocator(void)850 __xmlDefaultSAXLocator(void) {
851     if (IS_MAIN_THREAD)
852 	return (&xmlDefaultSAXLocator);
853     else
854 	return (&xmlGetGlobalState()->xmlDefaultSAXLocator);
855 }
856 
857 #undef	xmlDoValidityCheckingDefaultValue
858 int *
__xmlDoValidityCheckingDefaultValue(void)859 __xmlDoValidityCheckingDefaultValue(void) {
860     if (IS_MAIN_THREAD)
861 	return (&xmlDoValidityCheckingDefaultValue);
862     else
863 	return (&xmlGetGlobalState()->xmlDoValidityCheckingDefaultValue);
864 }
xmlThrDefDoValidityCheckingDefaultValue(int v)865 int xmlThrDefDoValidityCheckingDefaultValue(int v) {
866     int ret;
867     xmlMutexLock(xmlThrDefMutex);
868     ret = xmlDoValidityCheckingDefaultValueThrDef;
869     xmlDoValidityCheckingDefaultValueThrDef = v;
870     xmlMutexUnlock(xmlThrDefMutex);
871     return ret;
872 }
873 
874 #undef	xmlGenericError
875 xmlGenericErrorFunc *
__xmlGenericError(void)876 __xmlGenericError(void) {
877     if (IS_MAIN_THREAD)
878 	return (&xmlGenericError);
879     else
880 	return (&xmlGetGlobalState()->xmlGenericError);
881 }
882 
883 #undef	xmlStructuredError
884 xmlStructuredErrorFunc *
__xmlStructuredError(void)885 __xmlStructuredError(void) {
886     if (IS_MAIN_THREAD)
887 	return (&xmlStructuredError);
888     else
889 	return (&xmlGetGlobalState()->xmlStructuredError);
890 }
891 
892 #undef	xmlGenericErrorContext
893 void * *
__xmlGenericErrorContext(void)894 __xmlGenericErrorContext(void) {
895     if (IS_MAIN_THREAD)
896 	return (&xmlGenericErrorContext);
897     else
898 	return (&xmlGetGlobalState()->xmlGenericErrorContext);
899 }
900 
901 #undef	xmlStructuredErrorContext
902 void * *
__xmlStructuredErrorContext(void)903 __xmlStructuredErrorContext(void) {
904     if (IS_MAIN_THREAD)
905 	return (&xmlStructuredErrorContext);
906     else
907 	return (&xmlGetGlobalState()->xmlStructuredErrorContext);
908 }
909 
910 #undef	xmlGetWarningsDefaultValue
911 int *
__xmlGetWarningsDefaultValue(void)912 __xmlGetWarningsDefaultValue(void) {
913     if (IS_MAIN_THREAD)
914 	return (&xmlGetWarningsDefaultValue);
915     else
916 	return (&xmlGetGlobalState()->xmlGetWarningsDefaultValue);
917 }
xmlThrDefGetWarningsDefaultValue(int v)918 int xmlThrDefGetWarningsDefaultValue(int v) {
919     int ret;
920     xmlMutexLock(xmlThrDefMutex);
921     ret = xmlGetWarningsDefaultValueThrDef;
922     xmlGetWarningsDefaultValueThrDef = v;
923     xmlMutexUnlock(xmlThrDefMutex);
924     return ret;
925 }
926 
927 #undef	xmlIndentTreeOutput
928 int *
__xmlIndentTreeOutput(void)929 __xmlIndentTreeOutput(void) {
930     if (IS_MAIN_THREAD)
931 	return (&xmlIndentTreeOutput);
932     else
933 	return (&xmlGetGlobalState()->xmlIndentTreeOutput);
934 }
xmlThrDefIndentTreeOutput(int v)935 int xmlThrDefIndentTreeOutput(int v) {
936     int ret;
937     xmlMutexLock(xmlThrDefMutex);
938     ret = xmlIndentTreeOutputThrDef;
939     xmlIndentTreeOutputThrDef = v;
940     xmlMutexUnlock(xmlThrDefMutex);
941     return ret;
942 }
943 
944 #undef	xmlTreeIndentString
945 const char * *
__xmlTreeIndentString(void)946 __xmlTreeIndentString(void) {
947     if (IS_MAIN_THREAD)
948 	return (&xmlTreeIndentString);
949     else
950 	return (&xmlGetGlobalState()->xmlTreeIndentString);
951 }
xmlThrDefTreeIndentString(const char * v)952 const char * xmlThrDefTreeIndentString(const char * v) {
953     const char * ret;
954     xmlMutexLock(xmlThrDefMutex);
955     ret = xmlTreeIndentStringThrDef;
956     xmlTreeIndentStringThrDef = v;
957     xmlMutexUnlock(xmlThrDefMutex);
958     return ret;
959 }
960 
961 #undef	xmlKeepBlanksDefaultValue
962 int *
__xmlKeepBlanksDefaultValue(void)963 __xmlKeepBlanksDefaultValue(void) {
964     if (IS_MAIN_THREAD)
965 	return (&xmlKeepBlanksDefaultValue);
966     else
967 	return (&xmlGetGlobalState()->xmlKeepBlanksDefaultValue);
968 }
xmlThrDefKeepBlanksDefaultValue(int v)969 int xmlThrDefKeepBlanksDefaultValue(int v) {
970     int ret;
971     xmlMutexLock(xmlThrDefMutex);
972     ret = xmlKeepBlanksDefaultValueThrDef;
973     xmlKeepBlanksDefaultValueThrDef = v;
974     xmlMutexUnlock(xmlThrDefMutex);
975     return ret;
976 }
977 
978 #undef	xmlLineNumbersDefaultValue
979 int *
__xmlLineNumbersDefaultValue(void)980 __xmlLineNumbersDefaultValue(void) {
981     if (IS_MAIN_THREAD)
982 	return (&xmlLineNumbersDefaultValue);
983     else
984 	return (&xmlGetGlobalState()->xmlLineNumbersDefaultValue);
985 }
xmlThrDefLineNumbersDefaultValue(int v)986 int xmlThrDefLineNumbersDefaultValue(int v) {
987     int ret;
988     xmlMutexLock(xmlThrDefMutex);
989     ret = xmlLineNumbersDefaultValueThrDef;
990     xmlLineNumbersDefaultValueThrDef = v;
991     xmlMutexUnlock(xmlThrDefMutex);
992     return ret;
993 }
994 
995 #undef	xmlLoadExtDtdDefaultValue
996 int *
__xmlLoadExtDtdDefaultValue(void)997 __xmlLoadExtDtdDefaultValue(void) {
998     if (IS_MAIN_THREAD)
999 	return (&xmlLoadExtDtdDefaultValue);
1000     else
1001 	return (&xmlGetGlobalState()->xmlLoadExtDtdDefaultValue);
1002 }
xmlThrDefLoadExtDtdDefaultValue(int v)1003 int xmlThrDefLoadExtDtdDefaultValue(int v) {
1004     int ret;
1005     xmlMutexLock(xmlThrDefMutex);
1006     ret = xmlLoadExtDtdDefaultValueThrDef;
1007     xmlLoadExtDtdDefaultValueThrDef = v;
1008     xmlMutexUnlock(xmlThrDefMutex);
1009     return ret;
1010 }
1011 
1012 #undef	xmlParserDebugEntities
1013 int *
__xmlParserDebugEntities(void)1014 __xmlParserDebugEntities(void) {
1015     if (IS_MAIN_THREAD)
1016 	return (&xmlParserDebugEntities);
1017     else
1018 	return (&xmlGetGlobalState()->xmlParserDebugEntities);
1019 }
xmlThrDefParserDebugEntities(int v)1020 int xmlThrDefParserDebugEntities(int v) {
1021     int ret;
1022     xmlMutexLock(xmlThrDefMutex);
1023     ret = xmlParserDebugEntitiesThrDef;
1024     xmlParserDebugEntitiesThrDef = v;
1025     xmlMutexUnlock(xmlThrDefMutex);
1026     return ret;
1027 }
1028 
1029 #undef	xmlParserVersion
1030 const char * *
__xmlParserVersion(void)1031 __xmlParserVersion(void) {
1032     if (IS_MAIN_THREAD)
1033 	return (&xmlParserVersion);
1034     else
1035 	return (&xmlGetGlobalState()->xmlParserVersion);
1036 }
1037 
1038 #undef	xmlPedanticParserDefaultValue
1039 int *
__xmlPedanticParserDefaultValue(void)1040 __xmlPedanticParserDefaultValue(void) {
1041     if (IS_MAIN_THREAD)
1042 	return (&xmlPedanticParserDefaultValue);
1043     else
1044 	return (&xmlGetGlobalState()->xmlPedanticParserDefaultValue);
1045 }
xmlThrDefPedanticParserDefaultValue(int v)1046 int xmlThrDefPedanticParserDefaultValue(int v) {
1047     int ret;
1048     xmlMutexLock(xmlThrDefMutex);
1049     ret = xmlPedanticParserDefaultValueThrDef;
1050     xmlPedanticParserDefaultValueThrDef = v;
1051     xmlMutexUnlock(xmlThrDefMutex);
1052     return ret;
1053 }
1054 
1055 #undef	xmlSaveNoEmptyTags
1056 int *
__xmlSaveNoEmptyTags(void)1057 __xmlSaveNoEmptyTags(void) {
1058     if (IS_MAIN_THREAD)
1059 	return (&xmlSaveNoEmptyTags);
1060     else
1061 	return (&xmlGetGlobalState()->xmlSaveNoEmptyTags);
1062 }
xmlThrDefSaveNoEmptyTags(int v)1063 int xmlThrDefSaveNoEmptyTags(int v) {
1064     int ret;
1065     xmlMutexLock(xmlThrDefMutex);
1066     ret = xmlSaveNoEmptyTagsThrDef;
1067     xmlSaveNoEmptyTagsThrDef = v;
1068     xmlMutexUnlock(xmlThrDefMutex);
1069     return ret;
1070 }
1071 
1072 #undef	xmlSubstituteEntitiesDefaultValue
1073 int *
__xmlSubstituteEntitiesDefaultValue(void)1074 __xmlSubstituteEntitiesDefaultValue(void) {
1075     if (IS_MAIN_THREAD)
1076 	return (&xmlSubstituteEntitiesDefaultValue);
1077     else
1078 	return (&xmlGetGlobalState()->xmlSubstituteEntitiesDefaultValue);
1079 }
xmlThrDefSubstituteEntitiesDefaultValue(int v)1080 int xmlThrDefSubstituteEntitiesDefaultValue(int v) {
1081     int ret;
1082     xmlMutexLock(xmlThrDefMutex);
1083     ret = xmlSubstituteEntitiesDefaultValueThrDef;
1084     xmlSubstituteEntitiesDefaultValueThrDef = v;
1085     xmlMutexUnlock(xmlThrDefMutex);
1086     return ret;
1087 }
1088 
1089 #undef	xmlRegisterNodeDefaultValue
1090 xmlRegisterNodeFunc *
__xmlRegisterNodeDefaultValue(void)1091 __xmlRegisterNodeDefaultValue(void) {
1092     if (IS_MAIN_THREAD)
1093 	return (&xmlRegisterNodeDefaultValue);
1094     else
1095 	return (&xmlGetGlobalState()->xmlRegisterNodeDefaultValue);
1096 }
1097 
1098 #undef	xmlDeregisterNodeDefaultValue
1099 xmlDeregisterNodeFunc *
__xmlDeregisterNodeDefaultValue(void)1100 __xmlDeregisterNodeDefaultValue(void) {
1101     if (IS_MAIN_THREAD)
1102 	return (&xmlDeregisterNodeDefaultValue);
1103     else
1104 	return (&xmlGetGlobalState()->xmlDeregisterNodeDefaultValue);
1105 }
1106 
1107 #undef	xmlParserInputBufferCreateFilenameValue
1108 xmlParserInputBufferCreateFilenameFunc *
__xmlParserInputBufferCreateFilenameValue(void)1109 __xmlParserInputBufferCreateFilenameValue(void) {
1110     if (IS_MAIN_THREAD)
1111 	return (&xmlParserInputBufferCreateFilenameValue);
1112     else
1113 	return (&xmlGetGlobalState()->xmlParserInputBufferCreateFilenameValue);
1114 }
1115 
1116 #undef	xmlOutputBufferCreateFilenameValue
1117 xmlOutputBufferCreateFilenameFunc *
__xmlOutputBufferCreateFilenameValue(void)1118 __xmlOutputBufferCreateFilenameValue(void) {
1119     if (IS_MAIN_THREAD)
1120 	return (&xmlOutputBufferCreateFilenameValue);
1121     else
1122 	return (&xmlGetGlobalState()->xmlOutputBufferCreateFilenameValue);
1123 }
1124 
1125 #define bottom_globals
1126 #include "elfgcchack.h"
1127