xmlmemory.h

00001 /*
00002 
00003  * Summary: interface for the memory allocator
00004 
00005  * Description: provides interfaces for the memory allocator,
00006 
00007  *              including debugging capabilities.
00008 
00009  *
00010 
00011  * Copy: See Copyright for the status of this software.
00012 
00013  *
00014 
00015  * Author: Daniel Veillard
00016 
00017  */
00018 
00019 
00020 
00021 
00022 
00023 #ifndef __DEBUG_MEMORY_ALLOC__
00024 
00025 #define __DEBUG_MEMORY_ALLOC__
00026 
00027 
00028 
00029 #include <stdio.h>
00030 
00031 #include <libxml/xmlversion.h>
00032 
00033 
00034 
00051 /* #define DEBUG_MEMORY_FREED */
00052 
00053 /* #define DEBUG_MEMORY_LOCATION */
00054 
00055 
00056 
00057 #ifdef DEBUG
00058 
00059 #ifndef DEBUG_MEMORY
00060 
00061 #define DEBUG_MEMORY
00062 
00063 #endif
00064 
00065 #endif
00066 
00067 
00068 
00081 #ifdef DEBUG_MEMORY_LOCATION
00082 
00083 #endif
00084 
00085 
00086 
00087 #ifdef __cplusplus
00088 
00089 extern "C" {
00090 
00091 #endif
00092 
00093 
00094 
00095 /*
00096 
00097  * The XML memory wrapper support 4 basic overloadable functions.
00098 
00099  */
00100 
00113 typedef void (XMLCALL *xmlFreeFunc)(void *mem);
00114 
00131 typedef void *(XMLCALL *xmlMallocFunc)(size_t size);
00132 
00133 
00134 
00153 typedef void *(XMLCALL *xmlReallocFunc)(void *mem, size_t size);
00154 
00155 
00156 
00173 typedef char *(XMLCALL *xmlStrdupFunc)(const char *str);
00174 
00175 
00176 
00177 /*
00178 
00179  * The 4 interfaces used for all memory handling within libxml.
00180 
00181 LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree;
00182 
00183 LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc;
00184 
00185 LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMallocAtomic;
00186 
00187 LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc;
00188 
00189 LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup;
00190 
00191  */
00192 
00193 
00194 
00195 /*
00196 
00197  * The way to overload the existing functions.
00198 
00199  * The xmlGc function have an extra entry for atomic block
00200 
00201  * allocations useful for garbage collected memory allocators
00202 
00203  */
00204 
00205 XMLPUBFUN int XMLCALL
00206 
00207         xmlMemSetup     (xmlFreeFunc freeFunc,
00208 
00209                          xmlMallocFunc mallocFunc,
00210 
00211                          xmlReallocFunc reallocFunc,
00212 
00213                          xmlStrdupFunc strdupFunc);
00214 
00215 XMLPUBFUN int XMLCALL     
00216 
00217         xmlMemGet       (xmlFreeFunc *freeFunc,
00218 
00219                          xmlMallocFunc *mallocFunc,
00220 
00221                          xmlReallocFunc *reallocFunc,
00222 
00223                          xmlStrdupFunc *strdupFunc);
00224 
00225 XMLPUBFUN int XMLCALL     
00226 
00227         xmlGcMemSetup   (xmlFreeFunc freeFunc,
00228 
00229                          xmlMallocFunc mallocFunc,
00230 
00231                          xmlMallocFunc mallocAtomicFunc,
00232 
00233                          xmlReallocFunc reallocFunc,
00234 
00235                          xmlStrdupFunc strdupFunc);
00236 
00237 XMLPUBFUN int XMLCALL     
00238 
00239         xmlGcMemGet     (xmlFreeFunc *freeFunc,
00240 
00241                          xmlMallocFunc *mallocFunc,
00242 
00243                          xmlMallocFunc *mallocAtomicFunc,
00244 
00245                          xmlReallocFunc *reallocFunc,
00246 
00247                          xmlStrdupFunc *strdupFunc);
00248 
00249 
00250 
00251 /*
00252 
00253  * Initialization of the memory layer.
00254 
00255  */
00256 
00257 XMLPUBFUN int XMLCALL   
00258 
00259         xmlInitMemory   (void);
00260 
00261 
00262 
00263 /* 
00264 
00265  * Cleanup of the memory layer.
00266 
00267  */
00268 
00269 XMLPUBFUN void XMLCALL                
00270 
00271                 xmlCleanupMemory        (void);
00272 
00273 /*
00274 
00275  * These are specific to the XML debug memory wrapper.
00276 
00277  */
00278 
00279 XMLPUBFUN int XMLCALL   
00280 
00281         xmlMemUsed      (void);
00282 
00283 XMLPUBFUN int XMLCALL   
00284 
00285         xmlMemBlocks    (void);
00286 
00287 XMLPUBFUN void XMLCALL  
00288 
00289         xmlMemDisplay   (FILE *fp);
00290 
00291 XMLPUBFUN void XMLCALL  
00292 
00293         xmlMemShow      (FILE *fp, int nr);
00294 
00295 XMLPUBFUN void XMLCALL  
00296 
00297         xmlMemoryDump   (void);
00298 
00299 XMLPUBFUN void * XMLCALL        
00300 
00301         xmlMemMalloc    (size_t size);
00302 
00303 XMLPUBFUN void * XMLCALL        
00304 
00305         xmlMemRealloc   (void *ptr,size_t size);
00306 
00307 XMLPUBFUN void XMLCALL  
00308 
00309         xmlMemFree      (void *ptr);
00310 
00311 XMLPUBFUN char * XMLCALL        
00312 
00313         xmlMemoryStrdup (const char *str);
00314 
00315 XMLPUBFUN void * XMLCALL  
00316 
00317         xmlMallocLoc    (size_t size, const char *file, int line);
00318 
00319 XMLPUBFUN void * XMLCALL        
00320 
00321         xmlReallocLoc   (void *ptr, size_t size, const char *file, int line);
00322 
00323 XMLPUBFUN void * XMLCALL        
00324 
00325         xmlMallocAtomicLoc (size_t size, const char *file, int line);
00326 
00327 XMLPUBFUN char * XMLCALL        
00328 
00329         xmlMemStrdupLoc (const char *str, const char *file, int line);
00330 
00331 
00332 
00333 
00334 
00335 #ifdef DEBUG_MEMORY_LOCATION
00336 
00353 #define xmlMalloc(size) xmlMallocLoc((size), __FILE__, __LINE__)
00354 
00373 #define xmlMallocAtomic(size) xmlMallocAtomicLoc((size), __FILE__, __LINE__)
00374 
00393 #define xmlRealloc(ptr, size) xmlReallocLoc((ptr), (size), __FILE__, __LINE__)
00394 
00411 #define xmlMemStrdup(str) xmlMemStrdupLoc((str), __FILE__, __LINE__)
00412 
00413 
00414 
00415 #endif /* DEBUG_MEMORY_LOCATION */
00416 
00417 
00418 
00419 #ifdef __cplusplus
00420 
00421 }
00422 
00423 #endif /* __cplusplus */
00424 
00425 
00426 
00427 #ifndef __XML_GLOBALS_H
00428 
00429 #ifndef __XML_THREADS_H__
00430 
00431 #include <libxml/threads.h>
00432 
00433 #include <libxml/globals.h>
00434 
00435 #endif
00436 
00437 #endif
00438 
00439 
00440 
00441 #endif  /* __DEBUG_MEMORY_ALLOC__ */
00442 
00443 
00444 

Generated on Wed Jul 26 13:30:46 2006 for XSB by  doxygen 1.4.5