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