2 * xmlmemory.c: libxml memory allocator wrapper.
12 #ifdef HAVE_SYS_TYPES_H
13 #include <sys/types.h>
32 /* #define DEBUG_MEMORY */
37 * keep track of all allocated blocks for error reporting
38 * Always build the memory list !
40 #ifdef DEBUG_MEMORY_LOCATION
42 #define MEM_LIST /* keep a list of all the allocated memory blocks */
46 #include <libxml/globals.h> /* must come before xmlmemory.h */
47 #include <libxml/xmlmemory.h>
48 #include <libxml/xmlerror.h>
49 #include <libxml/threads.h>
51 static int xmlMemInitialized
= 0;
52 static unsigned long debugMemSize
= 0;
53 static unsigned long debugMemBlocks
= 0;
54 static unsigned long debugMaxMemSize
= 0;
55 static xmlMutexPtr xmlMemMutex
= NULL
;
57 void xmlMallocBreakpoint(void);
59 /************************************************************************
61 * Macros, variables and associated types *
63 ************************************************************************/
65 #if !defined(LIBXML_THREAD_ENABLED) && !defined(LIBXML_THREAD_ALLOC_ENABLED)
78 * Each of the blocks allocated begin with a header containing informations
84 #define REALLOC_TYPE 2
86 #define MALLOC_ATOMIC_TYPE 4
87 #define REALLOC_ATOMIC_TYPE 5
89 typedef struct memnod
{
92 unsigned long mh_number
;
95 struct memnod
*mh_next
;
96 struct memnod
*mh_prev
;
104 #define ALIGN_SIZE 16
106 #define ALIGN_SIZE sizeof(double)
108 #define HDR_SIZE sizeof(MEMHDR)
109 #define RESERVE_SIZE (((HDR_SIZE + (ALIGN_SIZE-1)) \
110 / ALIGN_SIZE ) * ALIGN_SIZE)
113 #define CLIENT_2_HDR(a) ((MEMHDR *) (((char *) (a)) - RESERVE_SIZE))
114 #define HDR_2_CLIENT(a) ((void *) (((char *) (a)) + RESERVE_SIZE))
117 static unsigned int block
=0;
118 static unsigned int xmlMemStopAtBlock
= 0;
119 static void *xmlMemTraceBlockAt
= NULL
;
121 static MEMHDR
*memlist
= NULL
;
124 static void debugmem_tag_error(void *addr
);
126 static void debugmem_list_add(MEMHDR
*);
127 static void debugmem_list_delete(MEMHDR
*);
129 #define Mem_Tag_Err(a) debugmem_tag_error(a);
136 * xmlMallocBreakpoint:
138 * Breakpoint to use in conjunction with xmlMemStopAtBlock. When the block
139 * number reaches the specified value this function is called. One need to add a breakpoint
140 * to it to get the context in which the given block is allocated.
144 xmlMallocBreakpoint(void) {
145 xmlGenericError(xmlGenericErrorContext
,
146 "xmlMallocBreakpoint reached on block %d\n", xmlMemStopAtBlock
);
151 * @size: an int specifying the size in byte to allocate.
152 * @file: the file name or NULL
153 * @line: the line number
155 * a malloc() equivalent, with logging of the allocation info.
157 * Returns a pointer to the allocated area or NULL in case of lack of memory.
161 xmlMallocLoc(size_t size
, const char * file
, int line
)
166 if (!xmlMemInitialized
) xmlInitMemory();
168 xmlGenericError(xmlGenericErrorContext
,
169 "Malloc(%d)\n",size
);
174 p
= (MEMHDR
*) malloc(RESERVE_SIZE
+size
);
177 xmlGenericError(xmlGenericErrorContext
,
178 "xmlMallocLoc : Out of free space\n");
184 p
->mh_type
= MALLOC_TYPE
;
187 xmlMutexLock(xmlMemMutex
);
188 p
->mh_number
= ++block
;
189 debugMemSize
+= size
;
191 if (debugMemSize
> debugMaxMemSize
) debugMaxMemSize
= debugMemSize
;
193 debugmem_list_add(p
);
195 xmlMutexUnlock(xmlMemMutex
);
198 xmlGenericError(xmlGenericErrorContext
,
199 "Malloc(%d) Ok\n",size
);
202 if (xmlMemStopAtBlock
== p
->mh_number
) xmlMallocBreakpoint();
204 ret
= HDR_2_CLIENT(p
);
206 if (xmlMemTraceBlockAt
== ret
) {
207 xmlGenericError(xmlGenericErrorContext
,
208 "%p : Malloc(%lu) Ok\n", xmlMemTraceBlockAt
,
209 (long unsigned)size
);
210 xmlMallocBreakpoint();
219 * xmlMallocAtomicLoc:
220 * @size: an int specifying the size in byte to allocate.
221 * @file: the file name or NULL
222 * @line: the line number
224 * a malloc() equivalent, with logging of the allocation info.
226 * Returns a pointer to the allocated area or NULL in case of lack of memory.
230 xmlMallocAtomicLoc(size_t size
, const char * file
, int line
)
235 if (!xmlMemInitialized
) xmlInitMemory();
237 xmlGenericError(xmlGenericErrorContext
,
238 "Malloc(%d)\n",size
);
243 p
= (MEMHDR
*) malloc(RESERVE_SIZE
+size
);
246 xmlGenericError(xmlGenericErrorContext
,
247 "xmlMallocLoc : Out of free space\n");
253 p
->mh_type
= MALLOC_ATOMIC_TYPE
;
256 xmlMutexLock(xmlMemMutex
);
257 p
->mh_number
= ++block
;
258 debugMemSize
+= size
;
260 if (debugMemSize
> debugMaxMemSize
) debugMaxMemSize
= debugMemSize
;
262 debugmem_list_add(p
);
264 xmlMutexUnlock(xmlMemMutex
);
267 xmlGenericError(xmlGenericErrorContext
,
268 "Malloc(%d) Ok\n",size
);
271 if (xmlMemStopAtBlock
== p
->mh_number
) xmlMallocBreakpoint();
273 ret
= HDR_2_CLIENT(p
);
275 if (xmlMemTraceBlockAt
== ret
) {
276 xmlGenericError(xmlGenericErrorContext
,
277 "%p : Malloc(%lu) Ok\n", xmlMemTraceBlockAt
,
278 (long unsigned)size
);
279 xmlMallocBreakpoint();
288 * @size: an int specifying the size in byte to allocate.
290 * a malloc() equivalent, with logging of the allocation info.
292 * Returns a pointer to the allocated area or NULL in case of lack of memory.
296 xmlMemMalloc(size_t size
)
298 return(xmlMallocLoc(size
, "none", 0));
303 * @ptr: the initial memory block pointer
304 * @size: an int specifying the size in byte to allocate.
305 * @file: the file name or NULL
306 * @line: the line number
308 * a realloc() equivalent, with logging of the allocation info.
310 * Returns a pointer to the allocated area or NULL in case of lack of memory.
314 xmlReallocLoc(void *ptr
,size_t size
, const char * file
, int line
)
317 unsigned long number
;
323 return(xmlMallocLoc(size
, file
, line
));
325 if (!xmlMemInitialized
) xmlInitMemory();
328 p
= CLIENT_2_HDR(ptr
);
329 number
= p
->mh_number
;
330 if (xmlMemStopAtBlock
== number
) xmlMallocBreakpoint();
331 if (p
->mh_tag
!= MEMTAG
) {
336 xmlMutexLock(xmlMemMutex
);
337 debugMemSize
-= p
->mh_size
;
340 oldsize
= p
->mh_size
;
343 debugmem_list_delete(p
);
345 xmlMutexUnlock(xmlMemMutex
);
347 tmp
= (MEMHDR
*) realloc(p
,RESERVE_SIZE
+size
);
353 if (xmlMemTraceBlockAt
== ptr
) {
354 xmlGenericError(xmlGenericErrorContext
,
355 "%p : Realloced(%lu -> %lu) Ok\n",
356 xmlMemTraceBlockAt
, (long unsigned)p
->mh_size
,
357 (long unsigned)size
);
358 xmlMallocBreakpoint();
361 p
->mh_number
= number
;
362 p
->mh_type
= REALLOC_TYPE
;
366 xmlMutexLock(xmlMemMutex
);
367 debugMemSize
+= size
;
369 if (debugMemSize
> debugMaxMemSize
) debugMaxMemSize
= debugMemSize
;
371 debugmem_list_add(p
);
373 xmlMutexUnlock(xmlMemMutex
);
378 xmlGenericError(xmlGenericErrorContext
,
379 "Realloced(%d to %d) Ok\n", oldsize
, size
);
381 return(HDR_2_CLIENT(p
));
389 * @ptr: the initial memory block pointer
390 * @size: an int specifying the size in byte to allocate.
392 * a realloc() equivalent, with logging of the allocation info.
394 * Returns a pointer to the allocated area or NULL in case of lack of memory.
398 xmlMemRealloc(void *ptr
,size_t size
) {
399 return(xmlReallocLoc(ptr
, size
, "none", 0));
404 * @ptr: the memory block pointer
406 * a free() equivalent, with error checking.
409 xmlMemFree(void *ptr
)
420 if (ptr
== (void *) -1) {
421 xmlGenericError(xmlGenericErrorContext
,
422 "trying to free pointer from freed area\n");
426 if (xmlMemTraceBlockAt
== ptr
) {
427 xmlGenericError(xmlGenericErrorContext
,
428 "%p : Freed()\n", xmlMemTraceBlockAt
);
429 xmlMallocBreakpoint();
434 target
= (char *) ptr
;
436 p
= CLIENT_2_HDR(ptr
);
437 if (p
->mh_tag
!= MEMTAG
) {
441 if (xmlMemStopAtBlock
== p
->mh_number
) xmlMallocBreakpoint();
443 memset(target
, -1, p
->mh_size
);
444 xmlMutexLock(xmlMemMutex
);
445 debugMemSize
-= p
->mh_size
;
451 debugmem_list_delete(p
);
453 xmlMutexUnlock(xmlMemMutex
);
460 xmlGenericError(xmlGenericErrorContext
,
461 "Freed(%d) Ok\n", size
);
467 xmlGenericError(xmlGenericErrorContext
,
468 "xmlMemFree(%lX) error\n", (unsigned long) ptr
);
469 xmlMallocBreakpoint();
475 * @str: the initial string pointer
476 * @file: the file name or NULL
477 * @line: the line number
479 * a strdup() equivalent, with logging of the allocation info.
481 * Returns a pointer to the new string or NULL if allocation error occurred.
485 xmlMemStrdupLoc(const char *str
, const char *file
, int line
)
488 size_t size
= strlen(str
) + 1;
491 if (!xmlMemInitialized
) xmlInitMemory();
494 p
= (MEMHDR
*) malloc(RESERVE_SIZE
+size
);
500 p
->mh_type
= STRDUP_TYPE
;
503 xmlMutexLock(xmlMemMutex
);
504 p
->mh_number
= ++block
;
505 debugMemSize
+= size
;
507 if (debugMemSize
> debugMaxMemSize
) debugMaxMemSize
= debugMemSize
;
509 debugmem_list_add(p
);
511 xmlMutexUnlock(xmlMemMutex
);
513 s
= (char *) HDR_2_CLIENT(p
);
515 if (xmlMemStopAtBlock
== p
->mh_number
) xmlMallocBreakpoint();
521 if (xmlMemTraceBlockAt
== s
) {
522 xmlGenericError(xmlGenericErrorContext
,
523 "%p : Strdup() Ok\n", xmlMemTraceBlockAt
);
524 xmlMallocBreakpoint();
535 * @str: the initial string pointer
537 * a strdup() equivalent, with logging of the allocation info.
539 * Returns a pointer to the new string or NULL if allocation error occurred.
543 xmlMemoryStrdup(const char *str
) {
544 return(xmlMemStrdupLoc(str
, "none", 0));
550 * Provides the amount of memory currently allocated
552 * Returns an int representing the amount of memory allocated.
557 return(debugMemSize
);
563 * Provides the number of memory areas currently allocated
565 * Returns an int representing the number of blocks
570 return(debugMemBlocks
);
576 * @fp: a FILE descriptor used as the output file
577 * @p: a memory block header
579 * tries to show some content from the memory block
583 xmlMemContentShow(FILE *fp
, MEMHDR
*p
)
589 fprintf(fp
, " NULL");
593 buf
= (const char *) HDR_2_CLIENT(p
);
595 for (i
= 0;i
< len
;i
++) {
596 if (buf
[i
] == 0) break;
597 if (!isprint((unsigned char) buf
[i
])) break;
599 if ((i
< 4) && ((buf
[i
] != 0) || (i
== 0))) {
604 for (j
= 0;(j
< len
-3) && (j
< 40);j
+= 4) {
605 cur
= *((void **) &buf
[j
]);
606 q
= CLIENT_2_HDR(cur
);
612 if (k
++ > 100) break;
614 if ((p
!= NULL
) && (p
== q
)) {
615 fprintf(fp
, " pointer to #%lu at index %d",
621 } else if ((i
== 0) && (buf
[i
] == 0)) {
624 if (buf
[i
] == 0) fprintf(fp
," \"%.25s\"", buf
);
627 for (j
= 0;j
< i
;j
++)
628 fprintf(fp
,"%c", buf
[j
]);
637 * @fp: a FILE descriptor used as the output file, if NULL, the result is
638 * written to the file .memorylist
639 * @nbBytes: the amount of memory to dump
641 * the last nbBytes of memory allocated and not freed, useful for dumping
642 * the memory left allocated between two places at runtime.
646 xmlMemDisplayLast(FILE *fp
, long nbBytes
)
659 fp
= fopen(".memorylist", "w");
665 fprintf(fp
," Last %li MEMORY ALLOCATED : %lu, MAX was %lu\n",
666 nbBytes
, debugMemSize
, debugMaxMemSize
);
667 fprintf(fp
,"BLOCK NUMBER SIZE TYPE\n");
669 xmlMutexLock(xmlMemMutex
);
671 while ((p
) && (nbBytes
> 0)) {
672 fprintf(fp
,"%-5u %6lu %6lu ",idx
++,p
->mh_number
,
673 (unsigned long)p
->mh_size
);
674 switch (p
->mh_type
) {
675 case STRDUP_TYPE
:fprintf(fp
,"strdup() in ");break;
676 case MALLOC_TYPE
:fprintf(fp
,"malloc() in ");break;
677 case REALLOC_TYPE
:fprintf(fp
,"realloc() in ");break;
678 case MALLOC_ATOMIC_TYPE
:fprintf(fp
,"atomicmalloc() in ");break;
679 case REALLOC_ATOMIC_TYPE
:fprintf(fp
,"atomicrealloc() in ");break;
681 fprintf(fp
,"Unknown memory block, may be corrupted");
682 xmlMutexUnlock(xmlMemMutex
);
687 if (p
->mh_file
!= NULL
) fprintf(fp
,"%s(%u)", p
->mh_file
, p
->mh_line
);
688 if (p
->mh_tag
!= MEMTAG
)
689 fprintf(fp
," INVALID");
692 xmlMemContentShow(fp
, p
);
697 nbBytes
-= (unsigned long)p
->mh_size
;
700 xmlMutexUnlock(xmlMemMutex
);
702 fprintf(fp
,"Memory list not compiled (MEM_LIST not defined !)\n");
710 * @fp: a FILE descriptor used as the output file, if NULL, the result is
711 * written to the file .memorylist
713 * show in-extenso the memory blocks allocated
717 xmlMemDisplay(FILE *fp
)
723 #if defined(HAVE_LOCALTIME) && defined(HAVE_STRFTIME)
732 fp
= fopen(".memorylist", "w");
738 #if defined(HAVE_LOCALTIME) && defined(HAVE_STRFTIME)
739 currentTime
= time(NULL
);
740 tstruct
= localtime(¤tTime
);
741 strftime(buf
, sizeof(buf
) - 1, "%I:%M:%S %p", tstruct
);
742 fprintf(fp
," %s\n\n", buf
);
746 fprintf(fp
," MEMORY ALLOCATED : %lu, MAX was %lu\n",
747 debugMemSize
, debugMaxMemSize
);
748 fprintf(fp
,"BLOCK NUMBER SIZE TYPE\n");
750 xmlMutexLock(xmlMemMutex
);
753 fprintf(fp
,"%-5u %6lu %6lu ",idx
++,p
->mh_number
,
754 (unsigned long)p
->mh_size
);
755 switch (p
->mh_type
) {
756 case STRDUP_TYPE
:fprintf(fp
,"strdup() in ");break;
757 case MALLOC_TYPE
:fprintf(fp
,"malloc() in ");break;
758 case REALLOC_TYPE
:fprintf(fp
,"realloc() in ");break;
759 case MALLOC_ATOMIC_TYPE
:fprintf(fp
,"atomicmalloc() in ");break;
760 case REALLOC_ATOMIC_TYPE
:fprintf(fp
,"atomicrealloc() in ");break;
762 fprintf(fp
,"Unknown memory block, may be corrupted");
763 xmlMutexUnlock(xmlMemMutex
);
768 if (p
->mh_file
!= NULL
) fprintf(fp
,"%s(%u)", p
->mh_file
, p
->mh_line
);
769 if (p
->mh_tag
!= MEMTAG
)
770 fprintf(fp
," INVALID");
773 xmlMemContentShow(fp
, p
);
780 xmlMutexUnlock(xmlMemMutex
);
782 fprintf(fp
,"Memory list not compiled (MEM_LIST not defined !)\n");
790 static void debugmem_list_add(MEMHDR
*p
)
792 p
->mh_next
= memlist
;
794 if (memlist
) memlist
->mh_prev
= p
;
796 #ifdef MEM_LIST_DEBUG
802 static void debugmem_list_delete(MEMHDR
*p
)
805 p
->mh_next
->mh_prev
= p
->mh_prev
;
807 p
->mh_prev
->mh_next
= p
->mh_next
;
808 else memlist
= p
->mh_next
;
809 #ifdef MEM_LIST_DEBUG
818 * debugmem_tag_error:
820 * internal error function.
823 static void debugmem_tag_error(void *p
)
825 xmlGenericError(xmlGenericErrorContext
,
826 "Memory tag error occurs :%p \n\t bye\n", p
);
829 xmlMemDisplay(stderr
);
834 static FILE *xmlMemoryDumpFile
= NULL
;
839 * @fp: a FILE descriptor used as the output file
840 * @nr: number of entries to dump
842 * show a show display of the memory allocated, and dump
843 * the @nr last allocated areas which were not freed
847 xmlMemShow(FILE *fp
, int nr ATTRIBUTE_UNUSED
)
854 fprintf(fp
," MEMORY ALLOCATED : %lu, MAX was %lu\n",
855 debugMemSize
, debugMaxMemSize
);
857 xmlMutexLock(xmlMemMutex
);
859 fprintf(fp
,"NUMBER SIZE TYPE WHERE\n");
861 while ((p
) && nr
> 0) {
862 fprintf(fp
,"%6lu %6lu ",p
->mh_number
,(unsigned long)p
->mh_size
);
863 switch (p
->mh_type
) {
864 case STRDUP_TYPE
:fprintf(fp
,"strdup() in ");break;
865 case MALLOC_TYPE
:fprintf(fp
,"malloc() in ");break;
866 case MALLOC_ATOMIC_TYPE
:fprintf(fp
,"atomicmalloc() in ");break;
867 case REALLOC_TYPE
:fprintf(fp
,"realloc() in ");break;
868 case REALLOC_ATOMIC_TYPE
:fprintf(fp
,"atomicrealloc() in ");break;
869 default:fprintf(fp
," ??? in ");break;
871 if (p
->mh_file
!= NULL
)
872 fprintf(fp
,"%s(%u)", p
->mh_file
, p
->mh_line
);
873 if (p
->mh_tag
!= MEMTAG
)
874 fprintf(fp
," INVALID");
875 xmlMemContentShow(fp
, p
);
881 xmlMutexUnlock(xmlMemMutex
);
882 #endif /* MEM_LIST */
888 * Dump in-extenso the memory blocks allocated to the file .memorylist
897 if (debugMaxMemSize
== 0)
899 dump
= fopen(".memdump", "w");
901 xmlMemoryDumpFile
= stderr
;
902 else xmlMemoryDumpFile
= dump
;
904 xmlMemDisplay(xmlMemoryDumpFile
);
906 if (dump
!= NULL
) fclose(dump
);
907 #endif /* MEM_LIST */
911 /****************************************************************
913 * Initialization Routines *
915 ****************************************************************/
920 * Initialize the memory layer.
922 * Returns 0 on success
931 xmlGenericError(xmlGenericErrorContext
,
932 "xmlInitMemory()\n");
935 This is really not good code (see Bug 130419). Suggestions for
936 improvement will be welcome!
938 if (xmlMemInitialized
) return(-1);
939 xmlMemInitialized
= 1;
940 xmlMemMutex
= xmlNewMutex();
943 breakpoint
= getenv("XML_MEM_BREAKPOINT");
944 if (breakpoint
!= NULL
) {
945 sscanf(breakpoint
, "%ud", &xmlMemStopAtBlock
);
949 breakpoint
= getenv("XML_MEM_TRACE");
950 if (breakpoint
!= NULL
) {
951 sscanf(breakpoint
, "%p", &xmlMemTraceBlockAt
);
956 xmlGenericError(xmlGenericErrorContext
,
957 "xmlInitMemory() Ok\n");
965 * Free up all the memory allocated by the library for its own
966 * use. This should not be called by user level code.
969 xmlCleanupMemory(void) {
971 xmlGenericError(xmlGenericErrorContext
,
972 "xmlCleanupMemory()\n");
974 if (xmlMemInitialized
== 0)
977 xmlFreeMutex(xmlMemMutex
);
979 xmlMemInitialized
= 0;
981 xmlGenericError(xmlGenericErrorContext
,
982 "xmlCleanupMemory() Ok\n");
988 * @freeFunc: the free() function to use
989 * @mallocFunc: the malloc() function to use
990 * @reallocFunc: the realloc() function to use
991 * @strdupFunc: the strdup() function to use
993 * Override the default memory access functions with a new set
994 * This has to be called before any other libxml routines !
996 * Should this be blocked if there was already some allocations
999 * Returns 0 on success
1002 xmlMemSetup(xmlFreeFunc freeFunc
, xmlMallocFunc mallocFunc
,
1003 xmlReallocFunc reallocFunc
, xmlStrdupFunc strdupFunc
) {
1005 xmlGenericError(xmlGenericErrorContext
,
1008 if (freeFunc
== NULL
)
1010 if (mallocFunc
== NULL
)
1012 if (reallocFunc
== NULL
)
1014 if (strdupFunc
== NULL
)
1017 xmlMalloc
= mallocFunc
;
1018 xmlMallocAtomic
= mallocFunc
;
1019 xmlRealloc
= reallocFunc
;
1020 xmlMemStrdup
= strdupFunc
;
1022 xmlGenericError(xmlGenericErrorContext
,
1023 "xmlMemSetup() Ok\n");
1030 * @freeFunc: place to save the free() function in use
1031 * @mallocFunc: place to save the malloc() function in use
1032 * @reallocFunc: place to save the realloc() function in use
1033 * @strdupFunc: place to save the strdup() function in use
1035 * Provides the memory access functions set currently in use
1037 * Returns 0 on success
1040 xmlMemGet(xmlFreeFunc
*freeFunc
, xmlMallocFunc
*mallocFunc
,
1041 xmlReallocFunc
*reallocFunc
, xmlStrdupFunc
*strdupFunc
) {
1042 if (freeFunc
!= NULL
) *freeFunc
= xmlFree
;
1043 if (mallocFunc
!= NULL
) *mallocFunc
= xmlMalloc
;
1044 if (reallocFunc
!= NULL
) *reallocFunc
= xmlRealloc
;
1045 if (strdupFunc
!= NULL
) *strdupFunc
= xmlMemStrdup
;
1051 * @freeFunc: the free() function to use
1052 * @mallocFunc: the malloc() function to use
1053 * @mallocAtomicFunc: the malloc() function to use for atomic allocations
1054 * @reallocFunc: the realloc() function to use
1055 * @strdupFunc: the strdup() function to use
1057 * Override the default memory access functions with a new set
1058 * This has to be called before any other libxml routines !
1059 * The mallocAtomicFunc is specialized for atomic block
1060 * allocations (i.e. of areas useful for garbage collected memory allocators
1062 * Should this be blocked if there was already some allocations
1065 * Returns 0 on success
1068 xmlGcMemSetup(xmlFreeFunc freeFunc
, xmlMallocFunc mallocFunc
,
1069 xmlMallocFunc mallocAtomicFunc
, xmlReallocFunc reallocFunc
,
1070 xmlStrdupFunc strdupFunc
) {
1072 xmlGenericError(xmlGenericErrorContext
,
1073 "xmlGcMemSetup()\n");
1075 if (freeFunc
== NULL
)
1077 if (mallocFunc
== NULL
)
1079 if (mallocAtomicFunc
== NULL
)
1081 if (reallocFunc
== NULL
)
1083 if (strdupFunc
== NULL
)
1086 xmlMalloc
= mallocFunc
;
1087 xmlMallocAtomic
= mallocAtomicFunc
;
1088 xmlRealloc
= reallocFunc
;
1089 xmlMemStrdup
= strdupFunc
;
1091 xmlGenericError(xmlGenericErrorContext
,
1092 "xmlGcMemSetup() Ok\n");
1099 * @freeFunc: place to save the free() function in use
1100 * @mallocFunc: place to save the malloc() function in use
1101 * @mallocAtomicFunc: place to save the atomic malloc() function in use
1102 * @reallocFunc: place to save the realloc() function in use
1103 * @strdupFunc: place to save the strdup() function in use
1105 * Provides the memory access functions set currently in use
1106 * The mallocAtomicFunc is specialized for atomic block
1107 * allocations (i.e. of areas useful for garbage collected memory allocators
1109 * Returns 0 on success
1112 xmlGcMemGet(xmlFreeFunc
*freeFunc
, xmlMallocFunc
*mallocFunc
,
1113 xmlMallocFunc
*mallocAtomicFunc
, xmlReallocFunc
*reallocFunc
,
1114 xmlStrdupFunc
*strdupFunc
) {
1115 if (freeFunc
!= NULL
) *freeFunc
= xmlFree
;
1116 if (mallocFunc
!= NULL
) *mallocFunc
= xmlMalloc
;
1117 if (mallocAtomicFunc
!= NULL
) *mallocAtomicFunc
= xmlMallocAtomic
;
1118 if (reallocFunc
!= NULL
) *reallocFunc
= xmlRealloc
;
1119 if (strdupFunc
!= NULL
) *strdupFunc
= xmlMemStrdup
;
1123 #define bottom_xmlmemory
1124 #include "elfgcchack.h"