imgtools/imgcheck/libxml/xmlmemory.h
changeset 0 044383f39525
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2  * Summary: interface for the memory allocator
       
     3  * 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 Veillard
       
     9  */
       
    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 debug
       
    22  * shell to the libc allocator.
       
    23  * DEBUG_MEMORY should only be activated when debugging 
       
    24  * libxml i.e. if libxml has been configured with --with-debug-mem too.
       
    25  */
       
    26 
       
    27 #ifdef DEBUG
       
    28 #ifndef DEBUG_MEMORY
       
    29 #define DEBUG_MEMORY
       
    30 #endif
       
    31 #endif
       
    32 
       
    33 /**
       
    34  * DEBUG_MEMORY_LOCATION:
       
    35  *
       
    36  * DEBUG_MEMORY_LOCATION should be activated only when debugging 
       
    37  * libxml i.e. if libxml has been configured with --with-debug-mem too.
       
    38  */
       
    39 #ifdef DEBUG_MEMORY_LOCATION
       
    40 #endif
       
    41 
       
    42 #ifdef __cplusplus
       
    43 extern "C" {
       
    44 #endif
       
    45 
       
    46 /*
       
    47  * The XML memory wrapper support 4 basic overloadable functions.
       
    48  */
       
    49 /**
       
    50  * xmlFreeFunc:
       
    51  * @mem: an already allocated block of memory
       
    52  *
       
    53  * Signature for a free() implementation.
       
    54  */
       
    55 typedef void (XMLCALL *xmlFreeFunc)(void *mem);
       
    56 /**
       
    57  * xmlMallocFunc:
       
    58  * @size:  the size requested in bytes
       
    59  *
       
    60  * Signature for a malloc() implementation.
       
    61  *
       
    62  * Returns a pointer to the newly allocated block or NULL in case of error.
       
    63  */
       
    64 typedef void *(XMLCALL *xmlMallocFunc)(size_t size);
       
    65 
       
    66 /**
       
    67  * xmlReallocFunc:
       
    68  * @mem: an already allocated block of memory
       
    69  * @size:  the new size requested in bytes
       
    70  *
       
    71  * Signature for a realloc() implementation.
       
    72  *
       
    73  * Returns a pointer to the newly reallocated block or NULL in case of error.
       
    74  */
       
    75 typedef void *(XMLCALL *xmlReallocFunc)(void *mem, size_t size);
       
    76 
       
    77 /**
       
    78  * xmlStrdupFunc:
       
    79  * @str: a zero terminated string
       
    80  *
       
    81  * Signature for an strdup() implementation.
       
    82  *
       
    83  * Returns the copy of the string or NULL in case of error.
       
    84  */
       
    85 typedef char *(XMLCALL *xmlStrdupFunc)(const char *str);
       
    86 
       
    87 /*
       
    88  * The 4 interfaces used for all memory handling within libxml.
       
    89 LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree;
       
    90 LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc;
       
    91 LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMallocAtomic;
       
    92 LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc;
       
    93 LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup;
       
    94  */
       
    95 
       
    96 /*
       
    97  * The way to overload the existing functions.
       
    98  * The xmlGc function have an extra entry for atomic block
       
    99  * allocations useful for garbage collected memory allocators
       
   100  */
       
   101 XMLPUBFUN int XMLCALL
       
   102 	xmlMemSetup	(xmlFreeFunc freeFunc,
       
   103 			 xmlMallocFunc mallocFunc,
       
   104 			 xmlReallocFunc reallocFunc,
       
   105 			 xmlStrdupFunc strdupFunc);
       
   106 XMLPUBFUN int XMLCALL     
       
   107 	xmlMemGet	(xmlFreeFunc *freeFunc,
       
   108 			 xmlMallocFunc *mallocFunc,
       
   109 			 xmlReallocFunc *reallocFunc,
       
   110 			 xmlStrdupFunc *strdupFunc);
       
   111 XMLPUBFUN int XMLCALL     
       
   112 	xmlGcMemSetup	(xmlFreeFunc freeFunc,
       
   113 			 xmlMallocFunc mallocFunc,
       
   114 			 xmlMallocFunc mallocAtomicFunc,
       
   115 			 xmlReallocFunc reallocFunc,
       
   116 			 xmlStrdupFunc strdupFunc);
       
   117 XMLPUBFUN int XMLCALL     
       
   118 	xmlGcMemGet	(xmlFreeFunc *freeFunc,
       
   119 			 xmlMallocFunc *mallocFunc,
       
   120 			 xmlMallocFunc *mallocAtomicFunc,
       
   121 			 xmlReallocFunc *reallocFunc,
       
   122 			 xmlStrdupFunc *strdupFunc);
       
   123 
       
   124 /*
       
   125  * Initialization of the memory layer.
       
   126  */
       
   127 XMLPUBFUN int XMLCALL	
       
   128 	xmlInitMemory	(void);
       
   129 
       
   130 /* 
       
   131  * Cleanup of the memory layer.
       
   132  */
       
   133 XMLPUBFUN void XMLCALL                
       
   134                 xmlCleanupMemory        (void);
       
   135 /*
       
   136  * These are specific to the XML debug memory wrapper.
       
   137  */
       
   138 XMLPUBFUN int XMLCALL	
       
   139 	xmlMemUsed	(void);
       
   140 XMLPUBFUN int XMLCALL	
       
   141 	xmlMemBlocks	(void);
       
   142 XMLPUBFUN void XMLCALL	
       
   143 	xmlMemDisplay	(FILE *fp);
       
   144 XMLPUBFUN void XMLCALL	
       
   145 	xmlMemShow	(FILE *fp, int nr);
       
   146 XMLPUBFUN void XMLCALL	
       
   147 	xmlMemoryDump	(void);
       
   148 XMLPUBFUN void * XMLCALL	
       
   149 	xmlMemMalloc	(size_t size);
       
   150 XMLPUBFUN void * XMLCALL	
       
   151 	xmlMemRealloc	(void *ptr,size_t size);
       
   152 XMLPUBFUN void XMLCALL	
       
   153 	xmlMemFree	(void *ptr);
       
   154 XMLPUBFUN char * XMLCALL	
       
   155 	xmlMemoryStrdup	(const char *str);
       
   156 XMLPUBFUN void * XMLCALL  
       
   157 	xmlMallocLoc	(size_t size, const char *file, int line);
       
   158 XMLPUBFUN void * XMLCALL	
       
   159 	xmlReallocLoc	(void *ptr, size_t size, const char *file, int line);
       
   160 XMLPUBFUN void * XMLCALL	
       
   161 	xmlMallocAtomicLoc (size_t size, const char *file, int line);
       
   162 XMLPUBFUN char * XMLCALL	
       
   163 	xmlMemStrdupLoc	(const char *str, const char *file, int line);
       
   164 
       
   165 
       
   166 #ifdef DEBUG_MEMORY_LOCATION
       
   167 /**
       
   168  * xmlMalloc:
       
   169  * @size:  number of bytes to allocate
       
   170  *
       
   171  * Wrapper for the malloc() function used in the XML library.
       
   172  *
       
   173  * Returns the pointer to the allocated area or NULL in case of error.
       
   174  */
       
   175 #define xmlMalloc(size) xmlMallocLoc((size), __FILE__, __LINE__)
       
   176 /**
       
   177  * xmlMallocAtomic:
       
   178  * @size:  number of bytes to allocate
       
   179  *
       
   180  * Wrapper for the malloc() function used in the XML library for allocation
       
   181  * of block not containing pointers to other areas.
       
   182  *
       
   183  * Returns the pointer to the allocated area or NULL in case of error.
       
   184  */
       
   185 #define xmlMallocAtomic(size) xmlMallocAtomicLoc((size), __FILE__, __LINE__)
       
   186 /**
       
   187  * xmlRealloc:
       
   188  * @ptr:  pointer to the existing allocated area
       
   189  * @size:  number of bytes to allocate
       
   190  *
       
   191  * Wrapper for the realloc() function used in the XML library.
       
   192  *
       
   193  * Returns the pointer to the allocated area or NULL in case of error.
       
   194  */
       
   195 #define xmlRealloc(ptr, size) xmlReallocLoc((ptr), (size), __FILE__, __LINE__)
       
   196 /**
       
   197  * xmlMemStrdup:
       
   198  * @str:  pointer to the existing string
       
   199  *
       
   200  * Wrapper for the strdup() function, xmlStrdup() is usually preferred.
       
   201  *
       
   202  * Returns the pointer to the allocated area or NULL in case of error.
       
   203  */
       
   204 #define xmlMemStrdup(str) xmlMemStrdupLoc((str), __FILE__, __LINE__)
       
   205 
       
   206 #endif /* DEBUG_MEMORY_LOCATION */
       
   207 
       
   208 #ifdef __cplusplus
       
   209 }
       
   210 #endif /* __cplusplus */
       
   211 
       
   212 #ifndef __XML_GLOBALS_H
       
   213 #ifndef __XML_THREADS_H__
       
   214 #include <libxml/threads.h>
       
   215 #include <libxml/globals.h>
       
   216 #endif
       
   217 #endif
       
   218 
       
   219 #endif  /* __DEBUG_MEMORY_ALLOC__ */
       
   220