2001-02-23 17:55:21 +00:00
/*
2003-11-18 20:56:51 +00:00
* Summary : interface for the memory allocator
* Description : provides interfaces for the memory allocator ,
* including debugging capabilities .
2001-02-23 17:55:21 +00:00
*
2003-11-18 20:56:51 +00:00
* Copy : See Copyright for the status of this software .
*
* Author : Daniel Veillard
2001-02-23 17:55:21 +00:00
*/
2003-09-25 12:18:34 +00:00
# ifndef __DEBUG_MEMORY_ALLOC__
# define __DEBUG_MEMORY_ALLOC__
2001-02-23 17:55:21 +00:00
# include <stdio.h>
# include <libxml/xmlversion.h>
2001-05-19 13:24:56 +00:00
/**
* DEBUG_MEMORY :
*
2002-03-12 18:46:39 +00:00
* DEBUG_MEMORY replaces the allocator with a collect and debug
* shell to the libc allocator .
* DEBUG_MEMORY should only be activated when debugging
* libxml i . e . if libxml has been configured with - - with - debug - mem too .
2001-02-23 17:55:21 +00:00
*/
2001-02-25 16:11:03 +00:00
/* #define DEBUG_MEMORY_FREED */
2001-02-23 17:55:21 +00:00
/* #define DEBUG_MEMORY_LOCATION */
# ifdef DEBUG
# ifndef DEBUG_MEMORY
# define DEBUG_MEMORY
# endif
# endif
2001-05-19 13:24:56 +00:00
/**
* DEBUG_MEMORY_LOCATION :
*
* DEBUG_MEMORY_LOCATION should be activated only when debugging
2002-03-12 18:46:39 +00:00
* libxml i . e . if libxml has been configured with - - with - debug - mem too .
2001-05-19 13:24:56 +00:00
*/
2001-02-23 17:55:21 +00:00
# ifdef DEBUG_MEMORY_LOCATION
2001-02-25 16:11:03 +00:00
# endif
2001-02-23 17:55:21 +00:00
# ifdef __cplusplus
extern " C " {
# endif
/*
2002-03-12 18:46:39 +00:00
* The XML memory wrapper support 4 basic overloadable functions .
2001-02-23 17:55:21 +00:00
*/
2002-01-22 18:15:52 +00:00
/**
* xmlFreeFunc :
* @ mem : an already allocated block of memory
*
2002-03-12 18:46:39 +00:00
* Signature for a free ( ) implementation .
2002-01-22 18:15:52 +00:00
*/
typedef void ( * xmlFreeFunc ) ( void * mem ) ;
/**
* xmlMallocFunc :
* @ size : the size requested in bytes
*
2002-03-12 18:46:39 +00:00
* Signature for a malloc ( ) implementation .
2002-01-22 18:15:52 +00:00
*
2002-03-12 18:46:39 +00:00
* Returns a pointer to the newly allocated block or NULL in case of error .
2002-01-22 18:15:52 +00:00
*/
typedef void * ( * xmlMallocFunc ) ( size_t size ) ;
/**
* xmlReallocFunc :
* @ mem : an already allocated block of memory
* @ size : the new size requested in bytes
*
2002-03-12 18:46:39 +00:00
* Signature for a realloc ( ) implementation .
2002-01-22 18:15:52 +00:00
*
2002-03-12 18:46:39 +00:00
* Returns a pointer to the newly reallocated block or NULL in case of error .
2002-01-22 18:15:52 +00:00
*/
typedef void * ( * xmlReallocFunc ) ( void * mem , size_t size ) ;
/**
* xmlStrdupFunc :
* @ str : a zero terminated string
*
2002-03-12 18:46:39 +00:00
* Signature for an strdup ( ) implementation .
2002-01-22 18:15:52 +00:00
*
2002-03-12 18:46:39 +00:00
* Returns the copy of the string or NULL in case of error .
2002-01-22 18:15:52 +00:00
*/
typedef char * ( * xmlStrdupFunc ) ( const char * str ) ;
2001-02-23 17:55:21 +00:00
/*
2002-03-12 18:46:39 +00:00
* The 4 interfaces used for all memory handling within libxml .
2001-02-23 17:55:21 +00:00
LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree ;
LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc ;
2003-04-19 00:07:51 +00:00
LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMallocAtomic ;
2001-02-23 17:55:21 +00:00
LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc ;
LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup ;
2002-02-11 08:54:05 +00:00
*/
2001-02-23 17:55:21 +00:00
/*
2002-03-12 18:46:39 +00:00
* The way to overload the existing functions .
2003-04-19 00:07:51 +00:00
* The xmlGc function have an extra entry for atomic block
* allocations useful for garbage collected memory allocators
2001-02-23 17:55:21 +00:00
*/
2003-08-25 09:05:12 +00:00
XMLPUBFUN int XMLCALL
xmlMemSetup ( xmlFreeFunc freeFunc ,
2001-02-23 17:55:21 +00:00
xmlMallocFunc mallocFunc ,
xmlReallocFunc reallocFunc ,
xmlStrdupFunc strdupFunc ) ;
2003-08-27 08:59:58 +00:00
XMLPUBFUN int XMLCALL
xmlMemGet ( xmlFreeFunc * freeFunc ,
2001-02-23 17:55:21 +00:00
xmlMallocFunc * mallocFunc ,
xmlReallocFunc * reallocFunc ,
xmlStrdupFunc * strdupFunc ) ;
2003-08-27 08:59:58 +00:00
XMLPUBFUN int XMLCALL
xmlGcMemSetup ( xmlFreeFunc freeFunc ,
2003-04-19 00:07:51 +00:00
xmlMallocFunc mallocFunc ,
xmlMallocFunc mallocAtomicFunc ,
xmlReallocFunc reallocFunc ,
xmlStrdupFunc strdupFunc ) ;
2003-08-27 08:59:58 +00:00
XMLPUBFUN int XMLCALL
xmlGcMemGet ( xmlFreeFunc * freeFunc ,
2003-04-19 00:07:51 +00:00
xmlMallocFunc * mallocFunc ,
xmlMallocFunc * mallocAtomicFunc ,
xmlReallocFunc * reallocFunc ,
xmlStrdupFunc * strdupFunc ) ;
2001-02-23 17:55:21 +00:00
/*
2002-03-12 18:46:39 +00:00
* Initialization of the memory layer .
2001-02-23 17:55:21 +00:00
*/
2003-08-27 08:59:58 +00:00
XMLPUBFUN int XMLCALL
xmlInitMemory ( void ) ;
2001-02-23 17:55:21 +00:00
/*
2003-08-05 15:52:22 +00:00
* These are specific to the XML debug memory wrapper .
2001-02-23 17:55:21 +00:00
*/
2003-08-27 08:59:58 +00:00
XMLPUBFUN int XMLCALL
xmlMemUsed ( void ) ;
XMLPUBFUN void XMLCALL
xmlMemDisplay ( FILE * fp ) ;
XMLPUBFUN void XMLCALL
xmlMemShow ( FILE * fp , int nr ) ;
XMLPUBFUN void XMLCALL
xmlMemoryDump ( void ) ;
XMLPUBFUN void * XMLCALL
xmlMemMalloc ( size_t size ) ;
XMLPUBFUN void * XMLCALL
xmlMemRealloc ( void * ptr , size_t size ) ;
XMLPUBFUN void XMLCALL
xmlMemFree ( void * ptr ) ;
XMLPUBFUN char * XMLCALL
xmlMemoryStrdup ( const char * str ) ;
XMLPUBFUN void * XMLCALL
xmlMallocLoc ( size_t size , const char * file , int line ) ;
XMLPUBFUN void * XMLCALL
xmlReallocLoc ( void * ptr , size_t size , const char * file , int line ) ;
XMLPUBFUN void * XMLCALL
xmlMallocAtomicLoc ( size_t size , const char * file , int line ) ;
XMLPUBFUN char * XMLCALL
xmlMemStrdupLoc ( const char * str , const char * file , int line ) ;
2003-08-05 15:52:22 +00:00
2001-02-23 17:55:21 +00:00
# ifdef DEBUG_MEMORY_LOCATION
2001-07-18 19:30:27 +00:00
/**
* xmlMalloc :
* @ size : number of bytes to allocate
*
2002-03-12 18:46:39 +00:00
* Wrapper for the malloc ( ) function used in the XML library .
2001-07-18 19:30:27 +00:00
*
2002-03-12 18:46:39 +00:00
* Returns the pointer to the allocated area or NULL in case of error .
2001-07-18 19:30:27 +00:00
*/
# define xmlMalloc(size) xmlMallocLoc((size), __FILE__, __LINE__)
2003-04-19 00:07:51 +00:00
/**
* xmlMallocAtomic :
* @ size : number of bytes to allocate
*
* Wrapper for the malloc ( ) function used in the XML library for allocation
* of block not containing pointers to other areas .
*
* Returns the pointer to the allocated area or NULL in case of error .
*/
# define xmlMallocAtomic(size) xmlMallocAtomicLoc((size), __FILE__, __LINE__)
2001-07-18 19:30:27 +00:00
/**
* xmlRealloc :
* @ ptr : pointer to the existing allocated area
* @ size : number of bytes to allocate
*
2002-03-12 18:46:39 +00:00
* Wrapper for the realloc ( ) function used in the XML library .
2001-07-18 19:30:27 +00:00
*
2002-03-12 18:46:39 +00:00
* Returns the pointer to the allocated area or NULL in case of error .
2001-07-18 19:30:27 +00:00
*/
# define xmlRealloc(ptr, size) xmlReallocLoc((ptr), (size), __FILE__, __LINE__)
/**
* xmlMemStrdup :
* @ str : pointer to the existing string
*
2002-03-12 18:46:39 +00:00
* Wrapper for the strdup ( ) function , xmlStrdup ( ) is usually preferred .
2001-07-18 19:30:27 +00:00
*
2002-03-12 18:46:39 +00:00
* Returns the pointer to the allocated area or NULL in case of error .
2001-07-18 19:30:27 +00:00
*/
# define xmlMemStrdup(str) xmlMemStrdupLoc((str), __FILE__, __LINE__)
2001-02-23 17:55:21 +00:00
# endif /* DEBUG_MEMORY_LOCATION */
# ifdef __cplusplus
}
# endif /* __cplusplus */
2002-02-11 08:54:05 +00:00
# ifndef __XML_GLOBALS_H
# ifndef __XML_THREADS_H__
# include <libxml/threads.h>
# include <libxml/globals.h>
# endif
# endif
2003-09-25 12:18:34 +00:00
# endif /* __DEBUG_MEMORY_ALLOC__ */
2001-02-23 17:55:21 +00:00