Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * xmlmemory.h: interface for the memory allocation debug. |
| 3 | * |
| 4 | * Daniel.Veillard@w3.org |
| 5 | */ |
| 6 | |
| 7 | |
| 8 | #ifndef _DEBUG_MEMORY_ALLOC_ |
| 9 | #define _DEBUG_MEMORY_ALLOC_ |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <libxml/xmlversion.h> |
| 13 | |
Daniel Veillard | f69bb4b | 2001-05-19 13:24:56 +0000 | [diff] [blame] | 14 | /** |
| 15 | * DEBUG_MEMORY: |
| 16 | * |
| 17 | * should be activated only done when debugging libxml. It replaces the |
| 18 | * allocator with a collect and debug shell to the libc allocator. |
| 19 | * DEBUG_MEMORY should be activated only when debugging |
| 20 | * libxml i.e. if libxml has been configured with --with-debug-mem too |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 21 | */ |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 22 | /* #define DEBUG_MEMORY_FREED */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 23 | /* #define DEBUG_MEMORY_LOCATION */ |
| 24 | |
| 25 | #ifdef DEBUG |
| 26 | #ifndef DEBUG_MEMORY |
| 27 | #define DEBUG_MEMORY |
| 28 | #endif |
| 29 | #endif |
| 30 | |
Daniel Veillard | f69bb4b | 2001-05-19 13:24:56 +0000 | [diff] [blame] | 31 | /** |
| 32 | * DEBUG_MEMORY_LOCATION: |
| 33 | * |
| 34 | * should be activated |
| 35 | * DEBUG_MEMORY_LOCATION should be activated only when debugging |
| 36 | * libxml i.e. if libxml has been configured with --with-debug-mem too |
| 37 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 38 | #ifdef DEBUG_MEMORY_LOCATION |
| 39 | #define MEM_LIST /* keep a list of all the allocated memory blocks */ |
Daniel Veillard | 48b2f89 | 2001-02-25 16:11:03 +0000 | [diff] [blame] | 40 | #endif |
| 41 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 42 | #ifdef __cplusplus |
| 43 | extern "C" { |
| 44 | #endif |
| 45 | |
| 46 | /* |
| 47 | * The XML memory wrapper support 4 basic overloadable functions |
| 48 | */ |
| 49 | typedef void (*xmlFreeFunc)(void *); |
| 50 | typedef void *(*xmlMallocFunc)(int); |
| 51 | typedef void *(*xmlReallocFunc)(void *, int); |
| 52 | typedef char *(*xmlStrdupFunc)(const char *); |
| 53 | |
| 54 | /* |
| 55 | * The 4 interfaces used for all memory handling within libxml |
| 56 | */ |
| 57 | LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree; |
| 58 | LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc; |
| 59 | LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc; |
| 60 | LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup; |
| 61 | |
| 62 | /* |
| 63 | * The way to overload the existing functions |
| 64 | */ |
| 65 | int xmlMemSetup (xmlFreeFunc freeFunc, |
| 66 | xmlMallocFunc mallocFunc, |
| 67 | xmlReallocFunc reallocFunc, |
| 68 | xmlStrdupFunc strdupFunc); |
| 69 | int xmlMemGet (xmlFreeFunc *freeFunc, |
| 70 | xmlMallocFunc *mallocFunc, |
| 71 | xmlReallocFunc *reallocFunc, |
| 72 | xmlStrdupFunc *strdupFunc); |
| 73 | |
| 74 | /* |
| 75 | * Initialization of the memory layer |
| 76 | */ |
| 77 | int xmlInitMemory (void); |
| 78 | |
| 79 | /* |
| 80 | * Those are specific to the XML debug memory wrapper |
| 81 | */ |
| 82 | int xmlMemUsed (void); |
| 83 | void xmlMemDisplay (FILE *fp); |
| 84 | void xmlMemShow (FILE *fp, int nr); |
| 85 | void xmlMemoryDump (void); |
| 86 | int xmlInitMemory (void); |
| 87 | |
| 88 | #ifdef DEBUG_MEMORY_LOCATION |
| 89 | #define xmlMalloc(x) xmlMallocLoc((x), __FILE__, __LINE__) |
| 90 | #define xmlRealloc(p, x) xmlReallocLoc((p), (x), __FILE__, __LINE__) |
| 91 | #define xmlMemStrdup(x) xmlMemStrdupLoc((x), __FILE__, __LINE__) |
| 92 | |
| 93 | void * xmlMallocLoc(int size, const char *file, int line); |
| 94 | void * xmlReallocLoc(void *ptr,int size, const char *file, int line); |
| 95 | char * xmlMemStrdupLoc(const char *str, const char *file, int line); |
| 96 | #endif /* DEBUG_MEMORY_LOCATION */ |
| 97 | |
| 98 | #ifdef __cplusplus |
| 99 | } |
| 100 | #endif /* __cplusplus */ |
| 101 | |
| 102 | #endif /* _DEBUG_MEMORY_ALLOC_ */ |
| 103 | |