blob: 2a899e079c815104c5e02549c642b55a3352d740 [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 Veillardd0463562001-10-13 09:15:48 +000016#include <libxml/xmlmemory.h>
Daniel Veillardb8478642001-10-12 17:29:10 +000017
Jaka Mocnik77d19ae2001-10-13 12:06:09 +000018#include <stdlib.h>
19#include <string.h>
20
Daniel Veillardb8478642001-10-12 17:29:10 +000021/*
22 * Helpful Macro
23 */
24#ifdef WITH_PTHREAD_H
25#if defined(SOLARIS)
26#define THR_MAIN(tid) (-1 == thr_main() || tid == thr_main())
27#else
28#define THR_MAIN(tid) (tid == 0 || tid == 1024)
29#endif
30
31#define IS_MAIN_THREAD (THR_MAIN(pthread_self()))
32#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
42const char *xmlParserVersion = LIBXML_VERSION_STRING;
Daniel Veillardd0463562001-10-13 09:15:48 +000043
Daniel Veillardb8478642001-10-12 17:29:10 +000044/*
45 * Memory allocation routines
46 */
47#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
Daniel Veillardd0463562001-10-13 09:15:48 +000048extern void xmlMemFree(void *ptr);
49extern void * xmlMemMalloc(size_t size);
50extern void * xmlMemRealloc(void *ptr,size_t size);
51extern char * xmlMemoryStrdup(const char *str);
52
Daniel Veillardb8478642001-10-12 17:29:10 +000053xmlFreeFunc xmlFree = (xmlFreeFunc) xmlMemFree;
54xmlMallocFunc xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
55xmlReallocFunc xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
56xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
57#else
58xmlFreeFunc xmlFree = (xmlFreeFunc) free;
59xmlMallocFunc xmlMalloc = (xmlMallocFunc) malloc;
60xmlReallocFunc xmlRealloc = (xmlReallocFunc) realloc;
61xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) strdup;
62#endif
63
Daniel Veillardd0463562001-10-13 09:15:48 +000064#include <libxml/threads.h>
65#include <libxml/globals.h>
66#include <libxml/SAX.h>
67
68#undef docbDefaultSAXHandler
69#undef htmlDefaultSAXHandler
70#undef oldXMLWDcompatibility
71#undef xmlBufferAllocScheme
72#undef xmlDefaultBufferSize
73#undef xmlDefaultSAXHandler
74#undef xmlDefaultSAXLocator
75#undef xmlDoValidityCheckingDefaultValue
76#undef xmlGenericError
77#undef xmlGenericErrorContext
78#undef xmlGetWarningsDefaultValue
79#undef xmlIndentTreeOutput
80#undef xmlKeepBlanksDefaultValue
81#undef xmlLineNumbersDefaultValue
82#undef xmlLoadExtDtdDefaultValue
83#undef xmlParserDebugEntities
84#undef xmlParserVersion
85#undef xmlPedanticParserDefaultValue
86#undef xmlSaveNoEmptyTags
87#undef xmlSubstituteEntitiesDefaultValue
88
89#undef xmlFree
90#undef xmlMalloc
91#undef xmlMemStrdup
92#undef xmlRealloc
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{
253 /*
254 * Perform initialisation as required by libxml
255 */
256 initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler);
257 inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler);
258 gs->oldXMLWDcompatibility = 0;
259 gs->xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
260 gs->xmlDefaultBufferSize = BASE_BUFFER_SIZE;
261 initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
262 gs->xmlDefaultSAXLocator.getPublicId = getPublicId;
263 gs->xmlDefaultSAXLocator.getSystemId = getSystemId;
264 gs->xmlDefaultSAXLocator.getLineNumber = getLineNumber;
265 gs->xmlDefaultSAXLocator.getColumnNumber = getColumnNumber;
266 gs->xmlDoValidityCheckingDefaultValue = 0;
267#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
268 gs->xmlFree = (xmlFreeFunc) xmlMemFree;
269 gs->xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
270 gs->xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
271 gs->xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
272#else
273 gs->xmlFree = (xmlFreeFunc) free;
274 gs->xmlMalloc = (xmlMallocFunc) malloc;
275 gs->xmlRealloc = (xmlReallocFunc) realloc;
276 gs->xmlMemStrdup = (xmlStrdupFunc) strdup;
277#endif
278 initGenericErrorDefaultFunc(&gs->xmlGenericError);
279 gs->xmlGenericErrorContext = NULL;
280 gs->xmlGetWarningsDefaultValue = 1;
281 gs->xmlIndentTreeOutput = 0;
282 gs->xmlKeepBlanksDefaultValue = 1;
283 gs->xmlLineNumbersDefaultValue = 0;
284 gs->xmlLoadExtDtdDefaultValue = 0;
285 gs->xmlParserDebugEntities = 0;
286 gs->xmlParserVersion = LIBXML_VERSION_STRING;
287 gs->xmlPedanticParserDefaultValue = 0;
288 gs->xmlSaveNoEmptyTags = 0;
289 gs->xmlSubstituteEntitiesDefaultValue = 0;
290}
291
292/*
293 * Everything starting from the line below is
294 * Automatically generated by build_glob.py.
295 * Do not modify the previous line.
296 */
297
298
299extern xmlSAXHandler docbDefaultSAXHandler;
300#undef docbDefaultSAXHandler
301xmlSAXHandler *
302__docbDefaultSAXHandler(void) {
303 if (IS_MAIN_THREAD)
304 return (&docbDefaultSAXHandler);
305 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000306 return (&xmlGetGlobalState()->docbDefaultSAXHandler);
Daniel Veillardb8478642001-10-12 17:29:10 +0000307}
308
309extern xmlSAXHandler htmlDefaultSAXHandler;
310#undef htmlDefaultSAXHandler
311xmlSAXHandler *
312__htmlDefaultSAXHandler(void) {
313 if (IS_MAIN_THREAD)
314 return (&htmlDefaultSAXHandler);
315 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000316 return (&xmlGetGlobalState()->htmlDefaultSAXHandler);
Daniel Veillardb8478642001-10-12 17:29:10 +0000317}
318
319extern int oldXMLWDcompatibility;
320#undef oldXMLWDcompatibility
321int *
322__oldXMLWDcompatibility(void) {
323 if (IS_MAIN_THREAD)
324 return (&oldXMLWDcompatibility);
325 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000326 return (&xmlGetGlobalState()->oldXMLWDcompatibility);
Daniel Veillardb8478642001-10-12 17:29:10 +0000327}
328
329extern xmlBufferAllocationScheme xmlBufferAllocScheme;
330#undef xmlBufferAllocScheme
331xmlBufferAllocationScheme *
332__xmlBufferAllocScheme(void) {
333 if (IS_MAIN_THREAD)
334 return (&xmlBufferAllocScheme);
335 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000336 return (&xmlGetGlobalState()->xmlBufferAllocScheme);
Daniel Veillardb8478642001-10-12 17:29:10 +0000337}
338
339extern int xmlDefaultBufferSize;
340#undef xmlDefaultBufferSize
341int *
342__xmlDefaultBufferSize(void) {
343 if (IS_MAIN_THREAD)
344 return (&xmlDefaultBufferSize);
345 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000346 return (&xmlGetGlobalState()->xmlDefaultBufferSize);
Daniel Veillardb8478642001-10-12 17:29:10 +0000347}
348
349extern xmlSAXHandler xmlDefaultSAXHandler;
350#undef xmlDefaultSAXHandler
351xmlSAXHandler *
352__xmlDefaultSAXHandler(void) {
353 if (IS_MAIN_THREAD)
354 return (&xmlDefaultSAXHandler);
355 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000356 return (&xmlGetGlobalState()->xmlDefaultSAXHandler);
Daniel Veillardb8478642001-10-12 17:29:10 +0000357}
358
359extern xmlSAXLocator xmlDefaultSAXLocator;
360#undef xmlDefaultSAXLocator
361xmlSAXLocator *
362__xmlDefaultSAXLocator(void) {
363 if (IS_MAIN_THREAD)
364 return (&xmlDefaultSAXLocator);
365 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000366 return (&xmlGetGlobalState()->xmlDefaultSAXLocator);
Daniel Veillardb8478642001-10-12 17:29:10 +0000367}
368
369extern int xmlDoValidityCheckingDefaultValue;
370#undef xmlDoValidityCheckingDefaultValue
371int *
372__xmlDoValidityCheckingDefaultValue(void) {
373 if (IS_MAIN_THREAD)
374 return (&xmlDoValidityCheckingDefaultValue);
375 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000376 return (&xmlGetGlobalState()->xmlDoValidityCheckingDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000377}
378
379extern xmlFreeFunc xmlFree;
380#undef xmlFree
381xmlFreeFunc *
382__xmlFree(void) {
383 if (IS_MAIN_THREAD)
384 return (&xmlFree);
385 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000386 return (&xmlGetGlobalState()->xmlFree);
Daniel Veillardb8478642001-10-12 17:29:10 +0000387}
388
389extern xmlGenericErrorFunc xmlGenericError;
390#undef xmlGenericError
391xmlGenericErrorFunc *
392__xmlGenericError(void) {
393 if (IS_MAIN_THREAD)
394 return (&xmlGenericError);
395 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000396 return (&xmlGetGlobalState()->xmlGenericError);
Daniel Veillardb8478642001-10-12 17:29:10 +0000397}
398
399extern void * xmlGenericErrorContext;
400#undef xmlGenericErrorContext
401void * *
402__xmlGenericErrorContext(void) {
403 if (IS_MAIN_THREAD)
404 return (&xmlGenericErrorContext);
405 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000406 return (&xmlGetGlobalState()->xmlGenericErrorContext);
Daniel Veillardb8478642001-10-12 17:29:10 +0000407}
408
409extern int xmlGetWarningsDefaultValue;
410#undef xmlGetWarningsDefaultValue
411int *
412__xmlGetWarningsDefaultValue(void) {
413 if (IS_MAIN_THREAD)
414 return (&xmlGetWarningsDefaultValue);
415 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000416 return (&xmlGetGlobalState()->xmlGetWarningsDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000417}
418
419extern int xmlIndentTreeOutput;
420#undef xmlIndentTreeOutput
421int *
422__xmlIndentTreeOutput(void) {
423 if (IS_MAIN_THREAD)
424 return (&xmlIndentTreeOutput);
425 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000426 return (&xmlGetGlobalState()->xmlIndentTreeOutput);
Daniel Veillardb8478642001-10-12 17:29:10 +0000427}
428
429extern int xmlKeepBlanksDefaultValue;
430#undef xmlKeepBlanksDefaultValue
431int *
432__xmlKeepBlanksDefaultValue(void) {
433 if (IS_MAIN_THREAD)
434 return (&xmlKeepBlanksDefaultValue);
435 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000436 return (&xmlGetGlobalState()->xmlKeepBlanksDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000437}
438
439extern int xmlLineNumbersDefaultValue;
440#undef xmlLineNumbersDefaultValue
441int *
442__xmlLineNumbersDefaultValue(void) {
443 if (IS_MAIN_THREAD)
444 return (&xmlLineNumbersDefaultValue);
445 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000446 return (&xmlGetGlobalState()->xmlLineNumbersDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000447}
448
449extern int xmlLoadExtDtdDefaultValue;
450#undef xmlLoadExtDtdDefaultValue
451int *
452__xmlLoadExtDtdDefaultValue(void) {
453 if (IS_MAIN_THREAD)
454 return (&xmlLoadExtDtdDefaultValue);
455 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000456 return (&xmlGetGlobalState()->xmlLoadExtDtdDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000457}
458
459extern xmlMallocFunc xmlMalloc;
460#undef xmlMalloc
461xmlMallocFunc *
462__xmlMalloc(void) {
463 if (IS_MAIN_THREAD)
464 return (&xmlMalloc);
465 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000466 return (&xmlGetGlobalState()->xmlMalloc);
Daniel Veillardb8478642001-10-12 17:29:10 +0000467}
468
469extern xmlStrdupFunc xmlMemStrdup;
470#undef xmlMemStrdup
471xmlStrdupFunc *
472__xmlMemStrdup(void) {
473 if (IS_MAIN_THREAD)
474 return (&xmlMemStrdup);
475 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000476 return (&xmlGetGlobalState()->xmlMemStrdup);
Daniel Veillardb8478642001-10-12 17:29:10 +0000477}
478
479extern int xmlParserDebugEntities;
480#undef xmlParserDebugEntities
481int *
482__xmlParserDebugEntities(void) {
483 if (IS_MAIN_THREAD)
484 return (&xmlParserDebugEntities);
485 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000486 return (&xmlGetGlobalState()->xmlParserDebugEntities);
Daniel Veillardb8478642001-10-12 17:29:10 +0000487}
488
489extern const char * xmlParserVersion;
490#undef xmlParserVersion
491const char * *
492__xmlParserVersion(void) {
493 if (IS_MAIN_THREAD)
494 return (&xmlParserVersion);
495 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000496 return (&xmlGetGlobalState()->xmlParserVersion);
Daniel Veillardb8478642001-10-12 17:29:10 +0000497}
498
499extern int xmlPedanticParserDefaultValue;
500#undef xmlPedanticParserDefaultValue
501int *
502__xmlPedanticParserDefaultValue(void) {
503 if (IS_MAIN_THREAD)
504 return (&xmlPedanticParserDefaultValue);
505 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000506 return (&xmlGetGlobalState()->xmlPedanticParserDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000507}
508
509extern xmlReallocFunc xmlRealloc;
510#undef xmlRealloc
511xmlReallocFunc *
512__xmlRealloc(void) {
513 if (IS_MAIN_THREAD)
514 return (&xmlRealloc);
515 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000516 return (&xmlGetGlobalState()->xmlRealloc);
Daniel Veillardb8478642001-10-12 17:29:10 +0000517}
518
519extern int xmlSaveNoEmptyTags;
520#undef xmlSaveNoEmptyTags
521int *
522__xmlSaveNoEmptyTags(void) {
523 if (IS_MAIN_THREAD)
524 return (&xmlSaveNoEmptyTags);
525 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000526 return (&xmlGetGlobalState()->xmlSaveNoEmptyTags);
Daniel Veillardb8478642001-10-12 17:29:10 +0000527}
528
529extern int xmlSubstituteEntitiesDefaultValue;
530#undef xmlSubstituteEntitiesDefaultValue
531int *
532__xmlSubstituteEntitiesDefaultValue(void) {
533 if (IS_MAIN_THREAD)
534 return (&xmlSubstituteEntitiesDefaultValue);
535 else
Daniel Veillardd0463562001-10-13 09:15:48 +0000536 return (&xmlGetGlobalState()->xmlSubstituteEntitiesDefaultValue);
Daniel Veillardb8478642001-10-12 17:29:10 +0000537}