blob: cfa5ca662deaf833737564c12524b77466177c95 [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 */
120xmlGenericErrorFunc xmlGenericError;
121void *xmlGenericErrorContext = NULL;
122
123/*
124 * output defaults
125 */
126int xmlIndentTreeOutput = 0;
127int xmlSaveNoEmptyTags = 0;
128
129/*
130 * Default handler for XML, builds the DOM tree
131 */
132xmlSAXHandler xmlDefaultSAXHandler = {
133 internalSubset,
134 isStandalone,
135 hasInternalSubset,
136 hasExternalSubset,
137 resolveEntity,
138 getEntity,
139 entityDecl,
140 notationDecl,
141 attributeDecl,
142 elementDecl,
143 unparsedEntityDecl,
144 setDocumentLocator,
145 startDocument,
146 endDocument,
147 startElement,
148 endElement,
149 reference,
150 characters,
151 characters,
152 processingInstruction,
153 comment,
154 xmlParserWarning,
155 xmlParserError,
156 xmlParserError,
157 getParameterEntity,
158 cdataBlock,
159 externalSubset,
160 0
161};
162
163/*
164 * The default SAX Locator.
165 */
166
167xmlSAXLocator xmlDefaultSAXLocator = {
168 getPublicId, getSystemId, getLineNumber, getColumnNumber
169};
170
171#ifdef LIBXML_HTML_ENABLED
172/*
173 * Default handler for HTML, builds the DOM tree
174 */
175xmlSAXHandler htmlDefaultSAXHandler = {
176 internalSubset,
177 NULL,
178 NULL,
179 NULL,
180 NULL,
181 getEntity,
182 NULL,
183 NULL,
184 NULL,
185 NULL,
186 NULL,
187 setDocumentLocator,
188 startDocument,
189 endDocument,
190 startElement,
191 endElement,
192 NULL,
193 characters,
194 ignorableWhitespace,
195 NULL,
196 comment,
197 xmlParserWarning,
198 xmlParserError,
199 xmlParserError,
200 getParameterEntity,
201 cdataBlock,
202 NULL,
203 0
204};
205#endif /* LIBXML_HTML_ENABLED */
206
207#ifdef LIBXML_DOCB_ENABLED
208/*
209 * Default handler for SGML DocBook, builds the DOM tree
210 */
211xmlSAXHandler docbDefaultSAXHandler = {
212 internalSubset,
213 isStandalone,
214 hasInternalSubset,
215 hasExternalSubset,
216 resolveEntity,
217 getEntity,
218 entityDecl,
219 NULL,
220 NULL,
221 NULL,
222 NULL,
223 setDocumentLocator,
224 startDocument,
225 endDocument,
226 startElement,
227 endElement,
228 reference,
229 characters,
230 ignorableWhitespace,
231 NULL,
232 comment,
233 xmlParserWarning,
234 xmlParserError,
235 xmlParserError,
236 getParameterEntity,
237 NULL,
238 NULL,
239 0
240};
241#endif /* LIBXML_DOCB_ENABLED */
242
243/**
244 * xmlInitializeGlobalState:
245 * @gs: a pointer to a newly allocated global state
246 *
247 * xmlInitializeGlobalState() initialize a global state with all the
248 * default values of the library.
249 */
250void
251xmlInitializeGlobalState(xmlGlobalStatePtr gs)
252{
Daniel Veillard3c01b1d2001-10-17 15:58:35 +0000253#ifdef DEBUG_GLOBALS
254 fprintf(stderr, "Initializing globals at %lu for thread %d\n",
255 (unsigned long) gs, xmlGetThreadId());
256#endif
257
Daniel Veillardb8478642001-10-12 17:29:10 +0000258 /*
259 * Perform initialisation as required by libxml
260 */
Daniel Veillard3c01b1d2001-10-17 15:58:35 +0000261 initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
Daniel Veillardb8478642001-10-12 17:29:10 +0000262 initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler);
263 inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler);
Daniel Veillard3c01b1d2001-10-17 15:58:35 +0000264 initGenericErrorDefaultFunc(&gs->xmlGenericError);
265
Daniel Veillardb8478642001-10-12 17:29:10 +0000266 gs->oldXMLWDcompatibility = 0;
267 gs->xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
268 gs->xmlDefaultBufferSize = BASE_BUFFER_SIZE;
269 initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
270 gs->xmlDefaultSAXLocator.getPublicId = getPublicId;
271 gs->xmlDefaultSAXLocator.getSystemId = getSystemId;
272 gs->xmlDefaultSAXLocator.getLineNumber = getLineNumber;
273 gs->xmlDefaultSAXLocator.getColumnNumber = getColumnNumber;
274 gs->xmlDoValidityCheckingDefaultValue = 0;
275#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
276 gs->xmlFree = (xmlFreeFunc) xmlMemFree;
277 gs->xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
278 gs->xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
279 gs->xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
280#else
281 gs->xmlFree = (xmlFreeFunc) free;
282 gs->xmlMalloc = (xmlMallocFunc) malloc;
283 gs->xmlRealloc = (xmlReallocFunc) realloc;
284 gs->xmlMemStrdup = (xmlStrdupFunc) strdup;
285#endif
Daniel Veillardb8478642001-10-12 17:29:10 +0000286 gs->xmlGenericErrorContext = NULL;
287 gs->xmlGetWarningsDefaultValue = 1;
288 gs->xmlIndentTreeOutput = 0;
289 gs->xmlKeepBlanksDefaultValue = 1;
290 gs->xmlLineNumbersDefaultValue = 0;
291 gs->xmlLoadExtDtdDefaultValue = 0;
292 gs->xmlParserDebugEntities = 0;
293 gs->xmlParserVersion = LIBXML_VERSION_STRING;
294 gs->xmlPedanticParserDefaultValue = 0;
295 gs->xmlSaveNoEmptyTags = 0;
296 gs->xmlSubstituteEntitiesDefaultValue = 0;
297}
298
299/*
300 * Everything starting from the line below is
301 * Automatically generated by build_glob.py.
302 * Do not modify the previous line.
303 */
304
305
306extern xmlSAXHandler docbDefaultSAXHandler;
307#undef docbDefaultSAXHandler
308xmlSAXHandler *
309__docbDefaultSAXHandler(void) {
310 if (IS_MAIN_THREAD)
311 return (&docbDefaultSAXHandler);
312 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000313 return (&xmlGetGlobalState()->docbDefaultSAXHandler);
Daniel Veillardb8478642001-10-12 17:29:10 +0000314}
315
316extern xmlSAXHandler htmlDefaultSAXHandler;
317#undef htmlDefaultSAXHandler
318xmlSAXHandler *
319__htmlDefaultSAXHandler(void) {
320 if (IS_MAIN_THREAD)
321 return (&htmlDefaultSAXHandler);
322 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000323 return (&xmlGetGlobalState()->htmlDefaultSAXHandler);
Daniel Veillardb8478642001-10-12 17:29:10 +0000324}
325
326extern int oldXMLWDcompatibility;
327#undef oldXMLWDcompatibility
328int *
329__oldXMLWDcompatibility(void) {
330 if (IS_MAIN_THREAD)
331 return (&oldXMLWDcompatibility);
332 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000333 return (&xmlGetGlobalState()->oldXMLWDcompatibility);
Daniel Veillardb8478642001-10-12 17:29:10 +0000334}
335
336extern xmlBufferAllocationScheme xmlBufferAllocScheme;
337#undef xmlBufferAllocScheme
338xmlBufferAllocationScheme *
339__xmlBufferAllocScheme(void) {
340 if (IS_MAIN_THREAD)
341 return (&xmlBufferAllocScheme);
342 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000343 return (&xmlGetGlobalState()->xmlBufferAllocScheme);
Daniel Veillardb8478642001-10-12 17:29:10 +0000344}
345
346extern int xmlDefaultBufferSize;
347#undef xmlDefaultBufferSize
348int *
349__xmlDefaultBufferSize(void) {
350 if (IS_MAIN_THREAD)
351 return (&xmlDefaultBufferSize);
352 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000353 return (&xmlGetGlobalState()->xmlDefaultBufferSize);
Daniel Veillardb8478642001-10-12 17:29:10 +0000354}
355
356extern xmlSAXHandler xmlDefaultSAXHandler;
357#undef xmlDefaultSAXHandler
358xmlSAXHandler *
359__xmlDefaultSAXHandler(void) {
360 if (IS_MAIN_THREAD)
361 return (&xmlDefaultSAXHandler);
362 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000363 return (&xmlGetGlobalState()->xmlDefaultSAXHandler);
Daniel Veillardb8478642001-10-12 17:29:10 +0000364}
365
366extern xmlSAXLocator xmlDefaultSAXLocator;
367#undef xmlDefaultSAXLocator
368xmlSAXLocator *
369__xmlDefaultSAXLocator(void) {
370 if (IS_MAIN_THREAD)
371 return (&xmlDefaultSAXLocator);
372 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000373 return (&xmlGetGlobalState()->xmlDefaultSAXLocator);
Daniel Veillardb8478642001-10-12 17:29:10 +0000374}
375
376extern int xmlDoValidityCheckingDefaultValue;
377#undef xmlDoValidityCheckingDefaultValue
378int *
379__xmlDoValidityCheckingDefaultValue(void) {
380 if (IS_MAIN_THREAD)
381 return (&xmlDoValidityCheckingDefaultValue);
382 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000383 return (&xmlGetGlobalState()->xmlDoValidityCheckingDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000384}
385
386extern xmlFreeFunc xmlFree;
387#undef xmlFree
388xmlFreeFunc *
389__xmlFree(void) {
390 if (IS_MAIN_THREAD)
391 return (&xmlFree);
392 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000393 return (&xmlGetGlobalState()->xmlFree);
Daniel Veillardb8478642001-10-12 17:29:10 +0000394}
395
396extern xmlGenericErrorFunc xmlGenericError;
397#undef xmlGenericError
398xmlGenericErrorFunc *
399__xmlGenericError(void) {
400 if (IS_MAIN_THREAD)
401 return (&xmlGenericError);
402 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000403 return (&xmlGetGlobalState()->xmlGenericError);
Daniel Veillardb8478642001-10-12 17:29:10 +0000404}
405
406extern void * xmlGenericErrorContext;
407#undef xmlGenericErrorContext
408void * *
409__xmlGenericErrorContext(void) {
410 if (IS_MAIN_THREAD)
411 return (&xmlGenericErrorContext);
412 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000413 return (&xmlGetGlobalState()->xmlGenericErrorContext);
Daniel Veillardb8478642001-10-12 17:29:10 +0000414}
415
416extern int xmlGetWarningsDefaultValue;
417#undef xmlGetWarningsDefaultValue
418int *
419__xmlGetWarningsDefaultValue(void) {
420 if (IS_MAIN_THREAD)
421 return (&xmlGetWarningsDefaultValue);
422 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000423 return (&xmlGetGlobalState()->xmlGetWarningsDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000424}
425
426extern int xmlIndentTreeOutput;
427#undef xmlIndentTreeOutput
428int *
429__xmlIndentTreeOutput(void) {
430 if (IS_MAIN_THREAD)
431 return (&xmlIndentTreeOutput);
432 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000433 return (&xmlGetGlobalState()->xmlIndentTreeOutput);
Daniel Veillardb8478642001-10-12 17:29:10 +0000434}
435
436extern int xmlKeepBlanksDefaultValue;
437#undef xmlKeepBlanksDefaultValue
438int *
439__xmlKeepBlanksDefaultValue(void) {
440 if (IS_MAIN_THREAD)
441 return (&xmlKeepBlanksDefaultValue);
442 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000443 return (&xmlGetGlobalState()->xmlKeepBlanksDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000444}
445
446extern int xmlLineNumbersDefaultValue;
447#undef xmlLineNumbersDefaultValue
448int *
449__xmlLineNumbersDefaultValue(void) {
450 if (IS_MAIN_THREAD)
451 return (&xmlLineNumbersDefaultValue);
452 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000453 return (&xmlGetGlobalState()->xmlLineNumbersDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000454}
455
456extern int xmlLoadExtDtdDefaultValue;
457#undef xmlLoadExtDtdDefaultValue
458int *
459__xmlLoadExtDtdDefaultValue(void) {
460 if (IS_MAIN_THREAD)
461 return (&xmlLoadExtDtdDefaultValue);
462 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000463 return (&xmlGetGlobalState()->xmlLoadExtDtdDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000464}
465
466extern xmlMallocFunc xmlMalloc;
467#undef xmlMalloc
468xmlMallocFunc *
469__xmlMalloc(void) {
470 if (IS_MAIN_THREAD)
471 return (&xmlMalloc);
472 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000473 return (&xmlGetGlobalState()->xmlMalloc);
Daniel Veillardb8478642001-10-12 17:29:10 +0000474}
475
476extern xmlStrdupFunc xmlMemStrdup;
477#undef xmlMemStrdup
478xmlStrdupFunc *
479__xmlMemStrdup(void) {
480 if (IS_MAIN_THREAD)
481 return (&xmlMemStrdup);
482 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000483 return (&xmlGetGlobalState()->xmlMemStrdup);
Daniel Veillardb8478642001-10-12 17:29:10 +0000484}
485
486extern int xmlParserDebugEntities;
487#undef xmlParserDebugEntities
488int *
489__xmlParserDebugEntities(void) {
490 if (IS_MAIN_THREAD)
491 return (&xmlParserDebugEntities);
492 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000493 return (&xmlGetGlobalState()->xmlParserDebugEntities);
Daniel Veillardb8478642001-10-12 17:29:10 +0000494}
495
496extern const char * xmlParserVersion;
497#undef xmlParserVersion
498const char * *
499__xmlParserVersion(void) {
500 if (IS_MAIN_THREAD)
501 return (&xmlParserVersion);
502 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000503 return (&xmlGetGlobalState()->xmlParserVersion);
Daniel Veillardb8478642001-10-12 17:29:10 +0000504}
505
506extern int xmlPedanticParserDefaultValue;
507#undef xmlPedanticParserDefaultValue
508int *
509__xmlPedanticParserDefaultValue(void) {
510 if (IS_MAIN_THREAD)
511 return (&xmlPedanticParserDefaultValue);
512 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000513 return (&xmlGetGlobalState()->xmlPedanticParserDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000514}
515
516extern xmlReallocFunc xmlRealloc;
517#undef xmlRealloc
518xmlReallocFunc *
519__xmlRealloc(void) {
520 if (IS_MAIN_THREAD)
521 return (&xmlRealloc);
522 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000523 return (&xmlGetGlobalState()->xmlRealloc);
Daniel Veillardb8478642001-10-12 17:29:10 +0000524}
525
526extern int xmlSaveNoEmptyTags;
527#undef xmlSaveNoEmptyTags
528int *
529__xmlSaveNoEmptyTags(void) {
530 if (IS_MAIN_THREAD)
531 return (&xmlSaveNoEmptyTags);
532 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000533 return (&xmlGetGlobalState()->xmlSaveNoEmptyTags);
Daniel Veillardb8478642001-10-12 17:29:10 +0000534}
535
536extern int xmlSubstituteEntitiesDefaultValue;
537#undef xmlSubstituteEntitiesDefaultValue
538int *
539__xmlSubstituteEntitiesDefaultValue(void) {
540 if (IS_MAIN_THREAD)
541 return (&xmlSubstituteEntitiesDefaultValue);
542 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000543 return (&xmlGetGlobalState()->xmlSubstituteEntitiesDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000544}