source: NonGTP/FCollada/libxml/xmlmemory.h @ 964

Revision 964, 5.7 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*
2 * Summary: interface for the memory allocator
3 * Description: provides interfaces for the memory allocator,
4 *              including debugging capabilities.
5 *
6 * Copy: See Copyright for the status of this software.
7 *
8 * Author: Daniel Veillard
9 */
10
11
12#ifndef __DEBUG_MEMORY_ALLOC__
13#define __DEBUG_MEMORY_ALLOC__
14
15#include <stdio.h>
16#include <libxml/xmlversion.h>
17
18/**
19 * DEBUG_MEMORY:
20 *
21 * DEBUG_MEMORY replaces the allocator with a collect and debug
22 * shell to the libc allocator.
23 * DEBUG_MEMORY should only be activated when debugging
24 * libxml i.e. if libxml has been configured with --with-debug-mem too.
25 */
26/* #define DEBUG_MEMORY_FREED */
27/* #define DEBUG_MEMORY_LOCATION */
28
29#ifdef DEBUG
30#ifndef DEBUG_MEMORY
31#define DEBUG_MEMORY
32#endif
33#endif
34
35/**
36 * DEBUG_MEMORY_LOCATION:
37 *
38 * DEBUG_MEMORY_LOCATION should be activated only when debugging
39 * libxml i.e. if libxml has been configured with --with-debug-mem too.
40 */
41#ifdef DEBUG_MEMORY_LOCATION
42#endif
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/*
49 * The XML memory wrapper support 4 basic overloadable functions.
50 */
51/**
52 * xmlFreeFunc:
53 * @mem: an already allocated block of memory
54 *
55 * Signature for a free() implementation.
56 */
57typedef void (XMLCALL *xmlFreeFunc)(void *mem);
58/**
59 * xmlMallocFunc:
60 * @size:  the size requested in bytes
61 *
62 * Signature for a malloc() implementation.
63 *
64 * Returns a pointer to the newly allocated block or NULL in case of error.
65 */
66typedef void *(XMLCALL *xmlMallocFunc)(size_t size);
67
68/**
69 * xmlReallocFunc:
70 * @mem: an already allocated block of memory
71 * @size:  the new size requested in bytes
72 *
73 * Signature for a realloc() implementation.
74 *
75 * Returns a pointer to the newly reallocated block or NULL in case of error.
76 */
77typedef void *(XMLCALL *xmlReallocFunc)(void *mem, size_t size);
78
79/**
80 * xmlStrdupFunc:
81 * @str: a zero terminated string
82 *
83 * Signature for an strdup() implementation.
84 *
85 * Returns the copy of the string or NULL in case of error.
86 */
87typedef char *(XMLCALL *xmlStrdupFunc)(const char *str);
88
89/*
90 * The 4 interfaces used for all memory handling within libxml.
91 */
92
93LIBXML_DLL_IMPORT xmlFreeFunc xmlFree;
94LIBXML_DLL_IMPORT xmlMallocFunc xmlMalloc;
95LIBXML_DLL_IMPORT xmlMallocFunc xmlMallocAtomic;
96LIBXML_DLL_IMPORT xmlReallocFunc xmlRealloc;
97LIBXML_DLL_IMPORT xmlStrdupFunc xmlMemStrdup;
98
99/*
100 * The way to overload the existing functions.
101 * The xmlGc function have an extra entry for atomic block
102 * allocations useful for garbage collected memory allocators
103 */
104XMLPUBFUN int XMLCALL
105        xmlMemSetup     (xmlFreeFunc freeFunc,
106                         xmlMallocFunc mallocFunc,
107                         xmlReallocFunc reallocFunc,
108                         xmlStrdupFunc strdupFunc);
109XMLPUBFUN int XMLCALL     
110        xmlMemGet       (xmlFreeFunc *freeFunc,
111                         xmlMallocFunc *mallocFunc,
112                         xmlReallocFunc *reallocFunc,
113                         xmlStrdupFunc *strdupFunc);
114XMLPUBFUN int XMLCALL     
115        xmlGcMemSetup   (xmlFreeFunc freeFunc,
116                         xmlMallocFunc mallocFunc,
117                         xmlMallocFunc mallocAtomicFunc,
118                         xmlReallocFunc reallocFunc,
119                         xmlStrdupFunc strdupFunc);
120XMLPUBFUN int XMLCALL     
121        xmlGcMemGet     (xmlFreeFunc *freeFunc,
122                         xmlMallocFunc *mallocFunc,
123                         xmlMallocFunc *mallocAtomicFunc,
124                         xmlReallocFunc *reallocFunc,
125                         xmlStrdupFunc *strdupFunc);
126
127/*
128 * Initialization of the memory layer.
129 */
130XMLPUBFUN int XMLCALL   
131        xmlInitMemory   (void);
132
133/*
134 * Cleanup of the memory layer.
135 */
136XMLPUBFUN void XMLCALL               
137                xmlCleanupMemory        (void);
138/*
139 * These are specific to the XML debug memory wrapper.
140 */
141XMLPUBFUN size_t XMLCALL       
142        xmlMemUsed      (void);
143XMLPUBFUN size_t XMLCALL       
144        xmlMemBlocks    (void);
145XMLPUBFUN void XMLCALL 
146        xmlMemDisplay   (FILE *fp);
147XMLPUBFUN void XMLCALL 
148        xmlMemShow      (FILE *fp, int nr);
149XMLPUBFUN void XMLCALL 
150        xmlMemoryDump   (void);
151XMLPUBFUN void * XMLCALL       
152        xmlMemMalloc    (size_t size);
153XMLPUBFUN void * XMLCALL       
154        xmlMemRealloc   (void *ptr,size_t size);
155XMLPUBFUN void XMLCALL 
156        xmlMemFree      (void *ptr);
157XMLPUBFUN char * XMLCALL       
158        xmlMemoryStrdup (const char *str);
159XMLPUBFUN void * XMLCALL 
160        xmlMallocLoc    (size_t size, const char *file, int line);
161XMLPUBFUN void * XMLCALL       
162        xmlReallocLoc   (void *ptr, size_t size, const char *file, int line);
163XMLPUBFUN void * XMLCALL       
164        xmlMallocAtomicLoc (size_t size, const char *file, int line);
165XMLPUBFUN char * XMLCALL       
166        xmlMemStrdupLoc (const char *str, const char *file, int line);
167
168
169#ifdef DEBUG_MEMORY_LOCATION
170/**
171 * xmlMalloc:
172 * @size:  number of bytes to allocate
173 *
174 * Wrapper for the malloc() function used in the XML library.
175 *
176 * Returns the pointer to the allocated area or NULL in case of error.
177 */
178#define xmlMalloc(size) xmlMallocLoc((size), __FILE__, __LINE__)
179/**
180 * xmlMallocAtomic:
181 * @size:  number of bytes to allocate
182 *
183 * Wrapper for the malloc() function used in the XML library for allocation
184 * of block not containing pointers to other areas.
185 *
186 * Returns the pointer to the allocated area or NULL in case of error.
187 */
188#define xmlMallocAtomic(size) xmlMallocAtomicLoc((size), __FILE__, __LINE__)
189/**
190 * xmlRealloc:
191 * @ptr:  pointer to the existing allocated area
192 * @size:  number of bytes to allocate
193 *
194 * Wrapper for the realloc() function used in the XML library.
195 *
196 * Returns the pointer to the allocated area or NULL in case of error.
197 */
198#define xmlRealloc(ptr, size) xmlReallocLoc((ptr), (size), __FILE__, __LINE__)
199/**
200 * xmlMemStrdup:
201 * @str:  pointer to the existing string
202 *
203 * Wrapper for the strdup() function, xmlStrdup() is usually preferred.
204 *
205 * Returns the pointer to the allocated area or NULL in case of error.
206 */
207#define xmlMemStrdup(str) xmlMemStrdupLoc((str), __FILE__, __LINE__)
208
209#endif /* DEBUG_MEMORY_LOCATION */
210
211#ifdef __cplusplus
212}
213#endif /* __cplusplus */
214
215#ifndef __XML_GLOBALS_H
216#ifndef __XML_THREADS_H__
217#include <libxml/threads.h>
218#include <libxml/globals.h>
219#endif
220#endif
221
222#endif  /* __DEBUG_MEMORY_ALLOC__ */
223
Note: See TracBrowser for help on using the repository browser.