Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:41:51

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