blob: c909e4ceacd742347ac00e1912929650f5eb9b63 [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 */
29#endif
30
Daniel Veillard48b2f892001-02-25 16:11:03 +000031#ifdef DEBUG_MEMORY_FREED
32#define MEM_CLEANUP(p,l) memset((p), -1, (l));
33#else
34#define MEM_CLEANUP(p,l)
35#endif
36
Owen Taylor3473f882001-02-23 17:55:21 +000037#ifdef __cplusplus
38extern "C" {
39#endif
40
41/*
42 * The XML memory wrapper support 4 basic overloadable functions
43 */
44typedef void (*xmlFreeFunc)(void *);
45typedef void *(*xmlMallocFunc)(int);
46typedef void *(*xmlReallocFunc)(void *, int);
47typedef char *(*xmlStrdupFunc)(const char *);
48
49/*
50 * The 4 interfaces used for all memory handling within libxml
51 */
52LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree;
53LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc;
54LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc;
55LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup;
56
57/*
58 * The way to overload the existing functions
59 */
60int xmlMemSetup (xmlFreeFunc freeFunc,
61 xmlMallocFunc mallocFunc,
62 xmlReallocFunc reallocFunc,
63 xmlStrdupFunc strdupFunc);
64int xmlMemGet (xmlFreeFunc *freeFunc,
65 xmlMallocFunc *mallocFunc,
66 xmlReallocFunc *reallocFunc,
67 xmlStrdupFunc *strdupFunc);
68
69/*
70 * Initialization of the memory layer
71 */
72int xmlInitMemory (void);
73
74/*
75 * Those are specific to the XML debug memory wrapper
76 */
77int xmlMemUsed (void);
78void xmlMemDisplay (FILE *fp);
79void xmlMemShow (FILE *fp, int nr);
80void xmlMemoryDump (void);
81int xmlInitMemory (void);
82
83#ifdef DEBUG_MEMORY_LOCATION
84#define xmlMalloc(x) xmlMallocLoc((x), __FILE__, __LINE__)
85#define xmlRealloc(p, x) xmlReallocLoc((p), (x), __FILE__, __LINE__)
86#define xmlMemStrdup(x) xmlMemStrdupLoc((x), __FILE__, __LINE__)
87
88void * xmlMallocLoc(int size, const char *file, int line);
89void * xmlReallocLoc(void *ptr,int size, const char *file, int line);
90char * xmlMemStrdupLoc(const char *str, const char *file, int line);
91#endif /* DEBUG_MEMORY_LOCATION */
92
93#ifdef __cplusplus
94}
95#endif /* __cplusplus */
96
97#endif /* _DEBUG_MEMORY_ALLOC_ */
98