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