xmlmemory.h

Go to the documentation of this file.
00001 /*
00002  * Summary: interface for the memory allocator
00003  * Description: provides interfaces for the memory allocator,
00004  *              including debugging capabilities.
00005  *
00006  * Copy: See Copyright for the status of this software.
00007  *
00008  * Author: Daniel Veillard
00009  */
00010 
00011 
00012 #ifndef __DEBUG_MEMORY_ALLOC__
00013 #define __DEBUG_MEMORY_ALLOC__
00014 
00015 #include <stdio.h>
00016 #include <libxml/xmlversion.h>
00017 
00026 /* #define DEBUG_MEMORY_FREED */
00027 /* #define DEBUG_MEMORY_LOCATION */
00028 
00029 #ifdef DEBUG
00030 #ifndef DEBUG_MEMORY
00031 #define DEBUG_MEMORY
00032 #endif
00033 #endif
00034 
00041 #ifdef DEBUG_MEMORY_LOCATION
00042 #endif
00043 
00044 #ifdef __cplusplus
00045 extern "C" {
00046 #endif
00047 
00048 /*
00049  * The XML memory wrapper support 4 basic overloadable functions.
00050  */
00057 typedef void (XMLCALL *xmlFreeFunc)(void *mem);
00066 typedef void *(XMLCALL *xmlMallocFunc)(size_t size);
00067 
00077 typedef void *(XMLCALL *xmlReallocFunc)(void *mem, size_t size);
00078 
00087 typedef char *(XMLCALL *xmlStrdupFunc)(const char *str);
00088 
00089 /*
00090  * The 4 interfaces used for all memory handling within libxml.
00091 LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree;
00092 LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc;
00093 LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMallocAtomic;
00094 LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc;
00095 LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup;
00096  */
00097 
00098 /*
00099  * The way to overload the existing functions.
00100  * The xmlGc function have an extra entry for atomic block
00101  * allocations useful for garbage collected memory allocators
00102  */
00103 XMLPUBFUN int XMLCALL
00104     xmlMemSetup (xmlFreeFunc freeFunc,
00105              xmlMallocFunc mallocFunc,
00106              xmlReallocFunc reallocFunc,
00107              xmlStrdupFunc strdupFunc);
00108 XMLPUBFUN int XMLCALL     
00109     xmlMemGet   (xmlFreeFunc *freeFunc,
00110              xmlMallocFunc *mallocFunc,
00111              xmlReallocFunc *reallocFunc,
00112              xmlStrdupFunc *strdupFunc);
00113 XMLPUBFUN int XMLCALL     
00114     xmlGcMemSetup   (xmlFreeFunc freeFunc,
00115              xmlMallocFunc mallocFunc,
00116              xmlMallocFunc mallocAtomicFunc,
00117              xmlReallocFunc reallocFunc,
00118              xmlStrdupFunc strdupFunc);
00119 XMLPUBFUN int XMLCALL     
00120     xmlGcMemGet (xmlFreeFunc *freeFunc,
00121              xmlMallocFunc *mallocFunc,
00122              xmlMallocFunc *mallocAtomicFunc,
00123              xmlReallocFunc *reallocFunc,
00124              xmlStrdupFunc *strdupFunc);
00125 
00126 /*
00127  * Initialization of the memory layer.
00128  */
00129 XMLPUBFUN int XMLCALL   
00130     xmlInitMemory   (void);
00131 
00132 /* 
00133  * Cleanup of the memory layer.
00134  */
00135 XMLPUBFUN void XMLCALL                
00136                 xmlCleanupMemory        (void);
00137 /*
00138  * These are specific to the XML debug memory wrapper.
00139  */
00140 XMLPUBFUN int XMLCALL   
00141     xmlMemUsed  (void);
00142 XMLPUBFUN int XMLCALL   
00143     xmlMemBlocks    (void);
00144 XMLPUBFUN void XMLCALL  
00145     xmlMemDisplay   (FILE *fp);
00146 XMLPUBFUN void XMLCALL  
00147     xmlMemShow  (FILE *fp, int nr);
00148 XMLPUBFUN void XMLCALL  
00149     xmlMemoryDump   (void);
00150 XMLPUBFUN void * XMLCALL    
00151     xmlMemMalloc    (size_t size);
00152 XMLPUBFUN void * XMLCALL    
00153     xmlMemRealloc   (void *ptr,size_t size);
00154 XMLPUBFUN void XMLCALL  
00155     xmlMemFree  (void *ptr);
00156 XMLPUBFUN char * XMLCALL    
00157     xmlMemoryStrdup (const char *str);
00158 XMLPUBFUN void * XMLCALL  
00159     xmlMallocLoc    (size_t size, const char *file, int line);
00160 XMLPUBFUN void * XMLCALL    
00161     xmlReallocLoc   (void *ptr, size_t size, const char *file, int line);
00162 XMLPUBFUN void * XMLCALL    
00163     xmlMallocAtomicLoc (size_t size, const char *file, int line);
00164 XMLPUBFUN char * XMLCALL    
00165     xmlMemStrdupLoc (const char *str, const char *file, int line);
00166 
00167 
00168 #ifdef DEBUG_MEMORY_LOCATION
00169 
00177 #define xmlMalloc(size) xmlMallocLoc((size), __FILE__, __LINE__)
00178 
00187 #define xmlMallocAtomic(size) xmlMallocAtomicLoc((size), __FILE__, __LINE__)
00188 
00197 #define xmlRealloc(ptr, size) xmlReallocLoc((ptr), (size), __FILE__, __LINE__)
00198 
00206 #define xmlMemStrdup(str) xmlMemStrdupLoc((str), __FILE__, __LINE__)
00207 
00208 #endif /* DEBUG_MEMORY_LOCATION */
00209 
00210 #ifdef __cplusplus
00211 }
00212 #endif /* __cplusplus */
00213 
00214 #ifndef __XML_GLOBALS_H
00215 #ifndef __XML_THREADS_H__
00216 #include <libxml/threads.h>
00217 #include <libxml/globals.h>
00218 #endif
00219 #endif
00220 
00221 #endif  /* __DEBUG_MEMORY_ALLOC__ */
00222 
footer
 SourceForge.net Logo