Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-26 09:00:46

0001 /**
0002  * @file
0003  * 
0004  * @brief interface for the memory allocator
0005  * 
0006  * provides interfaces for the memory allocator,
0007  *              including debugging capabilities.
0008  *
0009  * @copyright See Copyright for the status of this software.
0010  *
0011  * @author Daniel Veillard
0012  */
0013 
0014 
0015 #ifndef __DEBUG_MEMORY_ALLOC__
0016 #define __DEBUG_MEMORY_ALLOC__
0017 
0018 #include <stdio.h>
0019 #include <libxml/xmlversion.h>
0020 
0021 #ifdef __cplusplus
0022 extern "C" {
0023 #endif
0024 
0025 /*
0026  * The XML memory wrapper support 4 basic overloadable functions.
0027  */
0028 /**
0029  * Signature for a free() implementation.
0030  *
0031  * @param mem  an already allocated block of memory
0032  */
0033 typedef void (*xmlFreeFunc)(void *mem);
0034 /**
0035  * Signature for a malloc() implementation.
0036  *
0037  * @param size  the size requested in bytes
0038  * @returns a pointer to the newly allocated block or NULL in case of error.
0039  */
0040 typedef void *(*xmlMallocFunc)(size_t size) LIBXML_ATTR_ALLOC_SIZE(1);
0041 
0042 /**
0043  * Signature for a realloc() implementation.
0044  *
0045  * @param mem  an already allocated block of memory
0046  * @param size  the new size requested in bytes
0047  * @returns a pointer to the newly reallocated block or NULL in case of error.
0048  */
0049 typedef void *(*xmlReallocFunc)(void *mem, size_t size);
0050 
0051 /**
0052  * Signature for an strdup() implementation.
0053  *
0054  * @param str  a zero terminated string
0055  * @returns the copy of the string or NULL in case of error.
0056  */
0057 typedef char *(*xmlStrdupFunc)(const char *str);
0058 
0059 /*
0060  * In general the memory allocation entry points are not kept
0061  * thread specific but this can be overridden by LIBXML_THREAD_ALLOC_ENABLED
0062  *    - xmlMalloc
0063  *    - xmlMallocAtomic
0064  *    - xmlRealloc
0065  *    - xmlMemStrdup
0066  *    - xmlFree
0067  */
0068 #ifdef LIBXML_THREAD_ALLOC_ENABLED
0069 
0070 XMLPUBFUN xmlMallocFunc *__xmlMalloc(void);
0071 XMLPUBFUN xmlMallocFunc *__xmlMallocAtomic(void);
0072 XMLPUBFUN xmlReallocFunc *__xmlRealloc(void);
0073 XMLPUBFUN xmlFreeFunc *__xmlFree(void);
0074 XMLPUBFUN xmlStrdupFunc *__xmlMemStrdup(void);
0075 
0076 #ifndef XML_GLOBALS_NO_REDEFINITION
0077   #define xmlMalloc (*__xmlMalloc())
0078   #define xmlMallocAtomic (*__xmlMallocAtomic())
0079   #define xmlRealloc (*__xmlRealloc())
0080   #define xmlFree (*__xmlFree())
0081   #define xmlMemStrdup (*__xmlMemStrdup())
0082 #endif
0083 
0084 #else
0085 
0086 /**
0087  * The variable holding the libxml malloc() implementation
0088  */
0089 XMLPUBVAR xmlMallocFunc xmlMalloc;
0090 /**
0091  * The variable holding the libxml malloc() implementation for atomic
0092  * data (i.e. blocks not containing pointers), useful when using a
0093  * garbage collecting allocator.
0094  *
0095  * @deprecated Use #xmlMalloc
0096  */
0097 XMLPUBVAR xmlMallocFunc xmlMallocAtomic;
0098 /**
0099  * The variable holding the libxml realloc() implementation
0100  */
0101 XMLPUBVAR xmlReallocFunc xmlRealloc;
0102 /**
0103  * The variable holding the libxml free() implementation
0104  */
0105 XMLPUBVAR xmlFreeFunc xmlFree;
0106 /**
0107  * The variable holding the libxml strdup() implementation
0108  */
0109 XMLPUBVAR xmlStrdupFunc xmlMemStrdup;
0110 
0111 #endif
0112 
0113 /*
0114  * The way to overload the existing functions.
0115  * The xmlGc function have an extra entry for atomic block
0116  * allocations useful for garbage collected memory allocators
0117  */
0118 XMLPUBFUN int
0119     xmlMemSetup (xmlFreeFunc freeFunc,
0120              xmlMallocFunc mallocFunc,
0121              xmlReallocFunc reallocFunc,
0122              xmlStrdupFunc strdupFunc);
0123 XMLPUBFUN int
0124     xmlMemGet   (xmlFreeFunc *freeFunc,
0125              xmlMallocFunc *mallocFunc,
0126              xmlReallocFunc *reallocFunc,
0127              xmlStrdupFunc *strdupFunc);
0128 XML_DEPRECATED
0129 XMLPUBFUN int
0130     xmlGcMemSetup   (xmlFreeFunc freeFunc,
0131              xmlMallocFunc mallocFunc,
0132              xmlMallocFunc mallocAtomicFunc,
0133              xmlReallocFunc reallocFunc,
0134              xmlStrdupFunc strdupFunc);
0135 XML_DEPRECATED
0136 XMLPUBFUN int
0137     xmlGcMemGet (xmlFreeFunc *freeFunc,
0138              xmlMallocFunc *mallocFunc,
0139              xmlMallocFunc *mallocAtomicFunc,
0140              xmlReallocFunc *reallocFunc,
0141              xmlStrdupFunc *strdupFunc);
0142 
0143 /*
0144  * Initialization of the memory layer.
0145  */
0146 XML_DEPRECATED
0147 XMLPUBFUN int
0148     xmlInitMemory   (void);
0149 
0150 /*
0151  * Cleanup of the memory layer.
0152  */
0153 XML_DEPRECATED
0154 XMLPUBFUN void
0155                 xmlCleanupMemory        (void);
0156 /*
0157  * These are specific to the XML debug memory wrapper.
0158  */
0159 XMLPUBFUN size_t
0160     xmlMemSize  (void *ptr);
0161 XMLPUBFUN int
0162     xmlMemUsed  (void);
0163 XMLPUBFUN int
0164     xmlMemBlocks    (void);
0165 XML_DEPRECATED
0166 XMLPUBFUN void
0167     xmlMemDisplay   (FILE *fp);
0168 XML_DEPRECATED
0169 XMLPUBFUN void
0170     xmlMemDisplayLast(FILE *fp, long nbBytes);
0171 XML_DEPRECATED
0172 XMLPUBFUN void
0173     xmlMemShow  (FILE *fp, int nr);
0174 XML_DEPRECATED
0175 XMLPUBFUN void
0176     xmlMemoryDump   (void);
0177 XMLPUBFUN void *
0178     xmlMemMalloc    (size_t size) LIBXML_ATTR_ALLOC_SIZE(1);
0179 XMLPUBFUN void *
0180     xmlMemRealloc   (void *ptr,size_t size);
0181 XMLPUBFUN void
0182     xmlMemFree  (void *ptr);
0183 XMLPUBFUN char *
0184     xmlMemoryStrdup (const char *str);
0185 XML_DEPRECATED
0186 XMLPUBFUN void *
0187     xmlMallocLoc    (size_t size, const char *file, int line) LIBXML_ATTR_ALLOC_SIZE(1);
0188 XML_DEPRECATED
0189 XMLPUBFUN void *
0190     xmlReallocLoc   (void *ptr, size_t size, const char *file, int line);
0191 XML_DEPRECATED
0192 XMLPUBFUN void *
0193     xmlMallocAtomicLoc (size_t size, const char *file, int line) LIBXML_ATTR_ALLOC_SIZE(1);
0194 XML_DEPRECATED
0195 XMLPUBFUN char *
0196     xmlMemStrdupLoc (const char *str, const char *file, int line);
0197 
0198 #ifdef __cplusplus
0199 }
0200 #endif /* __cplusplus */
0201 
0202 #endif  /* __DEBUG_MEMORY_ALLOC__ */
0203