blob: e5b5bc8bbc2f233aafec9271cbe7070f6838d5ba [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 Veillard3c01b1d2001-10-17 15:58:35 +000021#include <libxml/xmlversion.h>
22#include <libxml/globals.h>
Daniel Veillarde7090612001-10-13 12:18:28 +000023#include <libxml/xmlmemory.h>
24
Daniel Veillard3c01b1d2001-10-17 15:58:35 +000025/* #define DEBUG_GLOBALS */
26
Daniel Veillardb8478642001-10-12 17:29:10 +000027/*
28 * Helpful Macro
29 */
Daniel Veillard3c01b1d2001-10-17 15:58:35 +000030#ifdef LIBXML_THREAD_ENABLED
31#define IS_MAIN_THREAD (xmlIsMainThread())
Daniel Veillardb8478642001-10-12 17:29:10 +000032#else
33#define IS_MAIN_THREAD 1
34#endif
35
36/************************************************************************
37 * *
38 * All the user accessible global variables of the library *
39 * *
40 ************************************************************************/
41
Daniel Veillardb8478642001-10-12 17:29:10 +000042/*
43 * Memory allocation routines
44 */
45#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
Daniel Veillardd0463562001-10-13 09:15:48 +000046extern void xmlMemFree(void *ptr);
47extern void * xmlMemMalloc(size_t size);
48extern void * xmlMemRealloc(void *ptr,size_t size);
49extern char * xmlMemoryStrdup(const char *str);
50
Daniel Veillardb8478642001-10-12 17:29:10 +000051xmlFreeFunc xmlFree = (xmlFreeFunc) xmlMemFree;
52xmlMallocFunc xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
53xmlReallocFunc xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
54xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
55#else
56xmlFreeFunc xmlFree = (xmlFreeFunc) free;
57xmlMallocFunc xmlMalloc = (xmlMallocFunc) malloc;
58xmlReallocFunc xmlRealloc = (xmlReallocFunc) realloc;
59xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) strdup;
60#endif
61
Daniel Veillardd0463562001-10-13 09:15:48 +000062#include <libxml/threads.h>
63#include <libxml/globals.h>
64#include <libxml/SAX.h>
65
66#undef docbDefaultSAXHandler
67#undef htmlDefaultSAXHandler
68#undef oldXMLWDcompatibility
69#undef xmlBufferAllocScheme
70#undef xmlDefaultBufferSize
71#undef xmlDefaultSAXHandler
72#undef xmlDefaultSAXLocator
73#undef xmlDoValidityCheckingDefaultValue
74#undef xmlGenericError
75#undef xmlGenericErrorContext
76#undef xmlGetWarningsDefaultValue
77#undef xmlIndentTreeOutput
78#undef xmlKeepBlanksDefaultValue
79#undef xmlLineNumbersDefaultValue
80#undef xmlLoadExtDtdDefaultValue
81#undef xmlParserDebugEntities
82#undef xmlParserVersion
83#undef xmlPedanticParserDefaultValue
84#undef xmlSaveNoEmptyTags
85#undef xmlSubstituteEntitiesDefaultValue
86
87#undef xmlFree
88#undef xmlMalloc
89#undef xmlMemStrdup
90#undef xmlRealloc
91
Daniel Veillard3c01b1d2001-10-17 15:58:35 +000092const char *xmlParserVersion = LIBXML_VERSION_STRING;
93
Daniel Veillardb8478642001-10-12 17:29:10 +000094/*
95 * Buffers stuff
96 */
97xmlBufferAllocationScheme xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
98int xmlDefaultBufferSize = BASE_BUFFER_SIZE;
99
100/*
101 * Parser defaults
102 */
Daniel Veillardd0463562001-10-13 09:15:48 +0000103
Daniel Veillardb8478642001-10-12 17:29:10 +0000104int oldXMLWDcompatibility = 0; /* DEPRECATED */
105int xmlParserDebugEntities = 0;
106int xmlDoValidityCheckingDefaultValue = 0;
107int xmlGetWarningsDefaultValue = 1;
108int xmlLoadExtDtdDefaultValue = 0;
109int xmlPedanticParserDefaultValue = 0;
110int xmlLineNumbersDefaultValue = 0;
111int xmlKeepBlanksDefaultValue = 1;
112int xmlSubstituteEntitiesDefaultValue = 0;
113
114/*
115 * Error handling
116 */
117
118/* xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc; */
119/* Must initialize xmlGenericError in xmlInitParser */
Daniel Veillard635ef722001-10-29 11:48:19 +0000120void xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED,
121 const char *msg,
122 ...);
123xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc;
Daniel Veillardb8478642001-10-12 17:29:10 +0000124void *xmlGenericErrorContext = NULL;
125
126/*
127 * output defaults
128 */
129int xmlIndentTreeOutput = 0;
130int xmlSaveNoEmptyTags = 0;
131
132/*
133 * Default handler for XML, builds the DOM tree
134 */
135xmlSAXHandler xmlDefaultSAXHandler = {
136 internalSubset,
137 isStandalone,
138 hasInternalSubset,
139 hasExternalSubset,
140 resolveEntity,
141 getEntity,
142 entityDecl,
143 notationDecl,
144 attributeDecl,
145 elementDecl,
146 unparsedEntityDecl,
147 setDocumentLocator,
148 startDocument,
149 endDocument,
150 startElement,
151 endElement,
152 reference,
153 characters,
154 characters,
155 processingInstruction,
156 comment,
157 xmlParserWarning,
158 xmlParserError,
159 xmlParserError,
160 getParameterEntity,
161 cdataBlock,
162 externalSubset,
163 0
164};
165
166/*
167 * The default SAX Locator.
168 */
169
170xmlSAXLocator xmlDefaultSAXLocator = {
171 getPublicId, getSystemId, getLineNumber, getColumnNumber
172};
173
174#ifdef LIBXML_HTML_ENABLED
175/*
176 * Default handler for HTML, builds the DOM tree
177 */
178xmlSAXHandler htmlDefaultSAXHandler = {
179 internalSubset,
180 NULL,
181 NULL,
182 NULL,
183 NULL,
184 getEntity,
185 NULL,
186 NULL,
187 NULL,
188 NULL,
189 NULL,
190 setDocumentLocator,
191 startDocument,
192 endDocument,
193 startElement,
194 endElement,
195 NULL,
196 characters,
197 ignorableWhitespace,
198 NULL,
199 comment,
200 xmlParserWarning,
201 xmlParserError,
202 xmlParserError,
203 getParameterEntity,
204 cdataBlock,
205 NULL,
206 0
207};
208#endif /* LIBXML_HTML_ENABLED */
209
210#ifdef LIBXML_DOCB_ENABLED
211/*
212 * Default handler for SGML DocBook, builds the DOM tree
213 */
214xmlSAXHandler docbDefaultSAXHandler = {
215 internalSubset,
216 isStandalone,
217 hasInternalSubset,
218 hasExternalSubset,
219 resolveEntity,
220 getEntity,
221 entityDecl,
222 NULL,
223 NULL,
224 NULL,
225 NULL,
226 setDocumentLocator,
227 startDocument,
228 endDocument,
229 startElement,
230 endElement,
231 reference,
232 characters,
233 ignorableWhitespace,
234 NULL,
235 comment,
236 xmlParserWarning,
237 xmlParserError,
238 xmlParserError,
239 getParameterEntity,
240 NULL,
241 NULL,
242 0
243};
244#endif /* LIBXML_DOCB_ENABLED */
245
246/**
247 * xmlInitializeGlobalState:
248 * @gs: a pointer to a newly allocated global state
249 *
250 * xmlInitializeGlobalState() initialize a global state with all the
251 * default values of the library.
252 */
253void
254xmlInitializeGlobalState(xmlGlobalStatePtr gs)
255{
Daniel Veillard3c01b1d2001-10-17 15:58:35 +0000256#ifdef DEBUG_GLOBALS
257 fprintf(stderr, "Initializing globals at %lu for thread %d\n",
258 (unsigned long) gs, xmlGetThreadId());
259#endif
260
Daniel Veillardb8478642001-10-12 17:29:10 +0000261 /*
262 * Perform initialisation as required by libxml
263 */
Daniel Veillard3c01b1d2001-10-17 15:58:35 +0000264 initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
Daniel Veillardb8478642001-10-12 17:29:10 +0000265 initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler);
266 inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler);
Daniel Veillard3c01b1d2001-10-17 15:58:35 +0000267 initGenericErrorDefaultFunc(&gs->xmlGenericError);
268
Daniel Veillardb8478642001-10-12 17:29:10 +0000269 gs->oldXMLWDcompatibility = 0;
270 gs->xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
271 gs->xmlDefaultBufferSize = BASE_BUFFER_SIZE;
272 initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
273 gs->xmlDefaultSAXLocator.getPublicId = getPublicId;
274 gs->xmlDefaultSAXLocator.getSystemId = getSystemId;
275 gs->xmlDefaultSAXLocator.getLineNumber = getLineNumber;
276 gs->xmlDefaultSAXLocator.getColumnNumber = getColumnNumber;
277 gs->xmlDoValidityCheckingDefaultValue = 0;
278#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
279 gs->xmlFree = (xmlFreeFunc) xmlMemFree;
280 gs->xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
281 gs->xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
282 gs->xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
283#else
284 gs->xmlFree = (xmlFreeFunc) free;
285 gs->xmlMalloc = (xmlMallocFunc) malloc;
286 gs->xmlRealloc = (xmlReallocFunc) realloc;
287 gs->xmlMemStrdup = (xmlStrdupFunc) strdup;
288#endif
Daniel Veillardb8478642001-10-12 17:29:10 +0000289 gs->xmlGenericErrorContext = NULL;
290 gs->xmlGetWarningsDefaultValue = 1;
291 gs->xmlIndentTreeOutput = 0;
292 gs->xmlKeepBlanksDefaultValue = 1;
293 gs->xmlLineNumbersDefaultValue = 0;
294 gs->xmlLoadExtDtdDefaultValue = 0;
295 gs->xmlParserDebugEntities = 0;
296 gs->xmlParserVersion = LIBXML_VERSION_STRING;
297 gs->xmlPedanticParserDefaultValue = 0;
298 gs->xmlSaveNoEmptyTags = 0;
299 gs->xmlSubstituteEntitiesDefaultValue = 0;
300}
301
302/*
303 * Everything starting from the line below is
304 * Automatically generated by build_glob.py.
305 * Do not modify the previous line.
306 */
307
308
309extern xmlSAXHandler docbDefaultSAXHandler;
310#undef docbDefaultSAXHandler
311xmlSAXHandler *
312__docbDefaultSAXHandler(void) {
313 if (IS_MAIN_THREAD)
314 return (&docbDefaultSAXHandler);
315 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000316 return (&xmlGetGlobalState()->docbDefaultSAXHandler);
Daniel Veillardb8478642001-10-12 17:29:10 +0000317}
318
319extern xmlSAXHandler htmlDefaultSAXHandler;
320#undef htmlDefaultSAXHandler
321xmlSAXHandler *
322__htmlDefaultSAXHandler(void) {
323 if (IS_MAIN_THREAD)
324 return (&htmlDefaultSAXHandler);
325 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000326 return (&xmlGetGlobalState()->htmlDefaultSAXHandler);
Daniel Veillardb8478642001-10-12 17:29:10 +0000327}
328
329extern int oldXMLWDcompatibility;
330#undef oldXMLWDcompatibility
331int *
332__oldXMLWDcompatibility(void) {
333 if (IS_MAIN_THREAD)
334 return (&oldXMLWDcompatibility);
335 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000336 return (&xmlGetGlobalState()->oldXMLWDcompatibility);
Daniel Veillardb8478642001-10-12 17:29:10 +0000337}
338
339extern xmlBufferAllocationScheme xmlBufferAllocScheme;
340#undef xmlBufferAllocScheme
341xmlBufferAllocationScheme *
342__xmlBufferAllocScheme(void) {
343 if (IS_MAIN_THREAD)
344 return (&xmlBufferAllocScheme);
345 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000346 return (&xmlGetGlobalState()->xmlBufferAllocScheme);
Daniel Veillardb8478642001-10-12 17:29:10 +0000347}
348
349extern int xmlDefaultBufferSize;
350#undef xmlDefaultBufferSize
351int *
352__xmlDefaultBufferSize(void) {
353 if (IS_MAIN_THREAD)
354 return (&xmlDefaultBufferSize);
355 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000356 return (&xmlGetGlobalState()->xmlDefaultBufferSize);
Daniel Veillardb8478642001-10-12 17:29:10 +0000357}
358
359extern xmlSAXHandler xmlDefaultSAXHandler;
360#undef xmlDefaultSAXHandler
361xmlSAXHandler *
362__xmlDefaultSAXHandler(void) {
363 if (IS_MAIN_THREAD)
364 return (&xmlDefaultSAXHandler);
365 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000366 return (&xmlGetGlobalState()->xmlDefaultSAXHandler);
Daniel Veillardb8478642001-10-12 17:29:10 +0000367}
368
369extern xmlSAXLocator xmlDefaultSAXLocator;
370#undef xmlDefaultSAXLocator
371xmlSAXLocator *
372__xmlDefaultSAXLocator(void) {
373 if (IS_MAIN_THREAD)
374 return (&xmlDefaultSAXLocator);
375 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000376 return (&xmlGetGlobalState()->xmlDefaultSAXLocator);
Daniel Veillardb8478642001-10-12 17:29:10 +0000377}
378
379extern int xmlDoValidityCheckingDefaultValue;
380#undef xmlDoValidityCheckingDefaultValue
381int *
382__xmlDoValidityCheckingDefaultValue(void) {
383 if (IS_MAIN_THREAD)
384 return (&xmlDoValidityCheckingDefaultValue);
385 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000386 return (&xmlGetGlobalState()->xmlDoValidityCheckingDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000387}
388
389extern xmlFreeFunc xmlFree;
390#undef xmlFree
391xmlFreeFunc *
392__xmlFree(void) {
393 if (IS_MAIN_THREAD)
394 return (&xmlFree);
395 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000396 return (&xmlGetGlobalState()->xmlFree);
Daniel Veillardb8478642001-10-12 17:29:10 +0000397}
398
399extern xmlGenericErrorFunc xmlGenericError;
400#undef xmlGenericError
401xmlGenericErrorFunc *
402__xmlGenericError(void) {
403 if (IS_MAIN_THREAD)
404 return (&xmlGenericError);
405 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000406 return (&xmlGetGlobalState()->xmlGenericError);
Daniel Veillardb8478642001-10-12 17:29:10 +0000407}
408
409extern void * xmlGenericErrorContext;
410#undef xmlGenericErrorContext
411void * *
412__xmlGenericErrorContext(void) {
413 if (IS_MAIN_THREAD)
414 return (&xmlGenericErrorContext);
415 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000416 return (&xmlGetGlobalState()->xmlGenericErrorContext);
Daniel Veillardb8478642001-10-12 17:29:10 +0000417}
418
419extern int xmlGetWarningsDefaultValue;
420#undef xmlGetWarningsDefaultValue
421int *
422__xmlGetWarningsDefaultValue(void) {
423 if (IS_MAIN_THREAD)
424 return (&xmlGetWarningsDefaultValue);
425 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000426 return (&xmlGetGlobalState()->xmlGetWarningsDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000427}
428
429extern int xmlIndentTreeOutput;
430#undef xmlIndentTreeOutput
431int *
432__xmlIndentTreeOutput(void) {
433 if (IS_MAIN_THREAD)
434 return (&xmlIndentTreeOutput);
435 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000436 return (&xmlGetGlobalState()->xmlIndentTreeOutput);
Daniel Veillardb8478642001-10-12 17:29:10 +0000437}
438
439extern int xmlKeepBlanksDefaultValue;
440#undef xmlKeepBlanksDefaultValue
441int *
442__xmlKeepBlanksDefaultValue(void) {
443 if (IS_MAIN_THREAD)
444 return (&xmlKeepBlanksDefaultValue);
445 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000446 return (&xmlGetGlobalState()->xmlKeepBlanksDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000447}
448
449extern int xmlLineNumbersDefaultValue;
450#undef xmlLineNumbersDefaultValue
451int *
452__xmlLineNumbersDefaultValue(void) {
453 if (IS_MAIN_THREAD)
454 return (&xmlLineNumbersDefaultValue);
455 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000456 return (&xmlGetGlobalState()->xmlLineNumbersDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000457}
458
459extern int xmlLoadExtDtdDefaultValue;
460#undef xmlLoadExtDtdDefaultValue
461int *
462__xmlLoadExtDtdDefaultValue(void) {
463 if (IS_MAIN_THREAD)
464 return (&xmlLoadExtDtdDefaultValue);
465 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000466 return (&xmlGetGlobalState()->xmlLoadExtDtdDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000467}
468
469extern xmlMallocFunc xmlMalloc;
470#undef xmlMalloc
471xmlMallocFunc *
472__xmlMalloc(void) {
473 if (IS_MAIN_THREAD)
474 return (&xmlMalloc);
475 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000476 return (&xmlGetGlobalState()->xmlMalloc);
Daniel Veillardb8478642001-10-12 17:29:10 +0000477}
478
479extern xmlStrdupFunc xmlMemStrdup;
480#undef xmlMemStrdup
481xmlStrdupFunc *
482__xmlMemStrdup(void) {
483 if (IS_MAIN_THREAD)
484 return (&xmlMemStrdup);
485 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000486 return (&xmlGetGlobalState()->xmlMemStrdup);
Daniel Veillardb8478642001-10-12 17:29:10 +0000487}
488
489extern int xmlParserDebugEntities;
490#undef xmlParserDebugEntities
491int *
492__xmlParserDebugEntities(void) {
493 if (IS_MAIN_THREAD)
494 return (&xmlParserDebugEntities);
495 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000496 return (&xmlGetGlobalState()->xmlParserDebugEntities);
Daniel Veillardb8478642001-10-12 17:29:10 +0000497}
498
499extern const char * xmlParserVersion;
500#undef xmlParserVersion
501const char * *
502__xmlParserVersion(void) {
503 if (IS_MAIN_THREAD)
504 return (&xmlParserVersion);
505 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000506 return (&xmlGetGlobalState()->xmlParserVersion);
Daniel Veillardb8478642001-10-12 17:29:10 +0000507}
508
509extern int xmlPedanticParserDefaultValue;
510#undef xmlPedanticParserDefaultValue
511int *
512__xmlPedanticParserDefaultValue(void) {
513 if (IS_MAIN_THREAD)
514 return (&xmlPedanticParserDefaultValue);
515 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000516 return (&xmlGetGlobalState()->xmlPedanticParserDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000517}
518
519extern xmlReallocFunc xmlRealloc;
520#undef xmlRealloc
521xmlReallocFunc *
522__xmlRealloc(void) {
523 if (IS_MAIN_THREAD)
524 return (&xmlRealloc);
525 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000526 return (&xmlGetGlobalState()->xmlRealloc);
Daniel Veillardb8478642001-10-12 17:29:10 +0000527}
528
529extern int xmlSaveNoEmptyTags;
530#undef xmlSaveNoEmptyTags
531int *
532__xmlSaveNoEmptyTags(void) {
533 if (IS_MAIN_THREAD)
534 return (&xmlSaveNoEmptyTags);
535 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000536 return (&xmlGetGlobalState()->xmlSaveNoEmptyTags);
Daniel Veillardb8478642001-10-12 17:29:10 +0000537}
538
539extern int xmlSubstituteEntitiesDefaultValue;
540#undef xmlSubstituteEntitiesDefaultValue
541int *
542__xmlSubstituteEntitiesDefaultValue(void) {
543 if (IS_MAIN_THREAD)
544 return (&xmlSubstituteEntitiesDefaultValue);
545 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000546 return (&xmlGetGlobalState()->xmlSubstituteEntitiesDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000547}