1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-23 01:52:48 +03:00

globals: Move malloc hooks back to xmlmemory.h

This commit is contained in:
Nick Wellnhofer
2023-09-20 17:00:50 +02:00
parent a77f9ab84c
commit d1336fd393
7 changed files with 51 additions and 67 deletions

View File

@@ -61,13 +61,39 @@ typedef void *(*xmlReallocFunc)(void *mem, size_t size);
typedef char *(*xmlStrdupFunc)(const char *str);
/*
* The 4 interfaces used for all memory handling within libxml.
LIBXML_DLL_IMPORT xmlFreeFunc xmlFree;
LIBXML_DLL_IMPORT xmlMallocFunc xmlMalloc;
LIBXML_DLL_IMPORT xmlMallocFunc xmlMallocAtomic;
LIBXML_DLL_IMPORT xmlReallocFunc xmlRealloc;
LIBXML_DLL_IMPORT xmlStrdupFunc xmlMemStrdup;
* In general the memory allocation entry points are not kept
* thread specific but this can be overridden by LIBXML_THREAD_ALLOC_ENABLED
* - xmlMalloc
* - xmlMallocAtomic
* - xmlRealloc
* - xmlMemStrdup
* - xmlFree
*/
#ifdef LIBXML_THREAD_ALLOC_ENABLED
#define XML_GLOBALS_ALLOC \
XML_OP(xmlMalloc, xmlMallocFunc, XML_EMPTY) \
XML_OP(xmlMallocAtomic, xmlMallocFunc, XML_EMPTY) \
XML_OP(xmlRealloc, xmlReallocFunc, XML_EMPTY) \
XML_OP(xmlFree, xmlFreeFunc, XML_EMPTY) \
XML_OP(xmlMemStrdup, xmlStrdupFunc, XML_EMPTY)
#define XML_OP XML_DECLARE_GLOBAL
XML_GLOBALS_ALLOC
#undef XML_OP
#ifdef LIBXML_THREAD_ENABLED
#define xmlMalloc XML_GLOBAL_MACRO(xmlMalloc)
#define xmlMallocAtomic XML_GLOBAL_MACRO(xmlMallocAtomic)
#define xmlRealloc XML_GLOBAL_MACRO(xmlRealloc)
#define xmlFree XML_GLOBAL_MACRO(xmlFree)
#define xmlMemStrdup XML_GLOBAL_MACRO(xmlMemStrdup)
#endif
#else
#define XML_GLOBALS_ALLOC
XMLPUBVAR xmlMallocFunc xmlMalloc;
XMLPUBVAR xmlMallocFunc xmlMallocAtomic;
XMLPUBVAR xmlReallocFunc xmlRealloc;
XMLPUBVAR xmlFreeFunc xmlFree;
XMLPUBVAR xmlStrdupFunc xmlMemStrdup;
#endif
/*
* The way to overload the existing functions.
@@ -191,12 +217,5 @@ XMLPUBFUN char *
}
#endif /* __cplusplus */
#ifndef __XML_GLOBALS_H
#ifndef __XML_THREADS_H__
#include <libxml/threads.h>
#include <libxml/globals.h>
#endif
#endif
#endif /* __DEBUG_MEMORY_ALLOC__ */