1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-26 00:37:43 +03:00

threads: Fix --with-thread-alloc

Fixes #606.
This commit is contained in:
Nick Wellnhofer
2023-10-18 20:06:35 +02:00
parent 4f132bcdb3
commit 253f260bb1
4 changed files with 23 additions and 8 deletions

View File

@@ -754,12 +754,20 @@ xmlInitGlobalState(xmlGlobalStatePtr gs) {
gs->gs_xmlDefaultSAXLocator.getColumnNumber = xmlSAX2GetColumnNumber;
gs->gs_xmlDoValidityCheckingDefaultValue =
xmlDoValidityCheckingDefaultValueThrDef;
#if defined(DEBUG_MEMORY_LOCATION)
gs->gs_xmlFree = (xmlFreeFunc) xmlMemFree;
gs->gs_xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
gs->gs_xmlMallocAtomic = (xmlMallocFunc) xmlMemMalloc;
gs->gs_xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
gs->gs_xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
#ifdef LIBXML_THREAD_ALLOC_ENABLED
#ifdef DEBUG_MEMORY_LOCATION
gs->gs_xmlFree = xmlMemFree;
gs->gs_xmlMalloc = xmlMemMalloc;
gs->gs_xmlMallocAtomic = xmlMemMalloc;
gs->gs_xmlRealloc = xmlMemRealloc;
gs->gs_xmlMemStrdup = xmlMemoryStrdup;
#else
gs->gs_xmlFree = free;
gs->gs_xmlMalloc = malloc;
gs->gs_xmlMallocAtomic = malloc;
gs->gs_xmlRealloc = realloc;
gs->gs_xmlMemStrdup = xmlPosixStrdup;
#endif
#endif
gs->gs_xmlGetWarningsDefaultValue = xmlGetWarningsDefaultValueThrDef;
#ifdef LIBXML_OUTPUT_ENABLED

View File

@@ -80,7 +80,7 @@ typedef char *(*xmlStrdupFunc)(const char *str);
#define XML_OP XML_DECLARE_GLOBAL
XML_GLOBALS_ALLOC
#undef XML_OP
#ifdef LIBXML_THREAD_ENABLED
#if defined(LIBXML_THREAD_ENABLED) && !defined(XML_GLOBALS_NO_REDEFINITION)
#define xmlMalloc XML_GLOBAL_MACRO(xmlMalloc)
#define xmlMallocAtomic XML_GLOBAL_MACRO(xmlMallocAtomic)
#define xmlRealloc XML_GLOBAL_MACRO(xmlRealloc)

View File

@@ -4431,6 +4431,10 @@ thread_specific_data(void *private_data)
const char *filename = params->filename;
int okay = 1;
#ifdef LIBXML_THREAD_ALLOC_ENABLED
xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup);
#endif
myDoc = xmlReadFile(filename, NULL, XML_PARSE_NOENT | XML_PARSE_DTDLOAD);
if (myDoc) {
xmlFreeDoc(myDoc);

View File

@@ -579,6 +579,7 @@ xmlInitParser(void) {
if (xmlParserInnerInitialized == 0) {
#if defined(_WIN32) && \
!defined(LIBXML_THREAD_ALLOC_ENABLED) && \
(!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
if (xmlFree == free)
atexit(xmlCleanupParser);
@@ -665,7 +666,9 @@ xmlCleanupParser(void) {
xmlParserInnerInitialized = 0;
}
#if defined(HAVE_ATTRIBUTE_DESTRUCTOR) && !defined(LIBXML_STATIC) && \
#if defined(HAVE_ATTRIBUTE_DESTRUCTOR) && \
!defined(LIBXML_THREAD_ALLOC_ENABLED) && \
!defined(LIBXML_STATIC) && \
!defined(_WIN32)
static void
ATTRIBUTE_DESTRUCTOR