globals.c 28 KB

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