Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * memory.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 | |
Daniel Veillard | 962195f | 1999-10-28 15:51:53 +0000 | [diff] [blame] | 11 | #define NO_DEBUG_MEMORY |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 12 | |
| 13 | #ifdef NO_DEBUG_MEMORY |
| 14 | #ifdef HAVE_MALLOC_H |
| 15 | #include <malloc.h> |
| 16 | #endif |
| 17 | |
| 18 | #define xmlFree(x) free((x)) |
| 19 | #define xmlMalloc(x) malloc(x) |
| 20 | #define xmlRealloc(p, x) realloc((p), (x)) |
| 21 | #define xmlMemStrdup(x) strdup((x)) |
| 22 | #define xmlInitMemory() |
| 23 | #define xmlMemUsed() |
| 24 | #define xmlInitMemory() |
| 25 | #define xmlMemoryDump() |
| 26 | #define xmlMemDisplay(x) |
| 27 | |
| 28 | #else /* ! NO_DEBUG_MEMORY */ |
| 29 | #include <stdio.h> |
| 30 | |
| 31 | /* #define DEBUG_MEMORY */ /* */ |
| 32 | |
| 33 | #define DEBUG_MEMORY_LOCATION |
| 34 | |
| 35 | #ifdef DEBUG |
| 36 | #ifndef DEBUG_MEMORY |
| 37 | #define DEBUG_MEMORY |
| 38 | #endif |
| 39 | #endif |
| 40 | |
| 41 | #define MEM_LIST /* keep a list of all the allocated memory blocks */ |
| 42 | |
| 43 | int xmlInitMemory (void); |
| 44 | void * xmlMalloc (int size); |
| 45 | void * xmlRealloc (void *ptr, |
| 46 | int size); |
| 47 | void xmlFree (void *ptr); |
| 48 | char * xmlMemStrdup (const char *str); |
| 49 | int xmlMemUsed (void); |
| 50 | void xmlMemDisplay (FILE *fp); |
| 51 | void xmlMemoryDump (void); |
| 52 | int xmlInitMemory (void); |
| 53 | |
| 54 | #ifdef DEBUG_MEMORY_LOCATION |
| 55 | #define xmlMalloc(x) xmlMallocLoc((x), __FILE__, __LINE__) |
| 56 | #define xmlRealloc(p, x) xmlReallocLoc((p), (x), __FILE__, __LINE__) |
| 57 | #define xmlMemStrdup(x) xmlMemStrdupLoc((x), __FILE__, __LINE__) |
| 58 | |
| 59 | extern void * xmlMallocLoc(int size, const char *file, int line); |
| 60 | extern void * xmlReallocLoc(void *ptr,int size, const char *file, int line); |
| 61 | extern char * xmlMemStrdupLoc(const char *str, const char *file, int line); |
| 62 | #endif /* DEBUG_MEMORY_LOCATION */ |
| 63 | #endif /* ! NO_DEBUG_MEMORY */ |
| 64 | |
| 65 | #endif /* _DEBUG_MEMORY_ALLOC_ */ |
| 66 | |