blob: 5c1b4774542d0d5d2f1079f626895aa293989807 [file] [log] [blame]
Daniel Veillard6454aec1999-09-02 22:04:43 +00001/*
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 Veillard962195f1999-10-28 15:51:53 +000011#define NO_DEBUG_MEMORY
Daniel Veillard6454aec1999-09-02 22:04:43 +000012
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
Daniel Veillard5cb5ab81999-12-21 15:35:29 +000043#ifdef __cplusplus
44extern "C" {
45#endif
Daniel Veillard6454aec1999-09-02 22:04:43 +000046int xmlInitMemory (void);
47void * xmlMalloc (int size);
48void * xmlRealloc (void *ptr,
49 int size);
50void xmlFree (void *ptr);
51char * xmlMemStrdup (const char *str);
52int xmlMemUsed (void);
53void xmlMemDisplay (FILE *fp);
54void xmlMemoryDump (void);
55int xmlInitMemory (void);
56
57#ifdef DEBUG_MEMORY_LOCATION
58#define xmlMalloc(x) xmlMallocLoc((x), __FILE__, __LINE__)
59#define xmlRealloc(p, x) xmlReallocLoc((p), (x), __FILE__, __LINE__)
60#define xmlMemStrdup(x) xmlMemStrdupLoc((x), __FILE__, __LINE__)
61
62extern void * xmlMallocLoc(int size, const char *file, int line);
63extern void * xmlReallocLoc(void *ptr,int size, const char *file, int line);
64extern char * xmlMemStrdupLoc(const char *str, const char *file, int line);
Daniel Veillard5cb5ab81999-12-21 15:35:29 +000065#ifdef __cplusplus
66}
67#endif
Daniel Veillard6454aec1999-09-02 22:04:43 +000068#endif /* DEBUG_MEMORY_LOCATION */
69#endif /* ! NO_DEBUG_MEMORY */
70
71#endif /* _DEBUG_MEMORY_ALLOC_ */
72