blob: 12538ab47706c58cbcc538462df5ab7c8c03edba [file] [log] [blame]
Owen Taylor3473f882001-02-23 17:55:21 +00001/*
2 * xmlmemory.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
11#include <stdio.h>
12#include <libxml/xmlversion.h>
13
14/*
15 * DEBUG_MEMORY_LOCATION should be activated only done when debugging
16 * libxml.
17 */
Daniel Veillard48b2f892001-02-25 16:11:03 +000018/* #define DEBUG_MEMORY_FREED */
Owen Taylor3473f882001-02-23 17:55:21 +000019/* #define DEBUG_MEMORY_LOCATION */
20
21#ifdef DEBUG
22#ifndef DEBUG_MEMORY
23#define DEBUG_MEMORY
24#endif
25#endif
26
27#ifdef DEBUG_MEMORY_LOCATION
28#define MEM_LIST /* keep a list of all the allocated memory blocks */
Daniel Veillard92ad2102001-03-27 12:47:33 +000029#define DEBUG_MEMORY_FREED
Owen Taylor3473f882001-02-23 17:55:21 +000030#endif
31
Daniel Veillard48b2f892001-02-25 16:11:03 +000032#ifdef DEBUG_MEMORY_FREED
33#define MEM_CLEANUP(p,l) memset((p), -1, (l));
34#else
35#define MEM_CLEANUP(p,l)
36#endif
37
Owen Taylor3473f882001-02-23 17:55:21 +000038#ifdef __cplusplus
39extern "C" {
40#endif
41
42/*
43 * The XML memory wrapper support 4 basic overloadable functions
44 */
45typedef void (*xmlFreeFunc)(void *);
46typedef void *(*xmlMallocFunc)(int);
47typedef void *(*xmlReallocFunc)(void *, int);
48typedef char *(*xmlStrdupFunc)(const char *);
49
50/*
51 * The 4 interfaces used for all memory handling within libxml
52 */
53LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree;
54LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc;
55LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc;
56LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup;
57
58/*
59 * The way to overload the existing functions
60 */
61int xmlMemSetup (xmlFreeFunc freeFunc,
62 xmlMallocFunc mallocFunc,
63 xmlReallocFunc reallocFunc,
64 xmlStrdupFunc strdupFunc);
65int xmlMemGet (xmlFreeFunc *freeFunc,
66 xmlMallocFunc *mallocFunc,
67 xmlReallocFunc *reallocFunc,
68 xmlStrdupFunc *strdupFunc);
69
70/*
71 * Initialization of the memory layer
72 */
73int xmlInitMemory (void);
74
75/*
76 * Those are specific to the XML debug memory wrapper
77 */
78int xmlMemUsed (void);
79void xmlMemDisplay (FILE *fp);
80void xmlMemShow (FILE *fp, int nr);
81void xmlMemoryDump (void);
82int xmlInitMemory (void);
83
84#ifdef DEBUG_MEMORY_LOCATION
85#define xmlMalloc(x) xmlMallocLoc((x), __FILE__, __LINE__)
86#define xmlRealloc(p, x) xmlReallocLoc((p), (x), __FILE__, __LINE__)
87#define xmlMemStrdup(x) xmlMemStrdupLoc((x), __FILE__, __LINE__)
88
89void * xmlMallocLoc(int size, const char *file, int line);
90void * xmlReallocLoc(void *ptr,int size, const char *file, int line);
91char * xmlMemStrdupLoc(const char *str, const char *file, int line);
92#endif /* DEBUG_MEMORY_LOCATION */
93
94#ifdef __cplusplus
95}
96#endif /* __cplusplus */
97
98#endif /* _DEBUG_MEMORY_ALLOC_ */
99