blob: 78ff392fff7ecf0be031040fdc3321d757dbddb0 [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 Veillard35008381999-10-25 13:15:52 +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
43int xmlInitMemory (void);
44void * xmlMalloc (int size);
45void * xmlRealloc (void *ptr,
46 int size);
47void xmlFree (void *ptr);
48char * xmlMemStrdup (const char *str);
49int xmlMemUsed (void);
50void xmlMemDisplay (FILE *fp);
51void xmlMemoryDump (void);
52int 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
59extern void * xmlMallocLoc(int size, const char *file, int line);
60extern void * xmlReallocLoc(void *ptr,int size, const char *file, int line);
61extern 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