blob: 1e533d15d2cffe91615e073d230be82dbb0f8233 [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>
Daniel Veillard361d8452000-04-03 19:48:13 +000012#include <libxml/xmlversion.h>
Daniel Veillard6454aec1999-09-02 22:04:43 +000013
Daniel Veillard8f621982000-03-20 13:07:15 +000014/*
15 * DEBUG_MEMORY_LOCATION should be activated only done when debugging
16 * libxml.
17 */
18/* #define DEBUG_MEMORY_LOCATION */
Daniel Veillard6454aec1999-09-02 22:04:43 +000019
20#ifdef DEBUG
21#ifndef DEBUG_MEMORY
22#define DEBUG_MEMORY
23#endif
24#endif
25
Daniel Veillard8f621982000-03-20 13:07:15 +000026#ifdef DEBUG_MEMORY_LOCATION
Daniel Veillard6454aec1999-09-02 22:04:43 +000027#define MEM_LIST /* keep a list of all the allocated memory blocks */
Daniel Veillard8f621982000-03-20 13:07:15 +000028#endif
Daniel Veillard6454aec1999-09-02 22:04:43 +000029
Daniel Veillard5cb5ab81999-12-21 15:35:29 +000030#ifdef __cplusplus
31extern "C" {
32#endif
Daniel Veillard8f621982000-03-20 13:07:15 +000033
34/*
35 * The XML memory wrapper support 4 basic overloadable functions
36 */
37typedef void (*xmlFreeFunc)(void *);
38typedef void *(*xmlMallocFunc)(int);
39typedef void *(*xmlReallocFunc)(void *, int);
40typedef char *(*xmlStrdupFunc)(const char *);
41
42/*
43 * The 4 interfaces used for all memory handling within libxml
44 */
Daniel Veillard748e45d2000-11-17 16:36:08 +000045LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree;
46LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc;
47LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc;
48LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup;
Daniel Veillard8f621982000-03-20 13:07:15 +000049
50/*
51 * The way to overload the existing functions
52 */
53int xmlMemSetup (xmlFreeFunc freeFunc,
54 xmlMallocFunc mallocFunc,
55 xmlReallocFunc reallocFunc,
56 xmlStrdupFunc strdupFunc);
57int xmlMemGet (xmlFreeFunc *freeFunc,
58 xmlMallocFunc *mallocFunc,
59 xmlReallocFunc *reallocFunc,
60 xmlStrdupFunc *strdupFunc);
61
62/*
63 * Initialization of the memory layer
64 */
Daniel Veillard6454aec1999-09-02 22:04:43 +000065int xmlInitMemory (void);
Daniel Veillard8f621982000-03-20 13:07:15 +000066
67/*
68 * Those are specific to the XML debug memory wrapper
69 */
Daniel Veillard6454aec1999-09-02 22:04:43 +000070int xmlMemUsed (void);
71void xmlMemDisplay (FILE *fp);
Daniel Veillarddbfd6411999-12-28 16:35:14 +000072void xmlMemShow (FILE *fp, int nr);
Daniel Veillard6454aec1999-09-02 22:04:43 +000073void xmlMemoryDump (void);
74int xmlInitMemory (void);
75
76#ifdef DEBUG_MEMORY_LOCATION
77#define xmlMalloc(x) xmlMallocLoc((x), __FILE__, __LINE__)
78#define xmlRealloc(p, x) xmlReallocLoc((p), (x), __FILE__, __LINE__)
79#define xmlMemStrdup(x) xmlMemStrdupLoc((x), __FILE__, __LINE__)
80
Daniel Veillard748e45d2000-11-17 16:36:08 +000081void * xmlMallocLoc(int size, const char *file, int line);
82void * xmlReallocLoc(void *ptr,int size, const char *file, int line);
83char * xmlMemStrdupLoc(const char *str, const char *file, int line);
Daniel Veillard8f621982000-03-20 13:07:15 +000084#endif /* DEBUG_MEMORY_LOCATION */
85
Daniel Veillard5cb5ab81999-12-21 15:35:29 +000086#ifdef __cplusplus
87}
Daniel Veillard8f621982000-03-20 13:07:15 +000088#endif /* __cplusplus */
Daniel Veillard6454aec1999-09-02 22:04:43 +000089
90#endif /* _DEBUG_MEMORY_ALLOC_ */
91