ReactOS 0.4.16-dev-2232-gc2aaa52
xmlmemory.h
Go to the documentation of this file.
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#ifdef __cplusplus
19extern "C" {
20#endif
21
22/*
23 * The XML memory wrapper support 4 basic overloadable functions.
24 */
31typedef void (*xmlFreeFunc)(void *mem);
40typedef void *(LIBXML_ATTR_ALLOC_SIZE(1) *xmlMallocFunc)(size_t size);
41
51typedef void *(*xmlReallocFunc)(void *mem, size_t size);
52
61typedef char *(*xmlStrdupFunc)(const char *str);
62
63/*
64 * In general the memory allocation entry points are not kept
65 * thread specific but this can be overridden by LIBXML_THREAD_ALLOC_ENABLED
66 * - xmlMalloc
67 * - xmlMallocAtomic
68 * - xmlRealloc
69 * - xmlMemStrdup
70 * - xmlFree
71 */
73#ifdef LIBXML_THREAD_ALLOC_ENABLED
74 #define XML_GLOBALS_ALLOC \
75 XML_OP(xmlMalloc, xmlMallocFunc, XML_NO_ATTR) \
76 XML_OP(xmlMallocAtomic, xmlMallocFunc, XML_NO_ATTR) \
77 XML_OP(xmlRealloc, xmlReallocFunc, XML_NO_ATTR) \
78 XML_OP(xmlFree, xmlFreeFunc, XML_NO_ATTR) \
79 XML_OP(xmlMemStrdup, xmlStrdupFunc, XML_NO_ATTR)
80 #define XML_OP XML_DECLARE_GLOBAL
82 #undef XML_OP
83 #if defined(LIBXML_THREAD_ENABLED) && !defined(XML_GLOBALS_NO_REDEFINITION)
84 #define xmlMalloc XML_GLOBAL_MACRO(xmlMalloc)
85 #define xmlMallocAtomic XML_GLOBAL_MACRO(xmlMallocAtomic)
86 #define xmlRealloc XML_GLOBAL_MACRO(xmlRealloc)
87 #define xmlFree XML_GLOBAL_MACRO(xmlFree)
88 #define xmlMemStrdup XML_GLOBAL_MACRO(xmlMemStrdup)
89 #endif
90#else
91 #define XML_GLOBALS_ALLOC
93 XMLPUBVAR xmlMallocFunc xmlMalloc;
98#endif
99
100/*
101 * The way to overload the existing functions.
102 * The xmlGc function have an extra entry for atomic block
103 * allocations useful for garbage collected memory allocators
104 */
105XMLPUBFUN int
106 xmlMemSetup (xmlFreeFunc freeFunc,
107 xmlMallocFunc mallocFunc,
108 xmlReallocFunc reallocFunc,
109 xmlStrdupFunc strdupFunc);
110XMLPUBFUN int
111 xmlMemGet (xmlFreeFunc *freeFunc,
112 xmlMallocFunc *mallocFunc,
113 xmlReallocFunc *reallocFunc,
114 xmlStrdupFunc *strdupFunc);
115XMLPUBFUN int
116 xmlGcMemSetup (xmlFreeFunc freeFunc,
117 xmlMallocFunc mallocFunc,
118 xmlMallocFunc mallocAtomicFunc,
119 xmlReallocFunc reallocFunc,
120 xmlStrdupFunc strdupFunc);
121XMLPUBFUN int
122 xmlGcMemGet (xmlFreeFunc *freeFunc,
123 xmlMallocFunc *mallocFunc,
124 xmlMallocFunc *mallocAtomicFunc,
125 xmlReallocFunc *reallocFunc,
126 xmlStrdupFunc *strdupFunc);
127
128/*
129 * Initialization of the memory layer.
130 */
132XMLPUBFUN int
133 xmlInitMemory (void);
134
135/*
136 * Cleanup of the memory layer.
137 */
139XMLPUBFUN void
140 xmlCleanupMemory (void);
141/*
142 * These are specific to the XML debug memory wrapper.
143 */
144XMLPUBFUN size_t
145 xmlMemSize (void *ptr);
146XMLPUBFUN int
147 xmlMemUsed (void);
148XMLPUBFUN int
149 xmlMemBlocks (void);
150XMLPUBFUN void
151 xmlMemDisplay (FILE *fp);
152XMLPUBFUN void
153 xmlMemDisplayLast(FILE *fp, long nbBytes);
154XMLPUBFUN void
155 xmlMemShow (FILE *fp, int nr);
156XMLPUBFUN void
157 xmlMemoryDump (void);
158XMLPUBFUN void *
160XMLPUBFUN void *
161 xmlMemRealloc (void *ptr,size_t size);
162XMLPUBFUN void
163 xmlMemFree (void *ptr);
164XMLPUBFUN char *
165 xmlMemoryStrdup (const char *str);
166XMLPUBFUN void *
167 xmlMallocLoc (size_t size, const char *file, int line) LIBXML_ATTR_ALLOC_SIZE(1);
168XMLPUBFUN void *
169 xmlReallocLoc (void *ptr, size_t size, const char *file, int line);
170XMLPUBFUN void *
171 xmlMallocAtomicLoc (size_t size, const char *file, int line) LIBXML_ATTR_ALLOC_SIZE(1);
172XMLPUBFUN char *
173 xmlMemStrdupLoc (const char *str, const char *file, int line);
174
175
177#ifdef DEBUG_MEMORY_LOCATION
186#define xmlMalloc(size) xmlMallocLoc((size), __FILE__, __LINE__)
196#define xmlMallocAtomic(size) xmlMallocAtomicLoc((size), __FILE__, __LINE__)
206#define xmlRealloc(ptr, size) xmlReallocLoc((ptr), (size), __FILE__, __LINE__)
215#define xmlMemStrdup(str) xmlMemStrdupLoc((str), __FILE__, __LINE__)
216
217#endif /* DEBUG_MEMORY_LOCATION */
220#ifdef __cplusplus
221}
222#endif /* __cplusplus */
223
224#endif /* __DEBUG_MEMORY_ALLOC__ */
GLsizeiptr size
Definition: glext.h:5919
static PVOID ptr
Definition: dispmode.c:27
ULONG nr
Definition: thread.c:7
const WCHAR * str
Definition: fci.c:127
Definition: parser.c:49
Definition: mem.c:349
#define XMLPUBFUN
Definition: xmlexports.h:30
#define XMLPUBVAR
Definition: xmlexports.h:37
XMLPUBFUN char * xmlMemoryStrdup(const char *str)
Definition: xmlmemory.c:510
void *(* xmlReallocFunc)(void *mem, size_t size)
Definition: xmlmemory.h:51
XMLPUBFUN int xmlGcMemSetup(xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, xmlMallocFunc mallocAtomicFunc, xmlReallocFunc reallocFunc, xmlStrdupFunc strdupFunc)
Definition: xmlmemory.c:967
XMLPUBFUN int xmlGcMemGet(xmlFreeFunc *freeFunc, xmlMallocFunc *mallocFunc, xmlMallocFunc *mallocAtomicFunc, xmlReallocFunc *reallocFunc, xmlStrdupFunc *strdupFunc)
Definition: xmlmemory.c:1003
XMLPUBFUN void * xmlMallocAtomicLoc(size_t size, const char *file, int line) LIBXML_ATTR_ALLOC_SIZE(1)
Definition: xmlmemory.c:210
XMLPUBFUN void xmlMemFree(void *ptr)
Definition: xmlmemory.c:381
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
Definition: xmlmemory.h:94
XMLPUBVAR xmlStrdupFunc xmlMemStrdup
Definition: xmlmemory.h:97
XMLPUBFUN char * xmlMemStrdupLoc(const char *str, const char *file, int line)
Definition: xmlmemory.c:446
XMLPUBFUN void * xmlMemRealloc(void *ptr, size_t size)
Definition: xmlmemory.c:370
XMLPUBFUN void xmlMemoryDump(void)
Definition: xmlmemory.c:802
#define XML_GLOBALS_ALLOC
Definition: xmlmemory.h:91
char *(* xmlStrdupFunc)(const char *str)
Definition: xmlmemory.h:61
XMLPUBFUN int xmlMemGet(xmlFreeFunc *freeFunc, xmlMallocFunc *mallocFunc, xmlReallocFunc *reallocFunc, xmlStrdupFunc *strdupFunc)
Definition: xmlmemory.c:939
XMLPUBFUN size_t xmlMemSize(void *ptr)
Definition: xmlmemory.c:522
XMLPUBFUN void * xmlReallocLoc(void *ptr, size_t size, const char *file, int line)
Definition: xmlmemory.c:290
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: xmlmemory.h:93
XMLPUBFUN int xmlMemBlocks(void)
Definition: xmlmemory.c:557
XMLPUBFUN void * xmlMemMalloc(size_t size) LIBXML_ATTR_ALLOC_SIZE(1)
Definition: xmlmemory.c:272
XMLPUBFUN int xmlMemUsed(void)
Definition: xmlmemory.c:544
XML_DEPRECATED XMLPUBFUN int xmlInitMemory(void)
Definition: xmlmemory.c:833
void(* xmlFreeFunc)(void *mem)
Definition: xmlmemory.h:31
XMLPUBFUN void xmlMemShow(FILE *fp, int nr)
Definition: xmlmemory.c:758
XMLPUBFUN void * xmlMallocLoc(size_t size, const char *file, int line) LIBXML_ATTR_ALLOC_SIZE(1)
Definition: xmlmemory.c:145
XMLPUBFUN int xmlMemSetup(xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, xmlReallocFunc reallocFunc, xmlStrdupFunc strdupFunc)
Definition: xmlmemory.c:909
void * LIBXML_ATTR_ALLOC_SIZE(1) *xmlMallocFunc)(size_t size)
Definition: xmlmemory.h:40
XMLPUBVAR xmlFreeFunc xmlFree
Definition: xmlmemory.h:96
XMLPUBFUN void xmlMemDisplayLast(FILE *fp, long nbBytes)
Definition: xmlmemory.c:577
XMLPUBFUN void xmlMemDisplay(FILE *fp)
Definition: xmlmemory.c:644
XMLPUBVAR xmlReallocFunc xmlRealloc
Definition: xmlmemory.h:95
XML_DEPRECATED XMLPUBFUN void xmlCleanupMemory(void)
Definition: xmlmemory.c:870
#define XML_DEPRECATED
Definition: xmlversion.h:475