Path: blob/master/venv/Lib/site-packages/lxml/includes/libxml/xmlmemory.h
811 views
/*1* Summary: interface for the memory allocator2* Description: provides interfaces for the memory allocator,3* including debugging capabilities.4*5* Copy: See Copyright for the status of this software.6*7* Author: Daniel Veillard8*/91011#ifndef __DEBUG_MEMORY_ALLOC__12#define __DEBUG_MEMORY_ALLOC__1314#include <stdio.h>15#include <libxml/xmlversion.h>1617/**18* DEBUG_MEMORY:19*20* DEBUG_MEMORY replaces the allocator with a collect and debug21* shell to the libc allocator.22* DEBUG_MEMORY should only be activated when debugging23* libxml i.e. if libxml has been configured with --with-debug-mem too.24*/25/* #define DEBUG_MEMORY_FREED */26/* #define DEBUG_MEMORY_LOCATION */2728#ifdef DEBUG29#ifndef DEBUG_MEMORY30#define DEBUG_MEMORY31#endif32#endif3334/**35* DEBUG_MEMORY_LOCATION:36*37* DEBUG_MEMORY_LOCATION should be activated only when debugging38* libxml i.e. if libxml has been configured with --with-debug-mem too.39*/40#ifdef DEBUG_MEMORY_LOCATION41#endif4243#ifdef __cplusplus44extern "C" {45#endif4647/*48* The XML memory wrapper support 4 basic overloadable functions.49*/50/**51* xmlFreeFunc:52* @mem: an already allocated block of memory53*54* Signature for a free() implementation.55*/56typedef void (XMLCALL *xmlFreeFunc)(void *mem);57/**58* xmlMallocFunc:59* @size: the size requested in bytes60*61* Signature for a malloc() implementation.62*63* Returns a pointer to the newly allocated block or NULL in case of error.64*/65typedef void *(LIBXML_ATTR_ALLOC_SIZE(1) XMLCALL *xmlMallocFunc)(size_t size);6667/**68* xmlReallocFunc:69* @mem: an already allocated block of memory70* @size: the new size requested in bytes71*72* Signature for a realloc() implementation.73*74* Returns a pointer to the newly reallocated block or NULL in case of error.75*/76typedef void *(XMLCALL *xmlReallocFunc)(void *mem, size_t size);7778/**79* xmlStrdupFunc:80* @str: a zero terminated string81*82* Signature for an strdup() implementation.83*84* Returns the copy of the string or NULL in case of error.85*/86typedef char *(XMLCALL *xmlStrdupFunc)(const char *str);8788/*89* The 4 interfaces used for all memory handling within libxml.90LIBXML_DLL_IMPORT xmlFreeFunc xmlFree;91LIBXML_DLL_IMPORT xmlMallocFunc xmlMalloc;92LIBXML_DLL_IMPORT xmlMallocFunc xmlMallocAtomic;93LIBXML_DLL_IMPORT xmlReallocFunc xmlRealloc;94LIBXML_DLL_IMPORT xmlStrdupFunc xmlMemStrdup;95*/9697/*98* The way to overload the existing functions.99* The xmlGc function have an extra entry for atomic block100* allocations useful for garbage collected memory allocators101*/102XMLPUBFUN int XMLCALL103xmlMemSetup (xmlFreeFunc freeFunc,104xmlMallocFunc mallocFunc,105xmlReallocFunc reallocFunc,106xmlStrdupFunc strdupFunc);107XMLPUBFUN int XMLCALL108xmlMemGet (xmlFreeFunc *freeFunc,109xmlMallocFunc *mallocFunc,110xmlReallocFunc *reallocFunc,111xmlStrdupFunc *strdupFunc);112XMLPUBFUN int XMLCALL113xmlGcMemSetup (xmlFreeFunc freeFunc,114xmlMallocFunc mallocFunc,115xmlMallocFunc mallocAtomicFunc,116xmlReallocFunc reallocFunc,117xmlStrdupFunc strdupFunc);118XMLPUBFUN int XMLCALL119xmlGcMemGet (xmlFreeFunc *freeFunc,120xmlMallocFunc *mallocFunc,121xmlMallocFunc *mallocAtomicFunc,122xmlReallocFunc *reallocFunc,123xmlStrdupFunc *strdupFunc);124125/*126* Initialization of the memory layer.127*/128XMLPUBFUN int XMLCALL129xmlInitMemory (void);130131/*132* Cleanup of the memory layer.133*/134XMLPUBFUN void XMLCALL135xmlCleanupMemory (void);136/*137* These are specific to the XML debug memory wrapper.138*/139XMLPUBFUN int XMLCALL140xmlMemUsed (void);141XMLPUBFUN int XMLCALL142xmlMemBlocks (void);143XMLPUBFUN void XMLCALL144xmlMemDisplay (FILE *fp);145XMLPUBFUN void XMLCALL146xmlMemDisplayLast(FILE *fp, long nbBytes);147XMLPUBFUN void XMLCALL148xmlMemShow (FILE *fp, int nr);149XMLPUBFUN void XMLCALL150xmlMemoryDump (void);151XMLPUBFUN void * XMLCALL152xmlMemMalloc (size_t size) LIBXML_ATTR_ALLOC_SIZE(1);153XMLPUBFUN void * XMLCALL154xmlMemRealloc (void *ptr,size_t size);155XMLPUBFUN void XMLCALL156xmlMemFree (void *ptr);157XMLPUBFUN char * XMLCALL158xmlMemoryStrdup (const char *str);159XMLPUBFUN void * XMLCALL160xmlMallocLoc (size_t size, const char *file, int line) LIBXML_ATTR_ALLOC_SIZE(1);161XMLPUBFUN void * XMLCALL162xmlReallocLoc (void *ptr, size_t size, const char *file, int line);163XMLPUBFUN void * XMLCALL164xmlMallocAtomicLoc (size_t size, const char *file, int line) LIBXML_ATTR_ALLOC_SIZE(1);165XMLPUBFUN char * XMLCALL166xmlMemStrdupLoc (const char *str, const char *file, int line);167168169#ifdef DEBUG_MEMORY_LOCATION170/**171* xmlMalloc:172* @size: number of bytes to allocate173*174* Wrapper for the malloc() function used in the XML library.175*176* Returns the pointer to the allocated area or NULL in case of error.177*/178#define xmlMalloc(size) xmlMallocLoc((size), __FILE__, __LINE__)179/**180* xmlMallocAtomic:181* @size: number of bytes to allocate182*183* Wrapper for the malloc() function used in the XML library for allocation184* of block not containing pointers to other areas.185*186* Returns the pointer to the allocated area or NULL in case of error.187*/188#define xmlMallocAtomic(size) xmlMallocAtomicLoc((size), __FILE__, __LINE__)189/**190* xmlRealloc:191* @ptr: pointer to the existing allocated area192* @size: number of bytes to allocate193*194* Wrapper for the realloc() function used in the XML library.195*196* Returns the pointer to the allocated area or NULL in case of error.197*/198#define xmlRealloc(ptr, size) xmlReallocLoc((ptr), (size), __FILE__, __LINE__)199/**200* xmlMemStrdup:201* @str: pointer to the existing string202*203* Wrapper for the strdup() function, xmlStrdup() is usually preferred.204*205* Returns the pointer to the allocated area or NULL in case of error.206*/207#define xmlMemStrdup(str) xmlMemStrdupLoc((str), __FILE__, __LINE__)208209#endif /* DEBUG_MEMORY_LOCATION */210211#ifdef __cplusplus212}213#endif /* __cplusplus */214215#ifndef __XML_GLOBALS_H216#ifndef __XML_THREADS_H__217#include <libxml/threads.h>218#include <libxml/globals.h>219#endif220#endif221222#endif /* __DEBUG_MEMORY_ALLOC__ */223224225226