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