Blame include/libxml/xmlmemory.h

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