#include <libxml/globals.h>
#include <libxml/xmlmemory.h>
+#include <libxml/threads.h>
/* #define DEBUG_GLOBALS */
#define IS_MAIN_THREAD 1
#endif
+/*
+ * Mutex to protect "ForNewThreads" variables
+ */
+static xmlMutexPtr xmlThrDefMutex = NULL;
+
+void xmlInitGlobals()
+{
+ xmlThrDefMutex = xmlNewMutex();
+}
+
+void xmlCleanupGlobals()
+{
+ if (xmlThrDefMutex != NULL) {
+ xmlFreeMutex(xmlThrDefMutex);
+ xmlThrDefMutex = NULL;
+ }
+}
+
/************************************************************************
* *
* All the user accessible global variables of the library *
* Memory allocation routines
*/
#if defined(DEBUG_MEMORY_LOCATION) || defined(DEBUG_MEMORY)
+#ifndef _DEBUG_MEMORY_ALLOC_
extern void xmlMemFree(void *ptr);
extern void * xmlMemMalloc(size_t size);
extern void * xmlMemRealloc(void *ptr,size_t size);
extern char * xmlMemoryStrdup(const char *str);
+#endif
xmlFreeFunc xmlFree = (xmlFreeFunc) xmlMemFree;
xmlMallocFunc xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
+xmlMallocFunc xmlMallocAtomic = (xmlMallocFunc) xmlMemMalloc;
xmlReallocFunc xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
#else
*/
xmlMallocFunc xmlMalloc = (xmlMallocFunc) malloc;
/**
+ * xmlMallocAtomic:
+ * @size: the size requested in bytes
+ *
+ * The variable holding the libxml malloc() implementation for atomic
+ * data (i.e. blocks not containings pointers), useful when using a
+ * garbage collecting allocator.
+ *
+ * Returns a pointer to the newly allocated block or NULL in case of error
+ */
+xmlMallocFunc xmlMallocAtomic = (xmlMallocFunc) malloc;
+/**
* xmlRealloc:
* @mem: an already allocated block of memory
* @size: the new size requested in bytes
#undef xmlFree
#undef xmlMalloc
+#undef xmlMallocAtomic
#undef xmlMemStrdup
#undef xmlRealloc
* XML_BUFFER_ALLOC_EXACT
*/
xmlBufferAllocationScheme xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
+static xmlBufferAllocationScheme xmlBufferAllocSchemeThrDef = XML_BUFFER_ALLOC_EXACT;
/**
* xmlDefaultBufferSize:
*
* Global setting, default buffer size. Default value is BASE_BUFFER_SIZE
*/
int xmlDefaultBufferSize = BASE_BUFFER_SIZE;
+static int xmlDefaultBufferSizeThrDef = BASE_BUFFER_SIZE;
/*
* Parser defaults
* Disabled by default
*/
int xmlParserDebugEntities = 0;
+static int xmlParserDebugEntitiesThrDef = 0;
/**
* xmlDoValidityCheckingDefaultValue:
*
* Disabled by default.
*/
int xmlDoValidityCheckingDefaultValue = 0;
+static int xmlDoValidityCheckingDefaultValueThrDef = 0;
/**
* xmlGetWarningsDefaultValue:
*
* Activated by default.
*/
int xmlGetWarningsDefaultValue = 1;
+static int xmlGetWarningsDefaultValueThrDef = 1;
/**
* xmlLoadExtDtdDefaultValue:
*
* Disabled by default.
*/
int xmlLoadExtDtdDefaultValue = 0;
+static int xmlLoadExtDtdDefaultValueThrDef = 0;
/**
* xmlPedanticParserDefaultValue:
*
* Disabled by default.
*/
int xmlPedanticParserDefaultValue = 0;
+static int xmlPedanticParserDefaultValueThrDef = 0;
/**
* xmlLineNumbersDefaultValue:
*
* applicaton.
*/
int xmlLineNumbersDefaultValue = 0;
+static int xmlLineNumbersDefaultValueThrDef = 0;
/**
* xmlKeepBlanksDefaultValue:
*
* for some applications since this was libxml1 default behaviour.
*/
int xmlKeepBlanksDefaultValue = 1;
+static int xmlKeepBlanksDefaultValueThrDef = 1;
/**
* xmlSubstituteEntitiesDefaultValue:
*
* engine does not handle entities references transparently.
*/
int xmlSubstituteEntitiesDefaultValue = 0;
+static int xmlSubstituteEntitiesDefaultValueThrDef = 0;
xmlRegisterNodeFunc xmlRegisterNodeDefaultValue = NULL;
+static xmlRegisterNodeFunc xmlRegisterNodeDefaultValueThrDef = NULL;
xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue = NULL;
+static xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValueThrDef = NULL;
/*
* Error handling
* Global setting: function used for generic error callbacks
*/
xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc;
+static xmlGenericErrorFunc xmlGenericErrorThrDef = xmlGenericErrorDefaultFunc;
/**
* xmlGenericErrorContext:
*
* Global setting passed to generic error callbacks
*/
void *xmlGenericErrorContext = NULL;
+static void *xmlGenericErrorContextThrDef = NULL;
/*
* output defaults
* Enabled by default
*/
int xmlIndentTreeOutput = 1;
+static int xmlIndentTreeOutputThrDef = 1;
/**
* xmlTreeIndentString:
* The string used to do one-level indent. By default is equal to " " (two spaces)
*/
const char *xmlTreeIndentString = " ";
+static const char *xmlTreeIndentStringThrDef = " ";
/**
* xmlSaveNoEmptyTags:
* Disabled by default
*/
int xmlSaveNoEmptyTags = 0;
+int xmlSaveNoEmptyTagsThrDef = 0;
/**
* xmlDefaultSAXHandler:
/*
* Perform initialization as required by libxml
*/
+ xmlMutexLock(xmlThrDefMutex);
#ifdef LIBXML_DOCB_ENABLED
initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler);
#ifdef LIBXML_HTML_ENABLED
inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler);
#endif
- initGenericErrorDefaultFunc(&gs->xmlGenericError);
gs->oldXMLWDcompatibility = 0;
- gs->xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
- gs->xmlDefaultBufferSize = BASE_BUFFER_SIZE;
+ gs->xmlBufferAllocScheme = xmlBufferAllocSchemeThrDef;
+ gs->xmlDefaultBufferSize = xmlDefaultBufferSizeThrDef;
initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
gs->xmlDefaultSAXLocator.getPublicId = getPublicId;
gs->xmlDefaultSAXLocator.getSystemId = getSystemId;
gs->xmlDefaultSAXLocator.getLineNumber = getLineNumber;
gs->xmlDefaultSAXLocator.getColumnNumber = getColumnNumber;
- gs->xmlDoValidityCheckingDefaultValue = 0;
+ gs->xmlDoValidityCheckingDefaultValue =
+ xmlDoValidityCheckingDefaultValueThrDef;
#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
gs->xmlFree = (xmlFreeFunc) xmlMemFree;
gs->xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
+ gs->xmlMallocAtomic = (xmlMallocFunc) xmlMemMalloc;
gs->xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
gs->xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
#else
gs->xmlFree = (xmlFreeFunc) free;
gs->xmlMalloc = (xmlMallocFunc) malloc;
+ gs->xmlMallocAtomic = (xmlMallocFunc) malloc;
gs->xmlRealloc = (xmlReallocFunc) realloc;
gs->xmlMemStrdup = (xmlStrdupFunc) xmlStrdup;
#endif
- gs->xmlGenericErrorContext = NULL;
- gs->xmlGetWarningsDefaultValue = 1;
- gs->xmlIndentTreeOutput = 1;
- gs->xmlTreeIndentString = " ";
- gs->xmlKeepBlanksDefaultValue = 1;
- gs->xmlLineNumbersDefaultValue = 0;
- gs->xmlLoadExtDtdDefaultValue = 0;
- gs->xmlParserDebugEntities = 0;
+ gs->xmlGetWarningsDefaultValue = xmlGetWarningsDefaultValueThrDef;
+ gs->xmlIndentTreeOutput = xmlIndentTreeOutputThrDef;
+ gs->xmlTreeIndentString = xmlTreeIndentStringThrDef;
+ gs->xmlKeepBlanksDefaultValue = xmlKeepBlanksDefaultValueThrDef;
+ gs->xmlLineNumbersDefaultValue = xmlLineNumbersDefaultValueThrDef;
+ gs->xmlLoadExtDtdDefaultValue = xmlLoadExtDtdDefaultValueThrDef;
+ gs->xmlParserDebugEntities = xmlParserDebugEntitiesThrDef;
gs->xmlParserVersion = LIBXML_VERSION_STRING;
- gs->xmlPedanticParserDefaultValue = 0;
- gs->xmlSaveNoEmptyTags = 0;
- gs->xmlSubstituteEntitiesDefaultValue = 0;
+ gs->xmlPedanticParserDefaultValue = xmlPedanticParserDefaultValueThrDef;
+ gs->xmlSaveNoEmptyTags = xmlSaveNoEmptyTagsThrDef;
+ gs->xmlSubstituteEntitiesDefaultValue =
+ xmlSubstituteEntitiesDefaultValueThrDef;
- gs->xmlRegisterNodeDefaultValue = NULL;
- gs->xmlDeregisterNodeDefaultValue = NULL;
+ gs->xmlGenericError = xmlGenericErrorThrDef;
+ gs->xmlGenericErrorContext = xmlGenericErrorContextThrDef;
+ gs->xmlRegisterNodeDefaultValue = xmlRegisterNodeDefaultValueThrDef;
+ gs->xmlDeregisterNodeDefaultValue = xmlDeregisterNodeDefaultValueThrDef;
+
+ xmlMutexUnlock(xmlThrDefMutex);
+}
+
+void
+xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
+ xmlMutexLock(xmlThrDefMutex);
+ xmlGenericErrorContextThrDef = ctx;
+ if (handler != NULL)
+ xmlGenericErrorThrDef = handler;
+ else
+ xmlGenericErrorThrDef = xmlGenericErrorDefaultFunc;
+ xmlMutexUnlock(xmlThrDefMutex);
}
/**
{
xmlRegisterNodeFunc old = xmlRegisterNodeDefaultValue;
+ __xmlRegisterCallbacks = 1;
xmlRegisterNodeDefaultValue = func;
return(old);
}
+xmlRegisterNodeFunc
+xmlThrDefRegisterNodeDefault(xmlRegisterNodeFunc func)
+{
+ xmlRegisterNodeFunc old;
+
+ xmlMutexLock(xmlThrDefMutex);
+ old = xmlRegisterNodeDefaultValueThrDef;
+
+ __xmlRegisterCallbacks = 1;
+ xmlRegisterNodeDefaultValueThrDef = func;
+ xmlMutexUnlock(xmlThrDefMutex);
+
+ return(old);
+}
+
/**
* xmlDeregisterNodeDefault:
* @func: function pointer to the new DeregisterNodeFunc
{
xmlDeregisterNodeFunc old = xmlDeregisterNodeDefaultValue;
+ __xmlRegisterCallbacks = 1;
xmlDeregisterNodeDefaultValue = func;
return(old);
}
+xmlDeregisterNodeFunc
+xmlThrDefDeregisterNodeDefault(xmlDeregisterNodeFunc func)
+{
+ xmlDeregisterNodeFunc old;
+
+ xmlMutexLock(xmlThrDefMutex);
+ old = xmlDeregisterNodeDefaultValueThrDef;
+
+ __xmlRegisterCallbacks = 1;
+ xmlDeregisterNodeDefaultValueThrDef = func;
+ xmlMutexUnlock(xmlThrDefMutex);
+
+ return(old);
+}
+
#ifdef LIBXML_DOCB_ENABLED
#undef docbDefaultSAXHandler
else
return (&xmlGetGlobalState()->xmlBufferAllocScheme);
}
+xmlBufferAllocationScheme xmlThrDefBufferAllocScheme(xmlBufferAllocationScheme v) {
+ xmlBufferAllocationScheme ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlBufferAllocSchemeThrDef;
+ xmlBufferAllocSchemeThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlDefaultBufferSize
int *
else
return (&xmlGetGlobalState()->xmlDefaultBufferSize);
}
+int xmlThrDefDefaultBufferSize(int v) {
+ int ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlDefaultBufferSizeThrDef;
+ xmlDefaultBufferSizeThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlDefaultSAXHandler
xmlSAXHandler *
else
return (&xmlGetGlobalState()->xmlDoValidityCheckingDefaultValue);
}
+int xmlThrDefDoValidityCheckingDefaultValue(int v) {
+ int ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlDoValidityCheckingDefaultValueThrDef;
+ xmlDoValidityCheckingDefaultValueThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlGenericError
xmlGenericErrorFunc *
else
return (&xmlGetGlobalState()->xmlGetWarningsDefaultValue);
}
+int xmlThrDefGetWarningsDefaultValue(int v) {
+ int ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlGetWarningsDefaultValueThrDef;
+ xmlGetWarningsDefaultValueThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlIndentTreeOutput
int *
else
return (&xmlGetGlobalState()->xmlIndentTreeOutput);
}
+int xmlThrDefIndentTreeOutput(int v) {
+ int ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlIndentTreeOutputThrDef;
+ xmlIndentTreeOutputThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlTreeIndentString
const char * *
else
return (&xmlGetGlobalState()->xmlTreeIndentString);
}
+const char * xmlThrDefTreeIndentString(const char * v) {
+ const char * ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlTreeIndentStringThrDef;
+ xmlTreeIndentStringThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlKeepBlanksDefaultValue
int *
else
return (&xmlGetGlobalState()->xmlKeepBlanksDefaultValue);
}
+int xmlThrDefKeepBlanksDefaultValue(int v) {
+ int ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlKeepBlanksDefaultValueThrDef;
+ xmlKeepBlanksDefaultValueThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlLineNumbersDefaultValue
int *
else
return (&xmlGetGlobalState()->xmlLineNumbersDefaultValue);
}
+int xmlThrDefLineNumbersDefaultValue(int v) {
+ int ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlLineNumbersDefaultValueThrDef;
+ xmlLineNumbersDefaultValueThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlLoadExtDtdDefaultValue
int *
else
return (&xmlGetGlobalState()->xmlLoadExtDtdDefaultValue);
}
+int xmlThrDefLoadExtDtdDefaultValue(int v) {
+ int ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlLoadExtDtdDefaultValueThrDef;
+ xmlLoadExtDtdDefaultValueThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlParserDebugEntities
int *
else
return (&xmlGetGlobalState()->xmlParserDebugEntities);
}
+int xmlThrDefParserDebugEntities(int v) {
+ int ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlParserDebugEntitiesThrDef;
+ xmlParserDebugEntitiesThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlParserVersion
const char * *
else
return (&xmlGetGlobalState()->xmlPedanticParserDefaultValue);
}
+int xmlThrDefPedanticParserDefaultValue(int v) {
+ int ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlPedanticParserDefaultValueThrDef;
+ xmlPedanticParserDefaultValueThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlSaveNoEmptyTags
int *
else
return (&xmlGetGlobalState()->xmlSaveNoEmptyTags);
}
+int xmlThrDefSaveNoEmptyTags(int v) {
+ int ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlSaveNoEmptyTagsThrDef;
+ xmlSaveNoEmptyTagsThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlSubstituteEntitiesDefaultValue
int *
else
return (&xmlGetGlobalState()->xmlSubstituteEntitiesDefaultValue);
}
+int xmlThrDefSubstituteEntitiesDefaultValue(int v) {
+ int ret;
+ xmlMutexLock(xmlThrDefMutex);
+ ret = xmlSubstituteEntitiesDefaultValueThrDef;
+ xmlSubstituteEntitiesDefaultValueThrDef = v;
+ xmlMutexUnlock(xmlThrDefMutex);
+ return ret;
+}
#undef xmlRegisterNodeDefaultValue
xmlRegisterNodeFunc *