blob: 43a92b01100dab7fde5f0e0d2ceaf3444b04aa3f [file] [log] [blame]
Daniel Veillard6454aec1999-09-02 22:04:43 +00001/*
Daniel Veillarddbfd6411999-12-28 16:35:14 +00002 * xmlmemory.h: interface for the memory allocation debug.
Daniel Veillard6454aec1999-09-02 22:04:43 +00003 *
4 * Daniel.Veillard@w3.org
5 */
6
7
8#ifndef _DEBUG_MEMORY_ALLOC_
9#define _DEBUG_MEMORY_ALLOC_
10
Daniel Veillard6454aec1999-09-02 22:04:43 +000011#include <stdio.h>
12
Daniel Veillard8f621982000-03-20 13:07:15 +000013/*
14 * DEBUG_MEMORY_LOCATION should be activated only done when debugging
15 * libxml.
16 */
17/* #define DEBUG_MEMORY_LOCATION */
Daniel Veillard6454aec1999-09-02 22:04:43 +000018
19#ifdef DEBUG
20#ifndef DEBUG_MEMORY
21#define DEBUG_MEMORY
22#endif
23#endif
24
Daniel Veillard8f621982000-03-20 13:07:15 +000025#ifdef DEBUG_MEMORY_LOCATION
Daniel Veillard6454aec1999-09-02 22:04:43 +000026#define MEM_LIST /* keep a list of all the allocated memory blocks */
Daniel Veillard8f621982000-03-20 13:07:15 +000027#endif
Daniel Veillard6454aec1999-09-02 22:04:43 +000028
Daniel Veillard5cb5ab81999-12-21 15:35:29 +000029#ifdef __cplusplus
30extern "C" {
31#endif
Daniel Veillard8f621982000-03-20 13:07:15 +000032
33/*
34 * The XML memory wrapper support 4 basic overloadable functions
35 */
36typedef void (*xmlFreeFunc)(void *);
37typedef void *(*xmlMallocFunc)(int);
38typedef void *(*xmlReallocFunc)(void *, int);
39typedef char *(*xmlStrdupFunc)(const char *);
40
41/*
42 * The 4 interfaces used for all memory handling within libxml
43 */
44extern xmlFreeFunc xmlFree;
45extern xmlMallocFunc xmlMalloc;
46extern xmlReallocFunc xmlRealloc;
47extern xmlStrdupFunc xmlMemStrdup;
48
49/*
50 * The way to overload the existing functions
51 */
52int xmlMemSetup (xmlFreeFunc freeFunc,
53 xmlMallocFunc mallocFunc,
54 xmlReallocFunc reallocFunc,
55 xmlStrdupFunc strdupFunc);
56int xmlMemGet (xmlFreeFunc *freeFunc,
57 xmlMallocFunc *mallocFunc,
58 xmlReallocFunc *reallocFunc,
59 xmlStrdupFunc *strdupFunc);
60
61/*
62 * Initialization of the memory layer
63 */
Daniel Veillard6454aec1999-09-02 22:04:43 +000064int xmlInitMemory (void);
Daniel Veillard8f621982000-03-20 13:07:15 +000065
66/*
67 * Those are specific to the XML debug memory wrapper
68 */
Daniel Veillard6454aec1999-09-02 22:04:43 +000069int xmlMemUsed (void);
70void xmlMemDisplay (FILE *fp);
Daniel Veillarddbfd6411999-12-28 16:35:14 +000071void xmlMemShow (FILE *fp, int nr);
Daniel Veillard6454aec1999-09-02 22:04:43 +000072void xmlMemoryDump (void);
73int xmlInitMemory (void);
74
75#ifdef DEBUG_MEMORY_LOCATION
76#define xmlMalloc(x) xmlMallocLoc((x), __FILE__, __LINE__)
77#define xmlRealloc(p, x) xmlReallocLoc((p), (x), __FILE__, __LINE__)
78#define xmlMemStrdup(x) xmlMemStrdupLoc((x), __FILE__, __LINE__)
79
80extern void * xmlMallocLoc(int size, const char *file, int line);
81extern void * xmlReallocLoc(void *ptr,int size, const char *file, int line);
82extern char * xmlMemStrdupLoc(const char *str, const char *file, int line);
Daniel Veillard8f621982000-03-20 13:07:15 +000083#endif /* DEBUG_MEMORY_LOCATION */
84
Daniel Veillard5cb5ab81999-12-21 15:35:29 +000085#ifdef __cplusplus
86}
Daniel Veillard8f621982000-03-20 13:07:15 +000087#endif /* __cplusplus */
Daniel Veillard6454aec1999-09-02 22:04:43 +000088
89#endif /* _DEBUG_MEMORY_ALLOC_ */
90