-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmlmemory.c
More file actions
350 lines (319 loc) · 8.6 KB
/
Copy pathxmlmemory.c
File metadata and controls
350 lines (319 loc) · 8.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/*
* xmlmemory.c: libxml memory allocator wrapper.
*
* Author: Daniel Veillard
*/
#define IN_LIBXML
#include "libxml.h"
#ifdef LIBXML_MEMORY_ENABLED
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/xmlerror.h>
#include <libxml/parser.h>
#include <libxml/threads.h>
#include "private/error.h"
#include "private/memory.h"
/************************************************************************
* *
* Macros, variables and associated types *
* *
************************************************************************/
/**
* @deprecated don't use
*
* @param size an int specifying the size in byte to allocate.
* @param file the file name or NULL
* @param line the line number
* @returns a pointer to the allocated area or NULL in case of lack of memory.
*/
void *
xmlMallocLoc(size_t size, const char *file ATTRIBUTE_UNUSED,
int line ATTRIBUTE_UNUSED)
{
return(xmlMemMalloc(size));
}
/**
* @deprecated don't use
*
* @param size an unsigned int specifying the size in byte to allocate.
* @param file the file name or NULL
* @param line the line number
* @returns a pointer to the allocated area or NULL in case of lack of memory.
*/
void *
xmlMallocAtomicLoc(size_t size, const char *file ATTRIBUTE_UNUSED,
int line ATTRIBUTE_UNUSED)
{
return(xmlMemMalloc(size));
}
/**
* @deprecated don't use
*
* @param size an int specifying the size in byte to allocate.
* @returns a pointer to the allocated area or NULL in case of lack of memory.
*/
void *
xmlMemMalloc(size_t size)
{
return malloc(size);
}
/**
* @deprecated don't use
*
* @param ptr the initial memory block pointer
* @param size an int specifying the size in byte to allocate.
* @param file the file name or NULL
* @param line the line number
* @returns a pointer to the allocated area or NULL in case of lack of memory.
*/
void *
xmlReallocLoc(void *ptr, size_t size, const char *file ATTRIBUTE_UNUSED,
int line ATTRIBUTE_UNUSED)
{
return(xmlMemRealloc(ptr, size));
}
/**
* @deprecated don't use
*
* @param ptr the initial memory block pointer
* @param size an int specifying the size in byte to allocate.
* @returns a pointer to the allocated area or NULL in case of lack of memory.
*/
void *
xmlMemRealloc(void *ptr, size_t size) {
return realloc(ptr, size);
}
/**
* @deprecated don't use
*
* @param ptr the memory block pointer
*/
void
xmlMemFree(void *ptr)
{
free(ptr);
}
/**
* @deprecated don't use
*
* @param str the initial string pointer
* @param file the file name or NULL
* @param line the line number
* @returns a pointer to the new string or NULL if allocation error occurred.
*/
char *
xmlMemStrdupLoc(const char *str, const char *file ATTRIBUTE_UNUSED,
int line ATTRIBUTE_UNUSED)
{
return(xmlMemoryStrdup(str));
}
/**
* @deprecated don't use
*
* @param str the initial string pointer
* @returns a pointer to the new string or NULL if allocation error occurred.
*/
char *
xmlMemoryStrdup(const char *str) {
return xmlPosixStrdup(str);
}
/**
* @deprecated don't use
*
* @param ptr pointer to the memory allocation
* @returns the size of a memory allocation.
*/
size_t
xmlMemSize(void *ptr ATTRIBUTE_UNUSED) {
return 0;
}
/**
* @deprecated don't use
*
* @returns an int representing the amount of memory allocated.
*/
int
xmlMemUsed(void) {
return 0;
}
/**
* @deprecated don't use
*
* @returns an int representing the number of blocks
*/
int
xmlMemBlocks(void) {
return 0;
}
/**
* @deprecated This feature was removed.
* @param fp a FILE descriptor
* @param nbBytes the amount of memory to dump
*/
void
xmlMemDisplayLast(FILE *fp ATTRIBUTE_UNUSED, long nbBytes ATTRIBUTE_UNUSED)
{
}
/**
* @deprecated This feature was removed.
* @param fp a FILE descriptor
*/
void
xmlMemDisplay(FILE *fp ATTRIBUTE_UNUSED)
{
}
/**
* @deprecated This feature was removed.
* @param fp a FILE descriptor
* @param nr number of entries to dump
*/
void
xmlMemShow(FILE *fp ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED)
{
}
/**
* @deprecated This feature was removed.
*/
void
xmlMemoryDump(void)
{
}
/****************************************************************
* *
* Initialization Routines *
* *
****************************************************************/
/**
* @deprecated Alias for #xmlInitParser.
*
* @returns 0.
*/
int
xmlInitMemory(void) {
xmlInitParser();
return(0);
}
/**
* @deprecated This function is a no-op. Call #xmlCleanupParser
* to free global state but see the warnings there. #xmlCleanupParser
* should be only called once at program exit. In most cases, you don't
* have call cleanup functions at all.
*/
void
xmlCleanupMemory(void) {
}
/**
* Override the default memory access functions with a new set
* This has to be called before any other libxml routines !
*
* Should this be blocked if there was already some allocations
* done ?
*
* @param freeFunc the free() function to use
* @param mallocFunc the malloc() function to use
* @param reallocFunc the realloc() function to use
* @param strdupFunc the strdup() function to use
* @returns 0 on success
*/
int
xmlMemSetup(xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc,
xmlReallocFunc reallocFunc, xmlStrdupFunc strdupFunc) {
if (freeFunc == NULL)
return(-1);
if (mallocFunc == NULL)
return(-1);
if (reallocFunc == NULL)
return(-1);
if (strdupFunc == NULL)
return(-1);
xmlFree = freeFunc;
xmlMalloc = mallocFunc;
xmlMallocAtomic = mallocFunc;
xmlRealloc = reallocFunc;
xmlMemStrdup = strdupFunc;
return(0);
}
/**
* Provides the memory access functions set currently in use
*
* @param freeFunc place to save the free() function in use
* @param mallocFunc place to save the malloc() function in use
* @param reallocFunc place to save the realloc() function in use
* @param strdupFunc place to save the strdup() function in use
* @returns 0 on success
*/
int
xmlMemGet(xmlFreeFunc *freeFunc, xmlMallocFunc *mallocFunc,
xmlReallocFunc *reallocFunc, xmlStrdupFunc *strdupFunc) {
if (freeFunc != NULL) *freeFunc = xmlFree;
if (mallocFunc != NULL) *mallocFunc = xmlMalloc;
if (reallocFunc != NULL) *reallocFunc = xmlRealloc;
if (strdupFunc != NULL) *strdupFunc = xmlMemStrdup;
return(0);
}
/**
* Override the default memory access functions with a new set
* This has to be called before any other libxml routines !
* The mallocAtomicFunc is specialized for atomic block
* allocations (i.e. of areas useful for garbage collected memory allocators
*
* @deprecated Use #xmlMemSetup.
*
* Should this be blocked if there was already some allocations
* done ?
*
* @param freeFunc the free() function to use
* @param mallocFunc the malloc() function to use
* @param mallocAtomicFunc the malloc() function to use for atomic allocations
* @param reallocFunc the realloc() function to use
* @param strdupFunc the strdup() function to use
* @returns 0 on success
*/
int
xmlGcMemSetup(xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc,
xmlMallocFunc mallocAtomicFunc, xmlReallocFunc reallocFunc,
xmlStrdupFunc strdupFunc) {
if (freeFunc == NULL)
return(-1);
if (mallocFunc == NULL)
return(-1);
if (mallocAtomicFunc == NULL)
return(-1);
if (reallocFunc == NULL)
return(-1);
if (strdupFunc == NULL)
return(-1);
xmlFree = freeFunc;
xmlMalloc = mallocFunc;
xmlMallocAtomic = mallocAtomicFunc;
xmlRealloc = reallocFunc;
xmlMemStrdup = strdupFunc;
return(0);
}
/**
* Provides the memory access functions set currently in use
* The mallocAtomicFunc is specialized for atomic block
* allocations (i.e. of areas useful for garbage collected memory allocators
*
* @deprecated Use #xmlMemGet.
*
* @param freeFunc place to save the free() function in use
* @param mallocFunc place to save the malloc() function in use
* @param mallocAtomicFunc place to save the atomic malloc() function in use
* @param reallocFunc place to save the realloc() function in use
* @param strdupFunc place to save the strdup() function in use
* @returns 0 on success
*/
int
xmlGcMemGet(xmlFreeFunc *freeFunc, xmlMallocFunc *mallocFunc,
xmlMallocFunc *mallocAtomicFunc, xmlReallocFunc *reallocFunc,
xmlStrdupFunc *strdupFunc) {
if (freeFunc != NULL) *freeFunc = xmlFree;
if (mallocFunc != NULL) *mallocFunc = xmlMalloc;
if (mallocAtomicFunc != NULL) *mallocAtomicFunc = xmlMallocAtomic;
if (reallocFunc != NULL) *reallocFunc = xmlRealloc;
if (strdupFunc != NULL) *strdupFunc = xmlMemStrdup;
return(0);
}
#endif /* LIBXML_MEMORY_ENABLED */