Macros | Functions
omtTestAlloc.c File Reference
#include "omtTest.h"
#include "omalloc.h"

Go to the source code of this file.

Macros

#define omSmallSize2AlignedBin   omSmallSize2Bin
 
#define DO_STRDUP(l)   (l & 1)
 

Functions

void omtTestAlloc (omMemCell cell, unsigned long spec)
 
void omtTestFree (omMemCell cell)
 
void omtTestRealloc (omMemCell cell, unsigned long new_spec)
 
void omtTestDup (omMemCell cell, unsigned long spec)
 

Macro Definition Documentation

◆ DO_STRDUP

#define DO_STRDUP (   l)    (l & 1)

Definition at line 346 of file omtTestAlloc.c.

◆ omSmallSize2AlignedBin

#define omSmallSize2AlignedBin   omSmallSize2Bin

Definition at line 29 of file omtTestAlloc.c.

Function Documentation

◆ omtTestAlloc()

void omtTestAlloc ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 32 of file omtTestAlloc.c.

33 {
34  size_t size = GET_SIZE(spec);
35  void* addr;
36  omBin bin = NULL;
37  omBin orig_bin = NULL;
38 
39  if (IS_BIN(spec) && (size <= OM_MAX_BLOCK_SIZE || IS_SPEC_BIN(spec)))
40  {
41  if (IS_SPEC_BIN(spec))
42  {
43  if (IS_ALIGNED(spec))
44  bin = omGetAlignedSpecBin(size);
45  else
46  bin = omGetSpecBin(size);
47  }
48  else
49  {
50  if (IS_ALIGNED(spec))
51  bin = omSmallSize2AlignedBin(size);
52  else
53  bin = omSmallSize2Bin(size);
54  }
55 
56  if (IS_STICKY_BIN(spec))
57  {
58  orig_bin = bin;
59  bin = omtGetStickyBin(bin);
60  }
61 
62  if (IS_INLINE(spec))
63  {
64  if (IS_ZERO(spec))
65  addr = omAlloc0Bin(bin);
66  else
67  addr = omAllocBin(bin);
68  }
69  else
70  {
71  if (IS_ZERO(spec))
72  omTypeAlloc0Bin(void*, addr, bin);
73  else
74  omTypeAllocBin(void*, addr, bin);
75  }
76  }
77  else
78  {
79  if (IS_INLINE(spec))
80  {
81  if (IS_ZERO(spec))
82  {
83  if (IS_ALIGNED(spec))
84  {
85  if (IS_SLOPPY(spec))
86  addr = omalloc0(size);
87  else
88  addr = omAlloc0Aligned(size);
89  }
90  else
91  addr = omAlloc0(size);
92  }
93  else
94  {
95  if (IS_ALIGNED(spec))
96  {
97  if (IS_SLOPPY(spec))
98  addr = omalloc(size);
99  else
100  addr = omAllocAligned(size);
101  }
102  else
103  addr = omAlloc(size);
104  }
105  }
106  else
107  {
108  if (IS_ZERO(spec))
109  {
110  if (IS_ALIGNED(spec))
111  omTypeAlloc0Aligned(void*, addr, size);
112  else
113  omTypeAlloc0(void*, addr, size);
114  }
115  else
116  {
117  if (IS_ALIGNED(spec))
118  omTypeAllocAligned(void*, addr, size);
119  else
120  omTypeAlloc(void*, addr, size);
121  }
122  }
123  }
124  cell->addr = addr;
125  cell->bin = bin;
126  cell->orig_bin = orig_bin;
127  cell->spec = spec;
128 
129  InitCellAddrContent(cell);
130 
131  omtTestDebug(cell);
132 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
omBin_t * omBin
Definition: omStructs.h:12
#define IS_ZERO(spec)
Definition: omtTest.h:55
#define omSmallSize2AlignedBin
Definition: omtTestAlloc.c:29
#define omAllocAligned
Definition: omAllocDecl.h:273
void InitCellAddrContent(omMemCell cell)
Definition: omtTest.c:134
#define IS_SPEC_BIN(spec)
Definition: omtTest.h:57
#define omTypeAllocBin(type, addr, bin)
Definition: omAllocDecl.h:203
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define GET_SIZE(spec)
Definition: omtTest.h:52
#define omTypeAlloc0Aligned
Definition: omAllocDecl.h:272
#define omTypeAlloc0(type, addr, size)
Definition: omAllocDecl.h:209
#define omGetAlignedSpecBin(size)
Definition: omBin.h:10
#define IS_SLOPPY(spec)
Definition: omtTest.h:89
#define IS_ALIGNED(spec)
Definition: omtTest.h:54
void omtTestDebug(omMemCell cell)
Definition: omtTest.c:34
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
omBin omtGetStickyBin(omBin bin)
Definition: omtTest.c:279
#define OM_MAX_BLOCK_SIZE
Definition: omTables.c:31
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define omGetSpecBin(size)
Definition: omBin.h:11
#define IS_STICKY_BIN(spec)
Definition: omtTest.h:50
#define omTypeAlloc0Bin(type, addr, bin)
Definition: omAllocDecl.h:204
#define omalloc(size)
Definition: omAllocDecl.h:228
#define NULL
Definition: omList.c:12
#define omalloc0(size)
Definition: omAllocDecl.h:229
#define omSmallSize2Bin(size)
#define omTypeAlloc(type, addr, size)
Definition: omAllocDecl.h:208
#define IS_INLINE(spec)
Definition: omtTest.h:58
#define IS_BIN(spec)
Definition: omtTest.h:56
#define omTypeAllocAligned
Definition: omAllocDecl.h:271
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define omAlloc0Aligned
Definition: omAllocDecl.h:274

◆ omtTestDup()

void omtTestDup ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 347 of file omtTestAlloc.c.

348 {
349  omtTestDebug(cell);
350 
351  if (DO_STRDUP(spec))
352  {
353  size_t size = omSizeOfAddr(cell->addr);
354  void* new_addr;
355  memset(cell->addr, 'a', size - 1);
356  ((char*) cell->addr)[size-1] = '\0';
357  new_addr = omStrDup(cell->addr);
358  TestAddrContentEqual(new_addr, cell->addr, size);
359  omFree(new_addr);
360  InitCellAddrContent(cell);
361  }
362  else
363  {
364  void* new_addr = omMemDup(cell->addr);
365  TestAddrContentEqual(new_addr, cell->addr, omSizeOfAddr(cell->addr));
366  omFree(new_addr);
367  new_addr = omMemDupAligned(cell->addr);
368  TestAddrContentEqual(new_addr, cell->addr, omSizeOfAddr(cell->addr));
369  omDebugAddrAlignedSize(new_addr, omSizeOfAddr(cell->addr));
370  omFree(new_addr);
371  }
372 }
#define omMemDup(s)
Definition: omAllocDecl.h:264
void TestAddrContentEqual(void *s1, void *s2, size_t size)
Definition: omtTest.c:94
size_t omSizeOfAddr(const void *addr)
void InitCellAddrContent(omMemCell cell)
Definition: omtTest.c:134
#define omDebugAddrAlignedSize
Definition: omAllocDecl.h:292
#define omFree(addr)
Definition: omAllocDecl.h:261
#define DO_STRDUP(l)
Definition: omtTestAlloc.c:346
void omtTestDebug(omMemCell cell)
Definition: omtTest.c:34
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#define omMemDupAligned
Definition: omAllocDecl.h:286
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ omtTestFree()

void omtTestFree ( omMemCell  cell)

Definition at line 134 of file omtTestAlloc.c.

135 {
136  void* addr = cell->addr;
137  unsigned long spec = cell->spec;
138  omBin bin = cell->bin;
139  omBin orig_bin = cell->orig_bin;
140  size_t size = GET_SIZE(spec);
141 
142  omtTestDebug(cell);
143 
144  if (IS_FREE_SIZE(spec))
145  {
146  if (IS_SLOPPY(spec))
147  omfreeSize(addr, size);
148  else
149  omFreeSize(addr, size);
150  }
151  else if (bin != NULL && IS_FREE_BIN(spec))
152  omFreeBin(addr, bin);
153  else if (IS_FREE_BINADDR(spec) && (bin != NULL) && (size <= OM_MAX_BLOCK_SIZE))
154  {
155  omFreeBinAddr(addr);
156  }
157  else
158  {
159  if (IS_SLOPPY(spec))
160  omfree(addr);
161  else
162  omFree(addr);
163  }
164 
165  if (bin != NULL && IS_SPEC_BIN(spec))
166  {
167  if (orig_bin != NULL)
168  omUnGetSpecBin(&orig_bin);
169  else
170  omUnGetSpecBin(&bin);
171  }
172 
173  cell->addr = NULL;
174  cell->spec = 0;
175  cell->bin = NULL;
176  cell->orig_bin = NULL;
177 }
#define IS_FREE_BINADDR(spec)
Definition: omtTest.h:90
omBin_t * omBin
Definition: omStructs.h:12
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omfreeSize(addr, size)
Definition: omAllocDecl.h:236
#define omUnGetSpecBin(bin_ptr)
Definition: omBin.h:14
#define IS_SPEC_BIN(spec)
Definition: omtTest.h:57
#define GET_SIZE(spec)
Definition: omtTest.h:52
#define IS_FREE_SIZE(spec)
Definition: omtTest.h:87
#define IS_SLOPPY(spec)
Definition: omtTest.h:89
#define omFreeBinAddr(addr)
Definition: omAllocDecl.h:258
#define omFree(addr)
Definition: omAllocDecl.h:261
#define omfree(addr)
Definition: omAllocDecl.h:237
#define IS_FREE_BIN(spec)
Definition: omtTest.h:88
void omtTestDebug(omMemCell cell)
Definition: omtTest.c:34
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#define OM_MAX_BLOCK_SIZE
Definition: omTables.c:31
#define NULL
Definition: omList.c:12
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259

◆ omtTestRealloc()

void omtTestRealloc ( omMemCell  cell,
unsigned long  new_spec 
)

Definition at line 179 of file omtTestAlloc.c.

180 {
181  void* old_addr = cell->addr;
182  unsigned long old_spec = cell->spec;
183  omBin old_bin = cell->bin;
184  omBin old_orig_bin = cell->orig_bin;
185  size_t old_size = GET_SIZE(old_spec);
186  void* new_addr;
187  omBin new_bin = NULL;
188  omBin new_orig_bin = NULL;
189  size_t new_size = GET_SIZE(new_spec);
190  size_t real_old_size = omSizeOfAddr(old_addr);
191  size_t min_size;
192 
193  omtTestDebug(cell);
194 
195  if (old_bin != NULL && IS_FREE_BIN(old_spec) &&
196  IS_BIN(new_spec) && ((new_size <= OM_MAX_BLOCK_SIZE) || IS_SPEC_BIN(new_spec)))
197  {
198  if (IS_SPEC_BIN(new_spec))
199  {
200  if (IS_ALIGNED(new_spec))
201  new_bin = omGetAlignedSpecBin(new_size);
202  else
203  new_bin = omGetSpecBin(new_size);
204  }
205  else
206  {
207  if (IS_ALIGNED(new_spec))
208  new_bin = omSmallSize2AlignedBin(new_size);
209  else
210  new_bin = omSmallSize2Bin(new_size);
211  }
212 
213  if (IS_STICKY_BIN(new_spec))
214  {
215  new_orig_bin = new_bin;
216  new_bin = omtGetStickyBin(new_bin);
217  }
218 
219  if (IS_INLINE(new_spec))
220  {
221  if (IS_ZERO(new_spec)) new_addr = omRealloc0Bin(old_addr, old_bin, new_bin);
222  else new_addr = omReallocBin(old_addr, old_bin, new_bin);
223  }
224  else
225  {
226  if (IS_ZERO(new_spec)) omTypeRealloc0Bin(old_addr, old_bin, void*, new_addr, new_bin);
227  else omTypeReallocBin(old_addr, old_bin, void*, new_addr, new_bin);
228  }
229  }
230  else
231  {
232  if (IS_FREE_SIZE(old_spec))
233  {
234  if (IS_INLINE(new_spec))
235  {
236  if (IS_ZERO(new_spec))
237  {
238  if (IS_ALIGNED(new_spec))
239  {
240  if (IS_SLOPPY(new_spec))
241  new_addr = omrealloc0Size(old_addr, old_size, new_size);
242  else
243  new_addr = omRealloc0AlignedSize(old_addr, old_size, new_size);
244  }
245  else
246  new_addr = omRealloc0Size(old_addr, old_size, new_size);
247  }
248  else
249  {
250  if (IS_ALIGNED(new_spec))
251  {
252  if (IS_SLOPPY(new_spec))
253  new_addr = omreallocSize(old_addr, old_size, new_size);
254  else
255  new_addr = omReallocAlignedSize(old_addr, old_size, new_size);
256  }
257  else new_addr = omReallocSize(old_addr, old_size, new_size);
258  }
259  }
260  else
261  {
262  if (IS_ZERO(new_spec))
263  {
264  if (IS_ALIGNED(new_spec)) omTypeRealloc0AlignedSize(old_addr, old_size, void*, new_addr, new_size);
265  else omTypeRealloc0Size(old_addr, old_size, void*, new_addr, new_size);
266  }
267  else
268  {
269  if (IS_ALIGNED(new_spec)) omTypeReallocAlignedSize(old_addr, old_size, void*, new_addr, new_size);
270  else omTypeReallocSize(old_addr, old_size, void*, new_addr, new_size);
271  }
272  }
273  }
274  else
275  {
276  if (IS_INLINE(new_spec))
277  {
278  if (IS_ZERO(new_spec))
279  {
280  if (IS_ALIGNED(new_spec))
281  {
282  if (IS_SLOPPY(new_spec))
283  new_addr = omrealloc0(old_addr, new_size);
284  else
285  new_addr = omRealloc0Aligned(old_addr, new_size);
286  }
287  else new_addr = omRealloc0(old_addr, new_size);
288  }
289  else
290  {
291  if (IS_ALIGNED(new_spec))
292  {
293  if (IS_SLOPPY(new_spec))
294  new_addr = omrealloc(old_addr, new_size);
295  else
296  new_addr = omReallocAligned(old_addr, new_size);
297  }
298  else new_addr = omRealloc(old_addr, new_size);
299  }
300  }
301  else
302  {
303  if (IS_ZERO(new_spec))
304  {
305  if (IS_ALIGNED(new_spec)) omTypeRealloc0Aligned(old_addr, void*, new_addr, new_size);
306  else omTypeRealloc0(old_addr, void*, new_addr, new_size);
307  }
308  else
309  {
310  if (IS_ALIGNED(new_spec)) omTypeReallocAligned(old_addr, void*, new_addr, new_size);
311  else omTypeRealloc(old_addr, void*, new_addr, new_size);
312  }
313  }
314  }
315  }
316 
317  if (old_bin != NULL && IS_SPEC_BIN(old_spec))
318  {
319  if (old_orig_bin != NULL)
320  omUnGetSpecBin(&old_orig_bin);
321  else
322  omUnGetSpecBin(&old_bin);
323  }
324 
325  new_size = omSizeOfAddr(new_addr);
326  old_size = real_old_size;
327  min_size = (new_size < old_size ? new_size : old_size);
328 
329  if (IS_ZERO(old_spec) && IS_ZERO(new_spec))
330  TestAddrContent(new_addr, 0, new_size);
331  else
332  {
333  TestAddrContent(new_addr, (IS_ZERO(old_spec) ? 0 : old_spec), min_size);
334  if (IS_ZERO(new_spec) && old_size < new_size)
335  TestAddrContent((char *)new_addr + old_size, 0, new_size - old_size);
336  }
337 
338  cell->addr = new_addr;
339  cell->spec = new_spec;
340  cell->bin = new_bin;
341  cell->orig_bin = new_orig_bin;
342  InitCellAddrContent(cell);
343  omtTestDebug(cell);
344 }
#define omRealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:221
omBin_t * omBin
Definition: omStructs.h:12
#define IS_ZERO(spec)
Definition: omtTest.h:55
#define omTypeReallocAligned
Definition: omAllocDecl.h:281
#define omSmallSize2AlignedBin
Definition: omtTestAlloc.c:29
size_t omSizeOfAddr(const void *addr)
#define omreallocSize(addr, o_size, size)
Definition: omAllocDecl.h:231
#define omTypeReallocSize(o_addr, o_size, type, addr, size)
Definition: omAllocDecl.h:218
#define omTypeRealloc0(o_addr, type, addr, size)
Definition: omAllocDecl.h:224
#define omTypeRealloc0Bin(o_addr, o_bin, type, addr, bin)
Definition: omAllocDecl.h:214
#define omReallocAlignedSize
Definition: omAllocDecl.h:278
#define omTypeReallocAlignedSize
Definition: omAllocDecl.h:276
void InitCellAddrContent(omMemCell cell)
Definition: omtTest.c:134
#define omUnGetSpecBin(bin_ptr)
Definition: omBin.h:14
#define IS_SPEC_BIN(spec)
Definition: omtTest.h:57
#define omrealloc0(addr, size)
Definition: omAllocDecl.h:234
#define GET_SIZE(spec)
Definition: omtTest.h:52
#define omTypeRealloc0AlignedSize
Definition: omAllocDecl.h:277
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220
#define omTypeReallocBin(o_addr, o_bin, type, addr, bin)
Definition: omAllocDecl.h:213
#define IS_FREE_SIZE(spec)
Definition: omtTest.h:87
#define omGetAlignedSpecBin(size)
Definition: omBin.h:10
#define omTypeRealloc0Aligned
Definition: omAllocDecl.h:282
void TestAddrContent(void *addr, unsigned long value, size_t size)
Definition: omtTest.c:110
#define IS_SLOPPY(spec)
Definition: omtTest.h:89
#define IS_ALIGNED(spec)
Definition: omtTest.h:54
#define IS_FREE_BIN(spec)
Definition: omtTest.h:88
#define omTypeRealloc0Size(o_addr, o_size, type, addr, size)
Definition: omAllocDecl.h:219
#define omReallocAligned
Definition: omAllocDecl.h:283
void omtTestDebug(omMemCell cell)
Definition: omtTest.c:34
omBin omtGetStickyBin(omBin bin)
Definition: omtTest.c:279
#define OM_MAX_BLOCK_SIZE
Definition: omTables.c:31
#define omGetSpecBin(size)
Definition: omBin.h:11
#define IS_STICKY_BIN(spec)
Definition: omtTest.h:50
#define omTypeRealloc(o_addr, type, addr, size)
Definition: omAllocDecl.h:223
#define omrealloc(addr, size)
Definition: omAllocDecl.h:233
#define NULL
Definition: omList.c:12
#define omRealloc0Aligned
Definition: omAllocDecl.h:284
#define omRealloc0Bin(o_addr, o_bin, bin)
Definition: omAllocDecl.h:216
#define omSmallSize2Bin(size)
#define omReallocBin(o_addr, o_bin, bin)
Definition: omAllocDecl.h:215
#define IS_INLINE(spec)
Definition: omtTest.h:58
#define IS_BIN(spec)
Definition: omtTest.h:56
#define omrealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:232
#define omRealloc0AlignedSize
Definition: omAllocDecl.h:279
#define omRealloc(addr, size)
Definition: omAllocDecl.h:225
#define omRealloc0(addr, size)
Definition: omAllocDecl.h:226