blob: 69a84f287a4d7a94c19131752b02a475ddcd0719 [file] [log] [blame]
Daniel Veillardb8478642001-10-12 17:29:10 +00001/*
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#include "libxml.h"
15
Daniel Veillarde7090612001-10-13 12:18:28 +000016#ifdef HAVE_STDLIB_H
Jaka Mocnik77d19ae2001-10-13 12:06:09 +000017#include <stdlib.h>
Daniel Veillarde7090612001-10-13 12:18:28 +000018#endif
Jaka Mocnik77d19ae2001-10-13 12:06:09 +000019#include <string.h>
20
Daniel Veillarde7090612001-10-13 12:18:28 +000021#include <libxml/xmlmemory.h>
22
Daniel Veillardb8478642001-10-12 17:29:10 +000023/*
24 * Helpful Macro
25 */
26#ifdef WITH_PTHREAD_H
27#if defined(SOLARIS)
28#define THR_MAIN(tid) (-1 == thr_main() || tid == thr_main())
29#else
30#define THR_MAIN(tid) (tid == 0 || tid == 1024)
31#endif
32
33#define IS_MAIN_THREAD (THR_MAIN(pthread_self()))
34#else
35#define IS_MAIN_THREAD 1
36#endif
37
38/************************************************************************
39 * *
40 * All the user accessible global variables of the library *
41 * *
42 ************************************************************************/
43
44const char *xmlParserVersion = LIBXML_VERSION_STRING;
Daniel Veillardd0463562001-10-13 09:15:48 +000045
Daniel Veillardb8478642001-10-12 17:29:10 +000046/*
47 * Memory allocation routines
48 */
49#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
Daniel Veillardd0463562001-10-13 09:15:48 +000050extern void xmlMemFree(void *ptr);
51extern void * xmlMemMalloc(size_t size);
52extern void * xmlMemRealloc(void *ptr,size_t size);
53extern char * xmlMemoryStrdup(const char *str);
54
Daniel Veillardb8478642001-10-12 17:29:10 +000055xmlFreeFunc xmlFree = (xmlFreeFunc) xmlMemFree;
56xmlMallocFunc xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
57xmlReallocFunc xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
58xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
59#else
60xmlFreeFunc xmlFree = (xmlFreeFunc) free;
61xmlMallocFunc xmlMalloc = (xmlMallocFunc) malloc;
62xmlReallocFunc xmlRealloc = (xmlReallocFunc) realloc;
63xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) strdup;
64#endif
65
Daniel Veillardd0463562001-10-13 09:15:48 +000066#include <libxml/threads.h>
67#include <libxml/globals.h>
68#include <libxml/SAX.h>
69
70#undef docbDefaultSAXHandler
71#undef htmlDefaultSAXHandler
72#undef oldXMLWDcompatibility
73#undef xmlBufferAllocScheme
74#undef xmlDefaultBufferSize
75#undef xmlDefaultSAXHandler
76#undef xmlDefaultSAXLocator
77#undef xmlDoValidityCheckingDefaultValue
78#undef xmlGenericError
79#undef xmlGenericErrorContext
80#undef xmlGetWarningsDefaultValue
81#undef xmlIndentTreeOutput
82#undef xmlKeepBlanksDefaultValue
83#undef xmlLineNumbersDefaultValue
84#undef xmlLoadExtDtdDefaultValue
85#undef xmlParserDebugEntities
86#undef xmlParserVersion
87#undef xmlPedanticParserDefaultValue
88#undef xmlSaveNoEmptyTags
89#undef xmlSubstituteEntitiesDefaultValue
90
91#undef xmlFree
92#undef xmlMalloc
93#undef xmlMemStrdup
94#undef xmlRealloc
95
Daniel Veillardb8478642001-10-12 17:29:10 +000096/*
97 * Buffers stuff
98 */
99xmlBufferAllocationScheme xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
100int xmlDefaultBufferSize = BASE_BUFFER_SIZE;
101
102/*
103 * Parser defaults
104 */
Daniel Veillardd0463562001-10-13 09:15:48 +0000105
Daniel Veillardb8478642001-10-12 17:29:10 +0000106int oldXMLWDcompatibility = 0; /* DEPRECATED */
107int xmlParserDebugEntities = 0;
108int xmlDoValidityCheckingDefaultValue = 0;
109int xmlGetWarningsDefaultValue = 1;
110int xmlLoadExtDtdDefaultValue = 0;
111int xmlPedanticParserDefaultValue = 0;
112int xmlLineNumbersDefaultValue = 0;
113int xmlKeepBlanksDefaultValue = 1;
114int xmlSubstituteEntitiesDefaultValue = 0;
115
116/*
117 * Error handling
118 */
119
120/* xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc; */
121/* Must initialize xmlGenericError in xmlInitParser */
122xmlGenericErrorFunc xmlGenericError;
123void *xmlGenericErrorContext = NULL;
124
125/*
126 * output defaults
127 */
128int xmlIndentTreeOutput = 0;
129int xmlSaveNoEmptyTags = 0;
130
131/*
132 * Default handler for XML, builds the DOM tree
133 */
134xmlSAXHandler xmlDefaultSAXHandler = {
135 internalSubset,
136 isStandalone,
137 hasInternalSubset,
138 hasExternalSubset,
139 resolveEntity,
140 getEntity,
141 entityDecl,
142 notationDecl,
143 attributeDecl,
144 elementDecl,
145 unparsedEntityDecl,
146 setDocumentLocator,
147 startDocument,
148 endDocument,
149 startElement,
150 endElement,
151 reference,
152 characters,
153 characters,
154 processingInstruction,
155 comment,
156 xmlParserWarning,
157 xmlParserError,
158 xmlParserError,
159 getParameterEntity,
160 cdataBlock,
161 externalSubset,
162 0
163};
164
165/*
166 * The default SAX Locator.
167 */
168
169xmlSAXLocator xmlDefaultSAXLocator = {
170 getPublicId, getSystemId, getLineNumber, getColumnNumber
171};
172
173#ifdef LIBXML_HTML_ENABLED
174/*
175 * Default handler for HTML, builds the DOM tree
176 */
177xmlSAXHandler htmlDefaultSAXHandler = {
178 internalSubset,
179 NULL,
180 NULL,
181 NULL,
182 NULL,
183 getEntity,
184 NULL,
185 NULL,
186 NULL,
187 NULL,
188 NULL,
189 setDocumentLocator,
190 startDocument,
191 endDocument,
192 startElement,
193 endElement,
194 NULL,
195 characters,
196 ignorableWhitespace,
197 NULL,
198 comment,
199 xmlParserWarning,
200 xmlParserError,
201 xmlParserError,
202 getParameterEntity,
203 cdataBlock,
204 NULL,
205 0
206};
207#endif /* LIBXML_HTML_ENABLED */
208
209#ifdef LIBXML_DOCB_ENABLED
210/*
211 * Default handler for SGML DocBook, builds the DOM tree
212 */
213xmlSAXHandler docbDefaultSAXHandler = {
214 internalSubset,
215 isStandalone,
216 hasInternalSubset,
217 hasExternalSubset,
218 resolveEntity,
219 getEntity,
220 entityDecl,
221 NULL,
222 NULL,
223 NULL,
224 NULL,
225 setDocumentLocator,
226 startDocument,
227 endDocument,
228 startElement,
229 endElement,
230 reference,
231 characters,
232 ignorableWhitespace,
233 NULL,
234 comment,
235 xmlParserWarning,
236 xmlParserError,
237 xmlParserError,
238 getParameterEntity,
239 NULL,
240 NULL,
241 0
242};
243#endif /* LIBXML_DOCB_ENABLED */
244
245/**
246 * xmlInitializeGlobalState:
247 * @gs: a pointer to a newly allocated global state
248 *
249 * xmlInitializeGlobalState() initialize a global state with all the
250 * default values of the library.
251 */
252void
253xmlInitializeGlobalState(xmlGlobalStatePtr gs)
254{
255 /*
256 * Perform initialisation as required by libxml
257 */
258 initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler);
259 inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler);
260 gs->oldXMLWDcompatibility = 0;
261 gs->xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
262 gs->xmlDefaultBufferSize = BASE_BUFFER_SIZE;
263 initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
264 gs->xmlDefaultSAXLocator.getPublicId = getPublicId;
265 gs->xmlDefaultSAXLocator.getSystemId = getSystemId;
266 gs->xmlDefaultSAXLocator.getLineNumber = getLineNumber;
267 gs->xmlDefaultSAXLocator.getColumnNumber = getColumnNumber;
268 gs->xmlDoValidityCheckingDefaultValue = 0;
269#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
270 gs->xmlFree = (xmlFreeFunc) xmlMemFree;
271 gs->xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
272 gs->xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
273 gs->xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
274#else
275 gs->xmlFree = (xmlFreeFunc) free;
276 gs->xmlMalloc = (xmlMallocFunc) malloc;
277 gs->xmlRealloc = (xmlReallocFunc) realloc;
278 gs->xmlMemStrdup = (xmlStrdupFunc) strdup;
279#endif
280 initGenericErrorDefaultFunc(&gs->xmlGenericError);
281 gs->xmlGenericErrorContext = NULL;
282 gs->xmlGetWarningsDefaultValue = 1;
283 gs->xmlIndentTreeOutput = 0;
284 gs->xmlKeepBlanksDefaultValue = 1;
285 gs->xmlLineNumbersDefaultValue = 0;
286 gs->xmlLoadExtDtdDefaultValue = 0;
287 gs->xmlParserDebugEntities = 0;
288 gs->xmlParserVersion = LIBXML_VERSION_STRING;
289 gs->xmlPedanticParserDefaultValue = 0;
290 gs->xmlSaveNoEmptyTags = 0;
291 gs->xmlSubstituteEntitiesDefaultValue = 0;
292}
293
294/*
295 * Everything starting from the line below is
296 * Automatically generated by build_glob.py.
297 * Do not modify the previous line.
298 */
299
300
301extern xmlSAXHandler docbDefaultSAXHandler;
302#undef docbDefaultSAXHandler
303xmlSAXHandler *
304__docbDefaultSAXHandler(void) {
305 if (IS_MAIN_THREAD)
306 return (&docbDefaultSAXHandler);
307 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000308 return (&xmlGetGlobalState()->docbDefaultSAXHandler);
Daniel Veillardb8478642001-10-12 17:29:10 +0000309}
310
311extern xmlSAXHandler htmlDefaultSAXHandler;
312#undef htmlDefaultSAXHandler
313xmlSAXHandler *
314__htmlDefaultSAXHandler(void) {
315 if (IS_MAIN_THREAD)
316 return (&htmlDefaultSAXHandler);
317 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000318 return (&xmlGetGlobalState()->htmlDefaultSAXHandler);
Daniel Veillardb8478642001-10-12 17:29:10 +0000319}
320
321extern int oldXMLWDcompatibility;
322#undef oldXMLWDcompatibility
323int *
324__oldXMLWDcompatibility(void) {
325 if (IS_MAIN_THREAD)
326 return (&oldXMLWDcompatibility);
327 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000328 return (&xmlGetGlobalState()->oldXMLWDcompatibility);
Daniel Veillardb8478642001-10-12 17:29:10 +0000329}
330
331extern xmlBufferAllocationScheme xmlBufferAllocScheme;
332#undef xmlBufferAllocScheme
333xmlBufferAllocationScheme *
334__xmlBufferAllocScheme(void) {
335 if (IS_MAIN_THREAD)
336 return (&xmlBufferAllocScheme);
337 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000338 return (&xmlGetGlobalState()->xmlBufferAllocScheme);
Daniel Veillardb8478642001-10-12 17:29:10 +0000339}
340
341extern int xmlDefaultBufferSize;
342#undef xmlDefaultBufferSize
343int *
344__xmlDefaultBufferSize(void) {
345 if (IS_MAIN_THREAD)
346 return (&xmlDefaultBufferSize);
347 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000348 return (&xmlGetGlobalState()->xmlDefaultBufferSize);
Daniel Veillardb8478642001-10-12 17:29:10 +0000349}
350
351extern xmlSAXHandler xmlDefaultSAXHandler;
352#undef xmlDefaultSAXHandler
353xmlSAXHandler *
354__xmlDefaultSAXHandler(void) {
355 if (IS_MAIN_THREAD)
356 return (&xmlDefaultSAXHandler);
357 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000358 return (&xmlGetGlobalState()->xmlDefaultSAXHandler);
Daniel Veillardb8478642001-10-12 17:29:10 +0000359}
360
361extern xmlSAXLocator xmlDefaultSAXLocator;
362#undef xmlDefaultSAXLocator
363xmlSAXLocator *
364__xmlDefaultSAXLocator(void) {
365 if (IS_MAIN_THREAD)
366 return (&xmlDefaultSAXLocator);
367 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000368 return (&xmlGetGlobalState()->xmlDefaultSAXLocator);
Daniel Veillardb8478642001-10-12 17:29:10 +0000369}
370
371extern int xmlDoValidityCheckingDefaultValue;
372#undef xmlDoValidityCheckingDefaultValue
373int *
374__xmlDoValidityCheckingDefaultValue(void) {
375 if (IS_MAIN_THREAD)
376 return (&xmlDoValidityCheckingDefaultValue);
377 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000378 return (&xmlGetGlobalState()->xmlDoValidityCheckingDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000379}
380
381extern xmlFreeFunc xmlFree;
382#undef xmlFree
383xmlFreeFunc *
384__xmlFree(void) {
385 if (IS_MAIN_THREAD)
386 return (&xmlFree);
387 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000388 return (&xmlGetGlobalState()->xmlFree);
Daniel Veillardb8478642001-10-12 17:29:10 +0000389}
390
391extern xmlGenericErrorFunc xmlGenericError;
392#undef xmlGenericError
393xmlGenericErrorFunc *
394__xmlGenericError(void) {
395 if (IS_MAIN_THREAD)
396 return (&xmlGenericError);
397 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000398 return (&xmlGetGlobalState()->xmlGenericError);
Daniel Veillardb8478642001-10-12 17:29:10 +0000399}
400
401extern void * xmlGenericErrorContext;
402#undef xmlGenericErrorContext
403void * *
404__xmlGenericErrorContext(void) {
405 if (IS_MAIN_THREAD)
406 return (&xmlGenericErrorContext);
407 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000408 return (&xmlGetGlobalState()->xmlGenericErrorContext);
Daniel Veillardb8478642001-10-12 17:29:10 +0000409}
410
411extern int xmlGetWarningsDefaultValue;
412#undef xmlGetWarningsDefaultValue
413int *
414__xmlGetWarningsDefaultValue(void) {
415 if (IS_MAIN_THREAD)
416 return (&xmlGetWarningsDefaultValue);
417 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000418 return (&xmlGetGlobalState()->xmlGetWarningsDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000419}
420
421extern int xmlIndentTreeOutput;
422#undef xmlIndentTreeOutput
423int *
424__xmlIndentTreeOutput(void) {
425 if (IS_MAIN_THREAD)
426 return (&xmlIndentTreeOutput);
427 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000428 return (&xmlGetGlobalState()->xmlIndentTreeOutput);
Daniel Veillardb8478642001-10-12 17:29:10 +0000429}
430
431extern int xmlKeepBlanksDefaultValue;
432#undef xmlKeepBlanksDefaultValue
433int *
434__xmlKeepBlanksDefaultValue(void) {
435 if (IS_MAIN_THREAD)
436 return (&xmlKeepBlanksDefaultValue);
437 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000438 return (&xmlGetGlobalState()->xmlKeepBlanksDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000439}
440
441extern int xmlLineNumbersDefaultValue;
442#undef xmlLineNumbersDefaultValue
443int *
444__xmlLineNumbersDefaultValue(void) {
445 if (IS_MAIN_THREAD)
446 return (&xmlLineNumbersDefaultValue);
447 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000448 return (&xmlGetGlobalState()->xmlLineNumbersDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000449}
450
451extern int xmlLoadExtDtdDefaultValue;
452#undef xmlLoadExtDtdDefaultValue
453int *
454__xmlLoadExtDtdDefaultValue(void) {
455 if (IS_MAIN_THREAD)
456 return (&xmlLoadExtDtdDefaultValue);
457 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000458 return (&xmlGetGlobalState()->xmlLoadExtDtdDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000459}
460
461extern xmlMallocFunc xmlMalloc;
462#undef xmlMalloc
463xmlMallocFunc *
464__xmlMalloc(void) {
465 if (IS_MAIN_THREAD)
466 return (&xmlMalloc);
467 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000468 return (&xmlGetGlobalState()->xmlMalloc);
Daniel Veillardb8478642001-10-12 17:29:10 +0000469}
470
471extern xmlStrdupFunc xmlMemStrdup;
472#undef xmlMemStrdup
473xmlStrdupFunc *
474__xmlMemStrdup(void) {
475 if (IS_MAIN_THREAD)
476 return (&xmlMemStrdup);
477 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000478 return (&xmlGetGlobalState()->xmlMemStrdup);
Daniel Veillardb8478642001-10-12 17:29:10 +0000479}
480
481extern int xmlParserDebugEntities;
482#undef xmlParserDebugEntities
483int *
484__xmlParserDebugEntities(void) {
485 if (IS_MAIN_THREAD)
486 return (&xmlParserDebugEntities);
487 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000488 return (&xmlGetGlobalState()->xmlParserDebugEntities);
Daniel Veillardb8478642001-10-12 17:29:10 +0000489}
490
491extern const char * xmlParserVersion;
492#undef xmlParserVersion
493const char * *
494__xmlParserVersion(void) {
495 if (IS_MAIN_THREAD)
496 return (&xmlParserVersion);
497 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000498 return (&xmlGetGlobalState()->xmlParserVersion);
Daniel Veillardb8478642001-10-12 17:29:10 +0000499}
500
501extern int xmlPedanticParserDefaultValue;
502#undef xmlPedanticParserDefaultValue
503int *
504__xmlPedanticParserDefaultValue(void) {
505 if (IS_MAIN_THREAD)
506 return (&xmlPedanticParserDefaultValue);
507 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000508 return (&xmlGetGlobalState()->xmlPedanticParserDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000509}
510
511extern xmlReallocFunc xmlRealloc;
512#undef xmlRealloc
513xmlReallocFunc *
514__xmlRealloc(void) {
515 if (IS_MAIN_THREAD)
516 return (&xmlRealloc);
517 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000518 return (&xmlGetGlobalState()->xmlRealloc);
Daniel Veillardb8478642001-10-12 17:29:10 +0000519}
520
521extern int xmlSaveNoEmptyTags;
522#undef xmlSaveNoEmptyTags
523int *
524__xmlSaveNoEmptyTags(void) {
525 if (IS_MAIN_THREAD)
526 return (&xmlSaveNoEmptyTags);
527 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000528 return (&xmlGetGlobalState()->xmlSaveNoEmptyTags);
Daniel Veillardb8478642001-10-12 17:29:10 +0000529}
530
531extern int xmlSubstituteEntitiesDefaultValue;
532#undef xmlSubstituteEntitiesDefaultValue
533int *
534__xmlSubstituteEntitiesDefaultValue(void) {
535 if (IS_MAIN_THREAD)
536 return (&xmlSubstituteEntitiesDefaultValue);
537 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000538 return (&xmlGetGlobalState()->xmlSubstituteEntitiesDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000539}