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                  extproc('xmlMemSetup')
140     d                                     like(xmlCint)
141     d  freeFunc                           value like(xmlFreeFunc)
142     d  mallocFunc                         value like(xmlMallocFunc)
143     d  reallocFunc                        value like(xmlReallocFunc)
144     d  strdupFunc                         value like(xmlStrdupFunc)
145
146     d xmlMemGet       pr                  extproc('xmlMemGet')
147     d                                     like(xmlCint)
148     d  freeFunc                           like(xmlFreeFunc)
149     d  mallocFunc                         like(xmlMallocFunc)
150     d  reallocFunc                        like(xmlReallocFunc)
151     d  strdupFunc                         like(xmlStrdupFunc)
152
153     d xmlGcMemSetup   pr                  extproc('xmlGcMemSetup')
154     d                                     like(xmlCint)
155     d  freeFunc                           value like(xmlFreeFunc)
156     d  mallocFunc                         value like(xmlMallocFunc)
157     d  mallocAtomicFunc...
158     d                                     value like(xmlMallocFunc)
159     d  reallocFunc                        value like(xmlReallocFunc)
160     d  strdupFunc                         value like(xmlStrdupFunc)
161
162     d xmlGcMemGet     pr                  extproc('xmlGcMemGet')
163     d                                     like(xmlCint)
164     d  freeFunc                           like(xmlFreeFunc)
165     d  mallocFunc                         like(xmlMallocFunc)
166     d  mallocAtomicFunc...
167     d                                     like(xmlMallocFunc)
168     d  reallocFunc                        like(xmlReallocFunc)
169     d  strdupFunc                         like(xmlStrdupFunc)
170
171      * Initialization of the memory layer.
172
173     d xmlInitMemory   pr                  extproc('xmlInitMemory')
174     d                                     like(xmlCint)
175
176      * Cleanup of the memory layer.
177
178     d xmlCleanupMemory...
179     d                 pr                  extproc('xmlCleanupMemory')
180
181      * These are specific to the XML debug memory wrapper.
182
183     d xmlMemUsed      pr                  extproc('xmlMemUsed')
184     d                                     like(xmlCint)
185
186     d xmlMemBlocks    pr                  extproc('xmlMemBlocks')
187     d                                     like(xmlCint)
188
189     d xmlMemDisplay   pr                  extproc('xmlMemDisplay')
190     d  fp                             *   value                                FILE *
191
192     d xmlMmDisplayLast...
193     d                 pr                  extproc('xmlMemDisplayLast')
194     d  fp                             *   value                                FILE *
195     d  nbBytes                            value like(xmlClong)
196
197     d xmlMemShow      pr                  extproc('xmlMemShow')
198     d  fp                             *   value                                FILE *
199     d  nr                                 value like(xmlCint)
200
201     d xmlMemoryDump   pr                  extproc('xmlMemoryDump')
202
203     d xmlMemMalloc    pr              *   extproc('xmlMemMalloc')              void *
204     d  size                               value like(xmlCsize_t)
205
206     d xmlMemRealloc   pr              *   extproc('xmlMemRealloc')             void *
207     d  ptr                            *   value                                void *
208     d  size                               value like(xmlCsize_t)
209
210     d xmlMemFree      pr                  extproc('xmlMemFree')
211     d  ptr                            *   value                                void *
212
213     d xmlMemoryStrdup...
214     d                 pr              *   extproc('xmlMemoryStrdup')           char *
215     d  str                            *   value options(*string)               const char *
216
217     d xmlMallocLoc    pr              *   extproc('xmlMallocLoc')              void *
218     d  size                               value like(xmlCsize_t)
219     d  file                           *   value options(*string)               const char *
220     d  line                               value like(xmlCint)
221
222     d xmlReallocLoc   pr              *   extproc('xmlReallocLoc')              void *
223     d  ptr                            *   value                                void *
224     d  size                               value like(xmlCsize_t)
225     d  file                           *   value options(*string)               const char *
226     d  line                               value like(xmlCint)
227
228     d xmlMallocAtomicLoc...
229     d                 pr              *   extproc('xmlMallocAtomicLoc')        void *
230     d  size                               value like(xmlCsize_t)
231     d  file                           *   value options(*string)               const char *
232     d  line                               value like(xmlCint)
233
234     d xmlMemStrdupLoc...
235     d                 pr              *   extproc('xmlMemStrdupLoc')           char *
236     d  str                            *   value options(*string)               const char *
237     d  file                           *   value options(*string)               const char *
238     d  line                               value like(xmlCint)
239
240      /if not defined(XML_GLOBALS_H)
241      /if not defined(XML_THREADS_H__)
242      /include "libxmlrpg/threads"
243      /include "libxmlrpg/globals"
244      /endif
245      /endif
246
247      /endif                                                                    DEBUG_MEMORY_ALLOC__
248