1 * Summary: interface for the memory allocator 2 * 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: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A. 8 9 /if not defined(DEBUG_MEMORY_ALLOC__) 10 /define DEBUG_MEMORY_ALLOC__ 11 12 /include "libxmlrpg/xmlversion" 13 /include "libxmlrpg/xmlTypesC" 14 15 * DEBUG_MEMORY: 16 * 17 * DEBUG_MEMORY replaces the allocator with a collect and debug 18 * shell to the libc allocator. 19 * DEBUG_MEMORY should only be activated when debugging 20 * libxml i.e. if libxml has been configured with --with-debug-mem too. 21 22 * /define DEBUG_MEMORY_FREED 23 * /define DEBUG_MEMORY_LOCATION 24 25 /if defined(DEBUG) 26 /if not defined(DEBUG_MEMORY) 27 /define DEBUG_MEMORY 28 /endif 29 /endif 30 31 * DEBUG_MEMORY_LOCATION: 32 * 33 * DEBUG_MEMORY_LOCATION should be activated only when debugging 34 * libxml i.e. if libxml has been configured with --with-debug-mem too. 35 36 /if defined(DEBUG_MEMORY_LOCATION) 37 /endif 38 39 * The XML memory wrapper support 4 basic overloadable functions. 40 41 * xmlFreeFunc: 42 * @mem: an already allocated block of memory 43 * 44 * Signature for a free() implementation. 45 46 d xmlFreeFunc s * based(######typedef######) 47 d procptr 48 49 * xmlMallocFunc: 50 * @size: the size requested in bytes 51 * 52 * Signature for a malloc() implementation. 53 * 54 * Returns a pointer to the newly allocated block or NULL in case of error. 55 56 d xmlMallocFunc s * based(######typedef######) 57 d procptr 58 59 * xmlReallocFunc: 60 * @mem: an already allocated block of memory 61 * @size: the new size requested in bytes 62 * 63 * Signature for a realloc() implementation. 64 * 65 * Returns a pointer to the newly reallocated block or NULL in case of error. 66 67 d xmlReallocFunc s * based(######typedef######) 68 d procptr 69 70 * xmlStrdupFunc: 71 * @str: a zero terminated string 72 * 73 * Signature for an strdup() implementation. 74 * 75 * Returns the copy of the string or NULL in case of error. 76 77 d xmlStrdupFunc s * based(######typedef######) 78 d procptr 79 80 * The 5 interfaces used for all memory handling within libxml. 81 * Since indirect calls are only supported via a based prototype, 82 * storage is accessed via functions. 83 84 d get_xmlFree pr extproc('__get_xmlFree') 85 d like(xmlFreeFunc) 86 87 d set_xmlFree pr extproc('__set_xmlFree') 88 d func value like(xmlFreeFunc) 89 90 d xmlFree pr extproc('__call_xmlFree') 91 d mem * value void * 92 93 d get_xmlMalloc pr extproc('__get_xmlMalloc') 94 d like(xmlMallocFunc) 95 96 d set_xmlMalloc pr extproc('__set_xmlMalloc') 97 d func value like(xmlMallocFunc) 98 99 d xmlMalloc pr * extproc('__call_xmlMalloc') void * 100 d size value like(xmlCsize_t) 101 102 d get_xmlMallocAtomic... 103 d pr extproc('__get_xmlMallocAtomic') 104 d like(xmlMallocFunc) 105 106 d set_xmlMallocAtomic... 107 d pr extproc('__set_xmlMallocAtomic') 108 d func value like(xmlMallocFunc) 109 110 d xmlMallocAtomic... 111 d pr * extproc('__call_xmlMallocAtomic') void * 112 d size value like(xmlCsize_t) 113 114 d get_xmlRealloc pr extproc('__get_xmlRealloc') 115 d like(xmlReallocFunc) 116 117 d set_xmlRealloc pr extproc('__set_xmlRealloc') 118 d func value like(xmlReallocFunc) 119 120 d xmlRealloc pr * extproc('__call_xmlRealloc') void * 121 d mem * value void * 122 d size value like(xmlCsize_t) 123 124 d get_xmlMemStrdup... 125 d pr extproc('__get_xmlMemStrdup') 126 d like(xmlStrdupFunc) 127 128 d set_xmlMemStrdup... 129 d pr extproc('__set_xmlMemstrdup') 130 d func value like(xmlStrdupFunc) 131 132 d xmlMemStrdup pr * extproc('__call_xmlMemStrdup') void * 133 d str * value options(*string) const char * 134 135 * The way to overload the existing functions. 136 * The xmlGc function have an extra entry for atomic block 137 * allocations useful for garbage collected memory allocators 138 139 d xmlMemSetup pr 10i 0 extproc('xmlMemSetup') 140 d freeFunc value like(xmlFreeFunc) 141 d mallocFunc value like(xmlMallocFunc) 142 d reallocFunc value like(xmlReallocFunc) 143 d strdupFunc value like(xmlStrdupFunc) 144 145 d xmlMemGet pr 10i 0 extproc('xmlMemGet') 146 d freeFunc like(xmlFreeFunc) 147 d mallocFunc like(xmlMallocFunc) 148 d reallocFunc like(xmlReallocFunc) 149 d strdupFunc like(xmlStrdupFunc) 150 151 d xmlGcMemSetup pr 10i 0 extproc('xmlGcMemSetup') 152 d freeFunc value like(xmlFreeFunc) 153 d mallocFunc value like(xmlMallocFunc) 154 d mallocAtomicFunc... 155 d value like(xmlMallocFunc) 156 d reallocFunc value like(xmlReallocFunc) 157 d strdupFunc value like(xmlStrdupFunc) 158 159 d xmlGcMemGet pr 10i 0 extproc('xmlGcMemGet') 160 d freeFunc like(xmlFreeFunc) 161 d mallocFunc like(xmlMallocFunc) 162 d mallocAtomicFunc... 163 d like(xmlMallocFunc) 164 d reallocFunc like(xmlReallocFunc) 165 d strdupFunc like(xmlStrdupFunc) 166 167 * Initialization of the memory layer. 168 169 d xmlInitMemory pr 10i 0 extproc('xmlInitMemory') 170 171 * Cleanup of the memory layer. 172 173 d xmlCleanupMemory... 174 d pr extproc('xmlCleanupMemory') 175 176 * These are specific to the XML debug memory wrapper. 177 178 d xmlMemUsed pr 10i 0 extproc('xmlMemUsed') 179 180 d xmlMemBlocks pr 10i 0 extproc('xmlMemBlocks') 181 182 d xmlMemDisplay pr extproc('xmlMemDisplay') 183 d fp * value FILE * 184 185 d xmlMmDisplayLast... 186 d pr extproc('xmlMemDisplayLast') 187 d fp * value FILE * 188 d nbBytes value like(xmlClong) 189 190 d xmlMemShow pr extproc('xmlMemShow') 191 d fp * value FILE * 192 d nr 10i 0 value 193 194 d xmlMemoryDump pr extproc('xmlMemoryDump') 195 196 d xmlMemMalloc pr * extproc('xmlMemMalloc') void * 197 d size value like(xmlCsize_t) 198 199 d xmlMemRealloc pr * extproc('xmlMemRealloc') void * 200 d ptr * value void * 201 d size value like(xmlCsize_t) 202 203 d xmlMemFree pr extproc('xmlMemFree') 204 d ptr * value void * 205 206 d xmlMemoryStrdup... 207 d pr * extproc('xmlMemoryStrdup') char * 208 d str * value options(*string) const char * 209 210 d xmlMallocLoc pr * extproc('xmlMallocLoc') void * 211 d size value like(xmlCsize_t) 212 d file * value options(*string) const char * 213 d line 10i 0 value 214 215 d xmlReallocLoc pr * extproc('xmlReallocLoc') void * 216 d ptr * value void * 217 d size value like(xmlCsize_t) 218 d file * value options(*string) const char * 219 d line 10i 0 value 220 221 d xmlMallocAtomicLoc... 222 d pr * extproc('xmlMallocAtomicLoc') void * 223 d size value like(xmlCsize_t) 224 d file * value options(*string) const char * 225 d line 10i 0 value 226 227 d xmlMemStrdupLoc... 228 d pr * extproc('xmlMemStrdupLoc') char * 229 d str * value options(*string) const char * 230 d file * value options(*string) const char * 231 d line 10i 0 value 232 233 /if not defined(XML_GLOBALS_H) 234 /if not defined(XML_THREADS_H__) 235 /include "libxmlrpg/threads" 236 /include "libxmlrpg/globals" 237 /endif 238 /endif 239 240 /endif DEBUG_MEMORY_ALLOC__ 241