blob: bd82c6d283ad870ee1d8fd972bd7c1f0c57f8e4b [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
Daniel Veillardf69bb4b2001-05-19 13:24:56 +000014/**
15 * DEBUG_MEMORY:
16 *
17 * should be activated only done when debugging libxml. It replaces the
18 * allocator with a collect and debug shell to the libc allocator.
19 * DEBUG_MEMORY should be activated only when debugging
20 * libxml i.e. if libxml has been configured with --with-debug-mem too
Owen Taylor3473f882001-02-23 17:55:21 +000021 */
Daniel Veillard48b2f892001-02-25 16:11:03 +000022/* #define DEBUG_MEMORY_FREED */
Owen Taylor3473f882001-02-23 17:55:21 +000023/* #define DEBUG_MEMORY_LOCATION */
24
25#ifdef DEBUG
26#ifndef DEBUG_MEMORY
27#define DEBUG_MEMORY
28#endif
29#endif
30
Daniel Veillardf69bb4b2001-05-19 13:24:56 +000031/**
32 * DEBUG_MEMORY_LOCATION:
33 *
34 * should be activated
35 * DEBUG_MEMORY_LOCATION should be activated only when debugging
36 * libxml i.e. if libxml has been configured with --with-debug-mem too
37 */
Owen Taylor3473f882001-02-23 17:55:21 +000038#ifdef DEBUG_MEMORY_LOCATION
39#define MEM_LIST /* keep a list of all the allocated memory blocks */
Daniel Veillard48b2f892001-02-25 16:11:03 +000040#endif
41
Owen Taylor3473f882001-02-23 17:55:21 +000042#ifdef __cplusplus
43extern "C" {
44#endif
45
46/*
47 * The XML memory wrapper support 4 basic overloadable functions
48 */
49typedef void (*xmlFreeFunc)(void *);
50typedef void *(*xmlMallocFunc)(int);
51typedef void *(*xmlReallocFunc)(void *, int);
52typedef char *(*xmlStrdupFunc)(const char *);
53
54/*
55 * The 4 interfaces used for all memory handling within libxml
56 */
57LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree;
58LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc;
59LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc;
60LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup;
61
62/*
63 * The way to overload the existing functions
64 */
65int xmlMemSetup (xmlFreeFunc freeFunc,
66 xmlMallocFunc mallocFunc,
67 xmlReallocFunc reallocFunc,
68 xmlStrdupFunc strdupFunc);
69int xmlMemGet (xmlFreeFunc *freeFunc,
70 xmlMallocFunc *mallocFunc,
71 xmlReallocFunc *reallocFunc,
72 xmlStrdupFunc *strdupFunc);
73
74/*
75 * Initialization of the memory layer
76 */
77int xmlInitMemory (void);
78
79/*
80 * Those are specific to the XML debug memory wrapper
81 */
82int xmlMemUsed (void);
83void xmlMemDisplay (FILE *fp);
84void xmlMemShow (FILE *fp, int nr);
85void xmlMemoryDump (void);
86int xmlInitMemory (void);
87
88#ifdef DEBUG_MEMORY_LOCATION
89#define xmlMalloc(x) xmlMallocLoc((x), __FILE__, __LINE__)
90#define xmlRealloc(p, x) xmlReallocLoc((p), (x), __FILE__, __LINE__)
91#define xmlMemStrdup(x) xmlMemStrdupLoc((x), __FILE__, __LINE__)
92
93void * xmlMallocLoc(int size, const char *file, int line);
94void * xmlReallocLoc(void *ptr,int size, const char *file, int line);
95char * xmlMemStrdupLoc(const char *str, const char *file, int line);
96#endif /* DEBUG_MEMORY_LOCATION */
97
98#ifdef __cplusplus
99}
100#endif /* __cplusplus */
101
102#endif /* _DEBUG_MEMORY_ALLOC_ */
103