My Project
Loading...
Searching...
No Matches
omtTestAlloc.c
Go to the documentation of this file.
1/*******************************************************************
2 * File: omtTestAlloc.c
3 * Purpose: alloc function to be included in omMain.c
4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann)
5 * Created: 11/99
6 *******************************************************************/
7#include "omtTest.h"
8
9#ifdef TEST_CHECK
10#define OM_CHECK CHECK_LEVEL
11#define omtTestAlloc omtTestAllocDebug
12#define omtTestRealloc omtTestReallocDebug
13#define omtTestFree omtTestFreeDebug
14#define omtTestDup omtTestDupDebug
15#endif
16
17#ifdef TEST_KEEP
18#define OM_CHECK CHECK_LEVEL
19#define OM_KEEP 1
20#define omtTestAlloc omtTestAllocKeep
21#define omtTestRealloc omtTestReallocKeep
22#define omtTestFree omtTestFreeKeep
23#define omtTestDup omtTestDupKeep
24#endif
25
26#include "omalloc.h"
27
28#ifndef OM_ALIGNMENT_NEEDS_WORK
29#define omSmallSize2AlignedBin omSmallSize2Bin
30#endif
31
32#ifdef HAVE_OMALLOC
33void omtTestAlloc(omMemCell cell, unsigned long spec)
34{
35 size_t size = GET_SIZE(spec);
36 void* addr;
37 omBin bin = NULL;
38 omBin orig_bin = NULL;
39
40 if (IS_BIN(spec) && (size <= OM_MAX_BLOCK_SIZE || IS_SPEC_BIN(spec)))
41 {
42 if (IS_SPEC_BIN(spec))
43 {
44 if (IS_ALIGNED(spec))
46 else
47 bin = omGetSpecBin(size);
48 }
49 else
50 {
51 if (IS_ALIGNED(spec))
53 else
54 bin = omSmallSize2Bin(size);
55 }
56
57 if (IS_STICKY_BIN(spec))
58 {
59 orig_bin = bin;
60 bin = omtGetStickyBin(bin);
61 }
62
63 if (IS_INLINE(spec))
64 {
65 if (IS_ZERO(spec))
66 addr = omAlloc0Bin(bin);
67 else
68 addr = omAllocBin(bin);
69 }
70 else
71 {
72 if (IS_ZERO(spec))
73 omTypeAlloc0Bin(void*, addr, bin);
74 else
75 omTypeAllocBin(void*, addr, bin);
76 }
77 }
78 else
79 {
80 if (IS_INLINE(spec))
81 {
82 if (IS_ZERO(spec))
83 {
84 if (IS_ALIGNED(spec))
85 {
86 if (IS_SLOPPY(spec))
87 addr = omalloc0(size);
88 else
89 addr = omAlloc0Aligned(size);
90 }
91 else
92 addr = omAlloc0(size);
93 }
94 else
95 {
96 if (IS_ALIGNED(spec))
97 {
98 if (IS_SLOPPY(spec))
99 addr = omalloc(size);
100 else
101 addr = omAllocAligned(size);
102 }
103 else
104 addr = omAlloc(size);
105 }
106 }
107 else
108 {
109 if (IS_ZERO(spec))
110 {
111 if (IS_ALIGNED(spec))
112 omTypeAlloc0Aligned(void*, addr, size);
113 else
114 omTypeAlloc0(void*, addr, size);
115 }
116 else
117 {
118 if (IS_ALIGNED(spec))
119 omTypeAllocAligned(void*, addr, size);
120 else
121 omTypeAlloc(void*, addr, size);
122 }
123 }
124 }
125 cell->addr = addr;
126 cell->bin = bin;
127 cell->orig_bin = orig_bin;
128 cell->spec = spec;
129
131
133}
134
136{
137 void* addr = cell->addr;
138 unsigned long spec = cell->spec;
139 omBin bin = cell->bin;
140 omBin orig_bin = cell->orig_bin;
141 size_t size = GET_SIZE(spec);
142
144
145 if (IS_FREE_SIZE(spec))
146 {
147 if (IS_SLOPPY(spec))
148 omfreeSize(addr, size);
149 else
150 omFreeSize(addr, size);
151 }
152 else if (bin != NULL && IS_FREE_BIN(spec))
153 omFreeBin(addr, bin);
154 else if (IS_FREE_BINADDR(spec) && (bin != NULL) && (size <= OM_MAX_BLOCK_SIZE))
155 {
156 omFreeBinAddr(addr);
157 }
158 else
159 {
160 if (IS_SLOPPY(spec))
161 omfree(addr);
162 else
163 omFree(addr);
164 }
165
166 if (bin != NULL && IS_SPEC_BIN(spec))
167 {
168 if (orig_bin != NULL)
169 omUnGetSpecBin(&orig_bin);
170 else
171 omUnGetSpecBin(&bin);
172 }
173
174 cell->addr = NULL;
175 cell->spec = 0;
176 cell->bin = NULL;
177 cell->orig_bin = NULL;
178}
179
181{
182 void* old_addr = cell->addr;
183 unsigned long old_spec = cell->spec;
184 omBin old_bin = cell->bin;
185 omBin old_orig_bin = cell->orig_bin;
186 size_t old_size = GET_SIZE(old_spec);
187 void* new_addr;
190 size_t new_size = GET_SIZE(new_spec);
192 size_t min_size;
193
195
196 if (old_bin != NULL && IS_FREE_BIN(old_spec) &&
198 {
200 {
201 if (IS_ALIGNED(new_spec))
203 else
205 }
206 else
207 {
208 if (IS_ALIGNED(new_spec))
210 else
212 }
213
215 {
218 }
219
220 if (IS_INLINE(new_spec))
221 {
224 }
225 else
226 {
229 }
230 }
231 else
232 {
234 {
235 if (IS_INLINE(new_spec))
236 {
237 if (IS_ZERO(new_spec))
238 {
239 if (IS_ALIGNED(new_spec))
240 {
241 if (IS_SLOPPY(new_spec))
243 else
245 }
246 else
248 }
249 else
250 {
251 if (IS_ALIGNED(new_spec))
252 {
253 if (IS_SLOPPY(new_spec))
255 else
257 }
259 }
260 }
261 else
262 {
263 if (IS_ZERO(new_spec))
264 {
267 }
268 else
269 {
272 }
273 }
274 }
275 else
276 {
277 if (IS_INLINE(new_spec))
278 {
279 if (IS_ZERO(new_spec))
280 {
281 if (IS_ALIGNED(new_spec))
282 {
283 if (IS_SLOPPY(new_spec))
285 else
287 }
289 }
290 else
291 {
292 if (IS_ALIGNED(new_spec))
293 {
294 if (IS_SLOPPY(new_spec))
296 else
298 }
300 }
301 }
302 else
303 {
304 if (IS_ZERO(new_spec))
305 {
308 }
309 else
310 {
313 }
314 }
315 }
316 }
317
318 if (old_bin != NULL && IS_SPEC_BIN(old_spec))
319 {
320 if (old_orig_bin != NULL)
322 else
324 }
325
329
332 else
333 {
337 }
338
339 cell->addr = new_addr;
340 cell->spec = new_spec;
341 cell->bin = new_bin;
342 cell->orig_bin = new_orig_bin;
345}
346
347#define DO_STRDUP(l) (l & 1)
348void omtTestDup(omMemCell cell, unsigned long spec)
349{
351
352 if (DO_STRDUP(spec))
353 {
354 size_t size = omSizeOfAddr(cell->addr);
355 void* new_addr;
356 memset(cell->addr, 'a', size - 1);
357 ((char*) cell->addr)[size-1] = '\0';
358 new_addr = omStrDup(cell->addr);
362 }
363 else
364 {
365 void* new_addr = omMemDup(cell->addr);
372 }
373}
374#endif
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
#define omStrDup(s)
#define omTypeAlloc0Bin(type, addr, bin)
#define omrealloc(addr, size)
#define omfree(addr)
#define omTypeReallocAlignedSize
#define omTypeRealloc0(o_addr, type, addr, size)
#define omFreeSize(addr, size)
#define omTypeRealloc0Size(o_addr, o_size, type, addr, size)
#define omAlloc0Aligned
#define omRealloc0AlignedSize
#define omrealloc0Size(addr, o_size, size)
#define omRealloc0Aligned
#define omAlloc(size)
#define omreallocSize(addr, o_size, size)
#define omReallocSize(addr, o_size, size)
#define omDebugAddrAlignedSize
#define omTypeAllocBin(type, addr, bin)
#define omAllocBin(bin)
#define omReallocAligned
#define omTypeRealloc0AlignedSize
#define omrealloc0(addr, size)
#define omRealloc0Bin(o_addr, o_bin, bin)
#define omAlloc0Bin(bin)
#define omTypeRealloc0Bin(o_addr, o_bin, type, addr, bin)
#define omTypeAlloc0(type, addr, size)
#define omalloc0(size)
#define omalloc(size)
#define omRealloc(addr, size)
#define omTypeAlloc0Aligned
#define omReallocAlignedSize
#define omFree(addr)
#define omTypeRealloc0Aligned
#define omAlloc0(size)
#define omFreeBin(addr, bin)
#define omFreeBinAddr(addr)
#define omReallocBin(o_addr, o_bin, bin)
#define omRealloc0Size(addr, o_size, size)
#define omMemDup(s)
#define omTypeAlloc(type, addr, size)
#define omTypeReallocAligned
#define omTypeAllocAligned
#define omRealloc0(addr, size)
#define omTypeReallocSize(o_addr, o_size, type, addr, size)
#define omTypeReallocBin(o_addr, o_bin, type, addr, bin)
#define omMemDupAligned
#define omTypeRealloc(o_addr, type, addr, size)
#define omAllocAligned
#define omfreeSize(addr, size)
#define omSmallSize2Bin(size)
size_t omSizeOfAddr(const void *addr)
#define omGetSpecBin(size)
Definition omBin.h:11
#define omGetAlignedSpecBin(size)
Definition omBin.h:10
#define omUnGetSpecBin(bin_ptr)
Definition omBin.h:14
#define NULL
Definition omList.c:12
omBin_t * omBin
Definition omStructs.h:12
#define OM_MAX_BLOCK_SIZE
Definition omTables.c:31
void omtTestAlloc(omMemCell cell, unsigned long spec)
void omtTestRealloc(omMemCell cell, unsigned long new_spec)
#define DO_STRDUP(l)
void omtTestDup(omMemCell cell, unsigned long spec)
#define omSmallSize2AlignedBin
void omtTestFree(omMemCell cell)
void TestAddrContent(void *addr, unsigned long value, size_t size)
Definition omtTest.c:106
omBin omtGetStickyBin(omBin bin)
Definition omtTest.c:275
void omtTestDebug(omMemCell cell)
Definition omtTest.c:36
void InitCellAddrContent(omMemCell cell)
Definition omtTest.c:130
void TestAddrContentEqual(void *s1, void *s2, size_t size)
Definition omtTest.c:90
#define IS_SPEC_BIN(spec)
Definition omtTest.h:56
#define IS_FREE_BINADDR(spec)
Definition omtTest.h:89
#define IS_STICKY_BIN(spec)
Definition omtTest.h:49
#define IS_ALIGNED(spec)
Definition omtTest.h:53
#define IS_BIN(spec)
Definition omtTest.h:55
#define IS_SLOPPY(spec)
Definition omtTest.h:88
#define IS_ZERO(spec)
Definition omtTest.h:54
#define IS_INLINE(spec)
Definition omtTest.h:57
#define IS_FREE_SIZE(spec)
Definition omtTest.h:86
omMemCell_t * omMemCell
Definition omtTest.h:33
#define IS_FREE_BIN(spec)
Definition omtTest.h:87
#define GET_SIZE(spec)
Definition omtTest.h:51