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