Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes16kdownloads
xmlmemory.h229 linesDownload Raw Back to libxml
1/*2 * Summary: interface for the memory allocator3 * Description: provides interfaces for the memory allocator,4 *              including debugging capabilities.5 *6 * Copy: See Copyright for the status of this software.7 *8 * Author: Daniel Veillard9 */10 11 12#ifndef __DEBUG_MEMORY_ALLOC__13#define __DEBUG_MEMORY_ALLOC__14 15#include <stdio.h>16#include <libxml/xmlversion.h>17 18/**19 * DEBUG_MEMORY:20 *21 * DEBUG_MEMORY replaces the allocator with a collect and debug22 * shell to the libc allocator.23 * DEBUG_MEMORY should only be activated when debugging24 * libxml i.e. if libxml has been configured with --with-debug-mem too.25 */26/* #define DEBUG_MEMORY_FREED */27/* #define DEBUG_MEMORY_LOCATION */28 29#ifdef DEBUG30#ifndef DEBUG_MEMORY31#define DEBUG_MEMORY32#endif33#endif34 35/**36 * DEBUG_MEMORY_LOCATION:37 *38 * DEBUG_MEMORY_LOCATION should be activated only when debugging39 * libxml i.e. if libxml has been configured with --with-debug-mem too.40 */41#ifdef DEBUG_MEMORY_LOCATION42#endif43 44#ifdef __cplusplus45extern "C" {46#endif47 48/*49 * The XML memory wrapper support 4 basic overloadable functions.50 */51/**52 * xmlFreeFunc:53 * @mem: an already allocated block of memory54 *55 * Signature for a free() implementation.56 */57typedef void (*xmlFreeFunc)(void *mem);58/**59 * xmlMallocFunc:60 * @size:  the size requested in bytes61 *62 * Signature for a malloc() implementation.63 *64 * Returns a pointer to the newly allocated block or NULL in case of error.65 */66typedef void *(LIBXML_ATTR_ALLOC_SIZE(1) *xmlMallocFunc)(size_t size);67 68/**69 * xmlReallocFunc:70 * @mem: an already allocated block of memory71 * @size:  the new size requested in bytes72 *73 * Signature for a realloc() implementation.74 *75 * Returns a pointer to the newly reallocated block or NULL in case of error.76 */77typedef void *(*xmlReallocFunc)(void *mem, size_t size);78 79/**80 * xmlStrdupFunc:81 * @str: a zero terminated string82 *83 * Signature for an strdup() implementation.84 *85 * Returns the copy of the string or NULL in case of error.86 */87typedef char *(*xmlStrdupFunc)(const char *str);88 89/*90 * The 4 interfaces used for all memory handling within libxml.91LIBXML_DLL_IMPORT xmlFreeFunc xmlFree;92LIBXML_DLL_IMPORT xmlMallocFunc xmlMalloc;93LIBXML_DLL_IMPORT xmlMallocFunc xmlMallocAtomic;94LIBXML_DLL_IMPORT xmlReallocFunc xmlRealloc;95LIBXML_DLL_IMPORT xmlStrdupFunc xmlMemStrdup;96 */97 98/*99 * The way to overload the existing functions.100 * The xmlGc function have an extra entry for atomic block101 * allocations useful for garbage collected memory allocators102 */103XMLPUBFUN int104	xmlMemSetup	(xmlFreeFunc freeFunc,105			 xmlMallocFunc mallocFunc,106			 xmlReallocFunc reallocFunc,107			 xmlStrdupFunc strdupFunc);108XMLPUBFUN int109	xmlMemGet	(xmlFreeFunc *freeFunc,110			 xmlMallocFunc *mallocFunc,111			 xmlReallocFunc *reallocFunc,112			 xmlStrdupFunc *strdupFunc);113XMLPUBFUN int114	xmlGcMemSetup	(xmlFreeFunc freeFunc,115			 xmlMallocFunc mallocFunc,116			 xmlMallocFunc mallocAtomicFunc,117			 xmlReallocFunc reallocFunc,118			 xmlStrdupFunc strdupFunc);119XMLPUBFUN int120	xmlGcMemGet	(xmlFreeFunc *freeFunc,121			 xmlMallocFunc *mallocFunc,122			 xmlMallocFunc *mallocAtomicFunc,123			 xmlReallocFunc *reallocFunc,124			 xmlStrdupFunc *strdupFunc);125 126/*127 * Initialization of the memory layer.128 */129XML_DEPRECATED130XMLPUBFUN int131	xmlInitMemory	(void);132 133/*134 * Cleanup of the memory layer.135 */136XML_DEPRECATED137XMLPUBFUN void138                xmlCleanupMemory        (void);139/*140 * These are specific to the XML debug memory wrapper.141 */142XMLPUBFUN size_t143	xmlMemSize	(void *ptr);144XMLPUBFUN int145	xmlMemUsed	(void);146XMLPUBFUN int147	xmlMemBlocks	(void);148XMLPUBFUN void149	xmlMemDisplay	(FILE *fp);150XMLPUBFUN void151	xmlMemDisplayLast(FILE *fp, long nbBytes);152XMLPUBFUN void153	xmlMemShow	(FILE *fp, int nr);154XMLPUBFUN void155	xmlMemoryDump	(void);156XMLPUBFUN void *157	xmlMemMalloc	(size_t size) LIBXML_ATTR_ALLOC_SIZE(1);158XMLPUBFUN void *159	xmlMemRealloc	(void *ptr,size_t size);160XMLPUBFUN void161	xmlMemFree	(void *ptr);162XMLPUBFUN char *163	xmlMemoryStrdup	(const char *str);164XMLPUBFUN void *165	xmlMallocLoc	(size_t size, const char *file, int line) LIBXML_ATTR_ALLOC_SIZE(1);166XMLPUBFUN void *167	xmlReallocLoc	(void *ptr, size_t size, const char *file, int line);168XMLPUBFUN void *169	xmlMallocAtomicLoc (size_t size, const char *file, int line) LIBXML_ATTR_ALLOC_SIZE(1);170XMLPUBFUN char *171	xmlMemStrdupLoc	(const char *str, const char *file, int line);172 173 174#ifdef DEBUG_MEMORY_LOCATION175/**176 * xmlMalloc:177 * @size:  number of bytes to allocate178 *179 * Wrapper for the malloc() function used in the XML library.180 *181 * Returns the pointer to the allocated area or NULL in case of error.182 */183#define xmlMalloc(size) xmlMallocLoc((size), __FILE__, __LINE__)184/**185 * xmlMallocAtomic:186 * @size:  number of bytes to allocate187 *188 * Wrapper for the malloc() function used in the XML library for allocation189 * of block not containing pointers to other areas.190 *191 * Returns the pointer to the allocated area or NULL in case of error.192 */193#define xmlMallocAtomic(size) xmlMallocAtomicLoc((size), __FILE__, __LINE__)194/**195 * xmlRealloc:196 * @ptr:  pointer to the existing allocated area197 * @size:  number of bytes to allocate198 *199 * Wrapper for the realloc() function used in the XML library.200 *201 * Returns the pointer to the allocated area or NULL in case of error.202 */203#define xmlRealloc(ptr, size) xmlReallocLoc((ptr), (size), __FILE__, __LINE__)204/**205 * xmlMemStrdup:206 * @str:  pointer to the existing string207 *208 * Wrapper for the strdup() function, xmlStrdup() is usually preferred.209 *210 * Returns the pointer to the allocated area or NULL in case of error.211 */212#define xmlMemStrdup(str) xmlMemStrdupLoc((str), __FILE__, __LINE__)213 214#endif /* DEBUG_MEMORY_LOCATION */215 216#ifdef __cplusplus217}218#endif /* __cplusplus */219 220#ifndef __XML_GLOBALS_H221#ifndef __XML_THREADS_H__222#include <libxml/threads.h>223#include <libxml/globals.h>224#endif225#endif226 227#endif  /* __DEBUG_MEMORY_ALLOC__ */228 229 
codekingpro/portable-devtools · Team Ai