2001-02-23 20:55:21 +03:00
/*
2002-01-01 19:50:03 +03:00
* xmlmemory . c : libxml memory allocator wrapper .
2001-02-23 20:55:21 +03:00
*
2001-06-24 16:13:24 +04:00
* daniel @ veillard . com
2001-02-23 20:55:21 +03:00
*/
2002-03-18 22:37:11 +03:00
# define IN_LIBXML
2001-04-21 20:57:29 +04:00
# include "libxml.h"
2001-02-23 20:55:21 +03:00
# include <string.h>
2022-03-02 02:29:17 +03:00
# include <stdlib.h>
# include <ctype.h>
# include <time.h>
2001-02-23 20:55:21 +03:00
# include <libxml/xmlmemory.h>
# include <libxml/xmlerror.h>
2023-09-20 18:00:50 +03:00
# include <libxml/parser.h>
2003-11-29 13:47:56 +03:00
# include <libxml/threads.h>
2001-02-23 20:55:21 +03:00
2022-11-24 22:52:57 +03:00
# include "private/memory.h"
2022-11-24 22:54:18 +03:00
# include "private/threads.h"
2022-11-24 22:52:57 +03:00
2003-09-29 13:22:39 +04:00
static unsigned long debugMemSize = 0 ;
2004-11-02 17:52:23 +03:00
static unsigned long debugMemBlocks = 0 ;
2022-11-24 22:54:18 +03:00
static xmlMutex xmlMemMutex ;
2003-09-28 22:58:27 +04:00
2001-03-24 20:00:36 +03:00
/************************************************************************
* *
2012-09-11 09:26:36 +04:00
* Macros , variables and associated types *
2001-03-24 20:00:36 +03:00
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-02-23 20:55:21 +03:00
/*
2020-03-08 19:19:42 +03:00
* Each of the blocks allocated begin with a header containing information
2001-02-23 20:55:21 +03:00
*/
2022-01-25 04:21:05 +03:00
# define MEMTAG 0x5aa5U
2001-02-23 20:55:21 +03:00
typedef struct memnod {
unsigned int mh_tag ;
size_t mh_size ;
2024-04-28 19:33:40 +03:00
} MEMHDR ;
2001-02-23 20:55:21 +03:00
# ifdef SUN4
# define ALIGN_SIZE 16
# else
# define ALIGN_SIZE sizeof(double)
# endif
2024-04-28 19:33:40 +03:00
# define RESERVE_SIZE (((sizeof(MEMHDR) + ALIGN_SIZE - 1) \
2001-02-23 20:55:21 +03:00
/ ALIGN_SIZE ) * ALIGN_SIZE )
2016-04-05 22:05:25 +03:00
# define MAX_SIZE_T ((size_t)-1)
2001-02-23 20:55:21 +03:00
2017-06-17 15:13:51 +03:00
# define CLIENT_2_HDR(a) ((void *) (((char *) (a)) - RESERVE_SIZE))
2001-02-23 20:55:21 +03:00
# define HDR_2_CLIENT(a) ((void *) (((char *) (a)) + RESERVE_SIZE))
/**
* xmlMallocLoc :
* @ size : an int specifying the size in byte to allocate .
* @ file : the file name or NULL
* @ line : the line number
*
2024-04-28 19:33:40 +03:00
* DEPRECATED : don ' t use
2001-02-23 20:55:21 +03:00
*
* Returns a pointer to the allocated area or NULL in case of lack of memory .
*/
void *
2024-04-28 19:33:40 +03:00
xmlMallocLoc ( size_t size , const char * file ATTRIBUTE_UNUSED ,
int line ATTRIBUTE_UNUSED )
2001-02-23 20:55:21 +03:00
{
2024-04-28 19:33:40 +03:00
return ( xmlMemMalloc ( size ) ) ;
2001-02-23 20:55:21 +03:00
}
2003-04-19 04:07:51 +04:00
/**
* xmlMallocAtomicLoc :
2016-04-05 22:05:25 +03:00
* @ size : an unsigned int specifying the size in byte to allocate .
2003-04-19 04:07:51 +04:00
* @ file : the file name or NULL
* @ line : the line number
*
2024-04-28 19:33:40 +03:00
* DEPRECATED : don ' t use
2003-04-19 04:07:51 +04:00
*
* Returns a pointer to the allocated area or NULL in case of lack of memory .
*/
2024-04-28 19:33:40 +03:00
void *
xmlMallocAtomicLoc ( size_t size , const char * file ATTRIBUTE_UNUSED ,
int line ATTRIBUTE_UNUSED )
{
return ( xmlMemMalloc ( size ) ) ;
}
2003-04-19 04:07:51 +04:00
2024-04-28 19:33:40 +03:00
/**
* xmlMemMalloc :
* @ size : an int specifying the size in byte to allocate .
*
* a malloc ( ) equivalent , with logging of the allocation info .
*
* Returns a pointer to the allocated area or NULL in case of lack of memory .
*/
2003-04-19 04:07:51 +04:00
void *
2024-04-28 19:33:40 +03:00
xmlMemMalloc ( size_t size )
2003-04-19 04:07:51 +04:00
{
MEMHDR * p ;
2008-07-30 16:58:11 +04:00
2022-11-25 14:21:49 +03:00
xmlInitParser ( ) ;
2003-04-19 04:07:51 +04:00
2016-04-05 22:05:25 +03:00
if ( size > ( MAX_SIZE_T - RESERVE_SIZE ) ) {
2024-04-28 19:33:40 +03:00
fprintf ( stderr , " xmlMemMalloc: Unsigned overflow \n " ) ;
return ( NULL ) ;
2016-04-05 22:05:25 +03:00
}
2024-04-28 19:33:40 +03:00
p = ( MEMHDR * ) malloc ( RESERVE_SIZE + size ) ;
2003-04-19 04:07:51 +04:00
if ( ! p ) {
2024-04-28 19:33:40 +03:00
fprintf ( stderr , " xmlMemMalloc: Out of memory \n " ) ;
return ( NULL ) ;
2008-07-30 16:58:11 +04:00
}
2003-04-19 04:07:51 +04:00
p - > mh_tag = MEMTAG ;
p - > mh_size = size ;
2024-04-28 19:33:40 +03:00
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlMemMutex ) ;
2003-04-19 04:07:51 +04:00
debugMemSize + = size ;
2004-11-02 17:52:23 +03:00
debugMemBlocks + + ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlMemMutex ) ;
2003-04-19 04:07:51 +04:00
2024-04-28 19:33:40 +03:00
return ( HDR_2_CLIENT ( p ) ) ;
2003-04-19 04:07:51 +04:00
}
2024-04-28 19:33:40 +03:00
2001-02-23 20:55:21 +03:00
/**
2024-04-28 19:33:40 +03:00
* xmlReallocLoc :
* @ ptr : the initial memory block pointer
2001-02-23 20:55:21 +03:00
* @ size : an int specifying the size in byte to allocate .
2024-04-28 19:33:40 +03:00
* @ file : the file name or NULL
* @ line : the line number
2001-02-23 20:55:21 +03:00
*
2024-04-28 19:33:40 +03:00
* DEPRECATED : don ' t use
2001-02-23 20:55:21 +03:00
*
* Returns a pointer to the allocated area or NULL in case of lack of memory .
*/
void *
2024-04-28 19:33:40 +03:00
xmlReallocLoc ( void * ptr , size_t size , const char * file ATTRIBUTE_UNUSED ,
int line ATTRIBUTE_UNUSED )
2001-02-23 20:55:21 +03:00
{
2024-04-28 19:33:40 +03:00
return ( xmlMemRealloc ( ptr , size ) ) ;
2001-02-23 20:55:21 +03:00
}
/**
2024-04-28 19:33:40 +03:00
* xmlMemRealloc :
2001-02-23 20:55:21 +03:00
* @ ptr : the initial memory block pointer
* @ size : an int specifying the size in byte to allocate .
*
* a realloc ( ) equivalent , with logging of the allocation info .
*
* Returns a pointer to the allocated area or NULL in case of lack of memory .
*/
void *
2024-04-28 19:33:40 +03:00
xmlMemRealloc ( void * ptr , size_t size ) {
2014-10-10 14:23:09 +04:00
MEMHDR * p , * tmp ;
2024-04-28 19:33:40 +03:00
size_t oldSize ;
2001-02-23 20:55:21 +03:00
2003-04-24 20:06:47 +04:00
if ( ptr = = NULL )
2024-04-28 19:33:40 +03:00
return ( xmlMemMalloc ( size ) ) ;
2004-01-23 01:20:31 +03:00
2022-11-25 14:21:49 +03:00
xmlInitParser ( ) ;
2024-04-28 19:33:40 +03:00
if ( size > ( MAX_SIZE_T - RESERVE_SIZE ) ) {
fprintf ( stderr , " xmlMemRealloc: Unsigned overflow \n " ) ;
return ( NULL ) ;
}
2001-02-23 20:55:21 +03:00
p = CLIENT_2_HDR ( ptr ) ;
if ( p - > mh_tag ! = MEMTAG ) {
2024-04-28 19:33:40 +03:00
fprintf ( stderr , " xmlMemRealloc: Tag error \n " ) ;
return ( NULL ) ;
2001-02-23 20:55:21 +03:00
}
2024-04-28 19:33:40 +03:00
oldSize = p - > mh_size ;
2001-02-23 20:55:21 +03:00
p - > mh_tag = ~ MEMTAG ;
2008-07-30 16:58:11 +04:00
2024-04-28 19:33:40 +03:00
tmp = ( MEMHDR * ) realloc ( p , RESERVE_SIZE + size ) ;
2014-10-10 14:23:09 +04:00
if ( ! tmp ) {
2024-04-28 19:33:40 +03:00
p - > mh_tag = MEMTAG ;
fprintf ( stderr , " xmlMemRealloc: Out of memory \n " ) ;
return ( NULL ) ;
2001-02-23 20:55:21 +03:00
}
2014-10-10 14:23:09 +04:00
p = tmp ;
2001-02-23 20:55:21 +03:00
p - > mh_tag = MEMTAG ;
p - > mh_size = size ;
2024-04-28 19:33:40 +03:00
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlMemMutex ) ;
2024-04-28 19:33:40 +03:00
debugMemSize - = oldSize ;
2001-02-23 20:55:21 +03:00
debugMemSize + = size ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlMemMutex ) ;
2001-02-23 20:55:21 +03:00
return ( HDR_2_CLIENT ( p ) ) ;
}
/**
* xmlMemFree :
* @ ptr : the memory block pointer
*
* a free ( ) equivalent , with error checking .
*/
void
xmlMemFree ( void * ptr )
{
MEMHDR * p ;
2007-10-30 23:24:40 +03:00
if ( ptr = = NULL )
2024-04-28 19:33:40 +03:00
return ;
2007-10-30 23:24:40 +03:00
2001-07-30 17:42:13 +04:00
if ( ptr = = ( void * ) - 1 ) {
2024-04-28 19:33:40 +03:00
fprintf ( stderr , " xmlMemFree: Pointer from freed area \n " ) ;
return ;
2001-07-30 17:42:13 +04:00
}
2001-02-23 20:55:21 +03:00
p = CLIENT_2_HDR ( ptr ) ;
if ( p - > mh_tag ! = MEMTAG ) {
2024-04-28 19:33:40 +03:00
fprintf ( stderr , " xmlMemFree: Tag error \n " ) ;
return ;
2001-02-23 20:55:21 +03:00
}
p - > mh_tag = ~ MEMTAG ;
2024-04-28 19:33:40 +03:00
memset ( ptr , - 1 , p - > mh_size ) ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlMemMutex ) ;
2003-11-29 13:47:56 +03:00
debugMemSize - = p - > mh_size ;
2004-11-02 17:52:23 +03:00
debugMemBlocks - - ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlMemMutex ) ;
2003-11-29 13:47:56 +03:00
2001-02-23 20:55:21 +03:00
free ( p ) ;
return ;
}
/**
* xmlMemStrdupLoc :
2002-01-22 21:15:52 +03:00
* @ str : the initial string pointer
2001-02-23 20:55:21 +03:00
* @ file : the file name or NULL
* @ line : the line number
*
2024-04-28 19:33:40 +03:00
* DEPRECATED : don ' t use
2001-02-23 20:55:21 +03:00
*
2002-01-01 19:50:03 +03:00
* Returns a pointer to the new string or NULL if allocation error occurred .
2001-02-23 20:55:21 +03:00
*/
char *
2024-04-28 19:33:40 +03:00
xmlMemStrdupLoc ( const char * str , const char * file ATTRIBUTE_UNUSED ,
int line ATTRIBUTE_UNUSED )
2001-02-23 20:55:21 +03:00
{
2024-04-28 19:33:40 +03:00
return ( xmlMemoryStrdup ( str ) ) ;
}
/**
* xmlMemoryStrdup :
* @ str : the initial string pointer
*
* a strdup ( ) equivalent , with logging of the allocation info .
*
* Returns a pointer to the new string or NULL if allocation error occurred .
*/
char *
xmlMemoryStrdup ( const char * str ) {
2001-02-23 20:55:21 +03:00
char * s ;
size_t size = strlen ( str ) + 1 ;
MEMHDR * p ;
2022-11-25 14:21:49 +03:00
xmlInitParser ( ) ;
2001-02-23 20:55:21 +03:00
2017-06-06 14:21:14 +03:00
if ( size > ( MAX_SIZE_T - RESERVE_SIZE ) ) {
2024-04-28 19:33:40 +03:00
fprintf ( stderr , " xmlMemoryStrdup: Unsigned overflow \n " ) ;
return ( NULL ) ;
2017-06-06 14:21:14 +03:00
}
2024-04-28 19:33:40 +03:00
p = ( MEMHDR * ) malloc ( RESERVE_SIZE + size ) ;
2001-02-23 20:55:21 +03:00
if ( ! p ) {
2024-04-28 19:33:40 +03:00
fprintf ( stderr , " xmlMemoryStrdup: Out of memory \n " ) ;
return ( NULL ) ;
2001-02-23 20:55:21 +03:00
}
p - > mh_tag = MEMTAG ;
p - > mh_size = size ;
2024-04-28 19:33:40 +03:00
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlMemMutex ) ;
2001-02-23 20:55:21 +03:00
debugMemSize + = size ;
2004-11-02 17:52:23 +03:00
debugMemBlocks + + ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlMemMutex ) ;
2008-07-30 16:58:11 +04:00
2001-02-23 20:55:21 +03:00
s = ( char * ) HDR_2_CLIENT ( p ) ;
2008-07-30 16:58:11 +04:00
2024-04-28 19:33:40 +03:00
memcpy ( s , str , size ) ;
2001-07-30 17:42:13 +04:00
2001-02-23 20:55:21 +03:00
return ( s ) ;
}
2023-03-14 15:02:36 +03:00
/**
* xmlMemSize :
* @ ptr : pointer to the memory allocation
*
* Returns the size of a memory allocation .
*/
size_t
xmlMemSize ( void * ptr ) {
MEMHDR * p ;
if ( ptr = = NULL )
return ( 0 ) ;
p = CLIENT_2_HDR ( ptr ) ;
if ( p - > mh_tag ! = MEMTAG )
return ( 0 ) ;
return ( p - > mh_size ) ;
}
2001-02-23 20:55:21 +03:00
/**
* xmlMemUsed :
*
2002-12-11 17:23:49 +03:00
* Provides the amount of memory currently allocated
2001-02-23 20:55:21 +03:00
*
* Returns an int representing the amount of memory allocated .
*/
int
xmlMemUsed ( void ) {
2022-11-25 19:39:01 +03:00
return ( debugMemSize ) ;
2001-02-23 20:55:21 +03:00
}
2004-11-02 17:52:23 +03:00
/**
* xmlMemBlocks :
*
* Provides the number of memory areas currently allocated
*
* Returns an int representing the number of blocks
*/
int
xmlMemBlocks ( void ) {
2015-04-13 11:32:14 +03:00
int res ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlMemMutex ) ;
2015-04-13 11:32:14 +03:00
res = debugMemBlocks ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlMemMutex ) ;
2015-04-13 11:32:14 +03:00
return ( res ) ;
2004-11-02 17:52:23 +03:00
}
2008-07-30 16:58:11 +04:00
/**
* xmlMemDisplayLast :
2024-04-28 19:33:40 +03:00
* @ fp : a FILE descriptor
2008-07-30 16:58:11 +04:00
* @ nbBytes : the amount of memory to dump
*
2024-04-28 19:33:40 +03:00
* DEPRECATED : This feature was removed .
2008-07-30 16:58:11 +04:00
*/
void
2024-04-28 19:33:40 +03:00
xmlMemDisplayLast ( FILE * fp ATTRIBUTE_UNUSED , long nbBytes ATTRIBUTE_UNUSED )
2008-07-30 16:58:11 +04:00
{
}
2001-02-23 20:55:21 +03:00
/**
* xmlMemDisplay :
2024-04-28 19:33:40 +03:00
* @ fp : a FILE descriptor
2001-02-23 20:55:21 +03:00
*
2024-04-28 19:33:40 +03:00
* DEPRECATED : This feature was removed .
2001-02-23 20:55:21 +03:00
*/
void
2024-04-28 19:33:40 +03:00
xmlMemDisplay ( FILE * fp ATTRIBUTE_UNUSED )
2001-02-23 20:55:21 +03:00
{
}
2003-09-29 13:22:39 +04:00
/**
* xmlMemShow :
2024-04-28 19:33:40 +03:00
* @ fp : a FILE descriptor
2003-09-29 13:22:39 +04:00
* @ nr : number of entries to dump
*
2024-04-28 19:33:40 +03:00
* DEPRECATED : This feature was removed .
2003-09-29 13:22:39 +04:00
*/
void
2024-04-28 19:33:40 +03:00
xmlMemShow ( FILE * fp ATTRIBUTE_UNUSED , int nr ATTRIBUTE_UNUSED )
2003-09-29 13:22:39 +04:00
{
}
2001-02-23 20:55:21 +03:00
/**
* xmlMemoryDump :
*
2024-04-28 19:33:40 +03:00
* DEPRECATED : This feature was removed .
2001-02-23 20:55:21 +03:00
*/
void
xmlMemoryDump ( void )
{
}
/****************************************************************
* *
* Initialization Routines *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* xmlInitMemory :
*
2022-11-24 22:52:57 +03:00
* DEPRECATED : Alias for xmlInitParser .
2024-05-20 14:58:22 +03:00
*
* Returns 0.
2022-11-24 22:52:57 +03:00
*/
int
xmlInitMemory ( void ) {
xmlInitParser ( ) ;
return ( 0 ) ;
}
/**
* xmlInitMemoryInternal :
2022-03-06 15:55:48 +03:00
*
2001-02-23 20:55:21 +03:00
* Initialize the memory layer .
*/
2022-11-24 22:52:57 +03:00
void
xmlInitMemoryInternal ( void ) {
2024-04-28 19:33:40 +03:00
xmlInitMutex ( & xmlMemMutex ) ;
2001-02-23 20:55:21 +03:00
}
2003-12-30 11:30:19 +03:00
/**
* xmlCleanupMemory :
*
2022-11-24 22:52:57 +03:00
* DEPRECATED : This function is a no - op . Call xmlCleanupParser
2022-03-06 15:55:48 +03:00
* 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 .
2022-11-24 22:52:57 +03:00
*/
void
xmlCleanupMemory ( void ) {
}
/**
* xmlCleanupMemoryInternal :
2022-03-06 15:55:48 +03:00
*
2004-12-10 13:26:42 +03:00
* Free up all the memory allocated by the library for its own
* use . This should not be called by user level code .
2003-12-30 11:30:19 +03:00
*/
void
2022-11-24 22:52:57 +03:00
xmlCleanupMemoryInternal ( void ) {
2023-09-22 00:29:18 +03:00
/*
* Don ' t clean up mutex on Windows . Global state destructors can call
* malloc functions after xmlCleanupParser was called . If memory
* debugging is enabled , xmlMemMutex can be used after cleanup .
*
* See python / tests / thread2 . py
*/
# if !defined(LIBXML_THREAD_ENABLED) || !defined(_WIN32)
2022-11-24 22:54:18 +03:00
xmlCleanupMutex ( & xmlMemMutex ) ;
2023-09-22 00:29:18 +03:00
# endif
2003-12-30 11:30:19 +03:00
}
2001-02-23 20:55:21 +03:00
/**
* xmlMemSetup :
* @ freeFunc : the free ( ) function to use
* @ mallocFunc : the malloc ( ) function to use
* @ reallocFunc : the realloc ( ) function to use
* @ strdupFunc : the strdup ( ) function to use
*
* 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 ?
*
* 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 ;
2003-04-19 04:07:51 +04:00
xmlMallocAtomic = mallocFunc ;
2001-02-23 20:55:21 +03:00
xmlRealloc = reallocFunc ;
xmlMemStrdup = strdupFunc ;
return ( 0 ) ;
}
/**
* xmlMemGet :
2002-12-11 17:23:49 +03:00
* @ freeFunc : place to save the free ( ) function in use
* @ mallocFunc : place to save the malloc ( ) function in use
* @ reallocFunc : place to save the realloc ( ) function in use
* @ strdupFunc : place to save the strdup ( ) function in use
2001-02-23 20:55:21 +03:00
*
2002-12-11 17:23:49 +03:00
* Provides the memory access functions set currently in use
2001-02-23 20:55:21 +03:00
*
* 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 ) ;
}
2003-04-19 04:07:51 +04:00
/**
* xmlGcMemSetup :
* @ freeFunc : the free ( ) function to use
* @ mallocFunc : the malloc ( ) function to use
* @ mallocAtomicFunc : the malloc ( ) function to use for atomic allocations
* @ reallocFunc : the realloc ( ) function to use
* @ strdupFunc : the strdup ( ) function to use
*
* 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
*
* Should this be blocked if there was already some allocations
* done ?
*
* 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 ) ;
}
/**
* xmlGcMemGet :
* @ freeFunc : place to save the free ( ) function in use
* @ mallocFunc : place to save the malloc ( ) function in use
* @ mallocAtomicFunc : place to save the atomic malloc ( ) function in use
* @ reallocFunc : place to save the realloc ( ) function in use
* @ strdupFunc : place to save the strdup ( ) function in use
*
* 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
*
* 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 ) ;
}