1 /*----------------------------------------------------------------------------------------
2   Database ut
3 ----------------------------------------------------------------------------------------*/
4 
5 #include "ddutil.h"
6 
7 union utTempType_ utTemp_;
8 struct utRootType_ utRootData;
9 uint8 utModuleID;
10 struct utSymtabFields utSymtabs;
11 struct utSymFields utSyms;
12 struct utDynarrayFields utDynarrays;
13 struct utSymArrayFields utSymArrays;
14 
15 /*----------------------------------------------------------------------------------------
16   Constructor/Destructor hooks.
17 ----------------------------------------------------------------------------------------*/
18 void(*utSymtabConstructorCallback)(utSymtab);
19 void(*utSymConstructorCallback)(utSym);
20 void(*utDynarrayConstructorCallback)(utDynarray);
21 void(*utDynarrayDestructorCallback)(utDynarray);
22 void(*utSymArrayConstructorCallback)(utSymArray);
23 void(*utSymArrayDestructorCallback)(utSymArray);
24 
25 /*----------------------------------------------------------------------------------------
26   Default constructor wrapper for the database manager.
27 ----------------------------------------------------------------------------------------*/
allocSymtab(void)28 static uint64 allocSymtab(void)
29 {
30     utSymtab Symtab = utSymtabAlloc();
31 
32     return utSymtab2Index(Symtab);
33 }
34 
35 /*----------------------------------------------------------------------------------------
36   Allocate the field arrays of Symtab.
37 ----------------------------------------------------------------------------------------*/
allocSymtabs(void)38 static void allocSymtabs(void)
39 {
40     utSetAllocatedSymtab(2);
41     utSetUsedSymtab(0);
42     utSymtabs.TableIndex = utNewA(uint32, (utAllocatedSymtab()));
43     utSymtabs.NumTable = utNewA(uint32, (utAllocatedSymtab()));
44     utSetUsedSymtabTable(0);
45     utSetAllocatedSymtabTable(2);
46     utSetFreeSymtabTable(0);
47     utSymtabs.Table = utNewA(utSym, utAllocatedSymtabTable());
48     utSymtabs.NumSym = utNewA(uint32, (utAllocatedSymtab()));
49 }
50 
51 /*----------------------------------------------------------------------------------------
52   Realloc the arrays of properties for class Symtab.
53 ----------------------------------------------------------------------------------------*/
reallocSymtabs(uint32 newSize)54 static void reallocSymtabs(
55     uint32 newSize)
56 {
57     utRecordResize(utModuleID, 0, (utAllocatedSymtab()), true);
58     utResizeArray(utSymtabs.TableIndex, (newSize));
59     utRecordResize(utModuleID, 0, (newSize), false);
60     utRecordResize(utModuleID, 1, (utAllocatedSymtab()), true);
61     utResizeArray(utSymtabs.NumTable, (newSize));
62     utRecordResize(utModuleID, 1, (newSize), false);
63     utRecordResize(utModuleID, 3, (utAllocatedSymtab()), true);
64     utResizeArray(utSymtabs.NumSym, (newSize));
65     utRecordResize(utModuleID, 3, (newSize), false);
66     utSetAllocatedSymtab(newSize);
67 }
68 
69 /*----------------------------------------------------------------------------------------
70   Allocate more Symtabs.
71 ----------------------------------------------------------------------------------------*/
utSymtabAllocMore(void)72 void utSymtabAllocMore(void)
73 {
74     reallocSymtabs((uint32)(utAllocatedSymtab() + (utAllocatedSymtab() >> 1)));
75 }
76 
77 /*----------------------------------------------------------------------------------------
78   Compact the Symtab.Table heap to free memory.
79 ----------------------------------------------------------------------------------------*/
utCompactSymtabTables(void)80 void utCompactSymtabTables(void)
81 {
82     uint32 elementSize = sizeof(utSym);
83     uint32 usedHeaderSize = (sizeof(utSymtab) + elementSize - 1)/elementSize;
84     uint32 freeHeaderSize = (sizeof(utSymtab) + sizeof(uint32) + elementSize - 1)/elementSize;
85     utSym *toPtr = utSymtabs.Table;
86     utSym *fromPtr = toPtr;
87     utSymtab Symtab;
88     uint32 size;
89 
90     while(fromPtr < utSymtabs.Table + utUsedSymtabTable()) {
91         Symtab = *(utSymtab *)(void *)fromPtr;
92         if(Symtab != utSymtabNull) {
93             /* Need to move it to toPtr */
94             size = utMax(utSymtabGetNumTable(Symtab) + usedHeaderSize, freeHeaderSize);
95             utRecordArray(utModuleID, 2, toPtr - utSymtabs.Table, size, true);
96             memmove((void *)toPtr, (void *)fromPtr, size*elementSize);
97             utRecordArray(utModuleID, 2, toPtr - utSymtabs.Table, size, false);
98             utSymtabSetTableIndex(Symtab, toPtr - utSymtabs.Table + usedHeaderSize);
99             toPtr += size;
100         } else {
101             /* Just skip it */
102             size = *(uint32 *)(void *)(((utSymtab *)(void *)fromPtr) + 1);
103         }
104         fromPtr += size;
105     }
106     utSetUsedSymtabTable(toPtr - utSymtabs.Table);
107     utSetFreeSymtabTable(0);
108 }
109 
110 /*----------------------------------------------------------------------------------------
111   Allocate more memory for the Symtab.Table heap.
112 ----------------------------------------------------------------------------------------*/
allocMoreSymtabTables(uint32 spaceNeeded)113 static void allocMoreSymtabTables(
114     uint32 spaceNeeded)
115 {
116     uint32 freeSpace = utAllocatedSymtabTable() - utUsedSymtabTable();
117 
118     if((utFreeSymtabTable() << 2) > utUsedSymtabTable()) {
119         utCompactSymtabTables();
120         freeSpace = utAllocatedSymtabTable() - utUsedSymtabTable();
121     }
122     if(freeSpace < spaceNeeded) {
123         utRecordResize(utModuleID, 2, utAllocatedSymtabTable(), true);
124         utSetAllocatedSymtabTable(utAllocatedSymtabTable() + spaceNeeded - freeSpace +
125             (utAllocatedSymtabTable() >> 1));
126         utResizeArray(utSymtabs.Table, utAllocatedSymtabTable());
127         utRecordResize(utModuleID, 2, utAllocatedSymtabTable(), false);
128     }
129 }
130 
131 /*----------------------------------------------------------------------------------------
132   Allocate memory for a new Symtab.Table array.
133 ----------------------------------------------------------------------------------------*/
utSymtabAllocTables(utSymtab Symtab,uint32 numTables)134 void utSymtabAllocTables(
135     utSymtab Symtab,
136     uint32 numTables)
137 {
138     uint32 freeSpace = utAllocatedSymtabTable() - utUsedSymtabTable();
139     uint32 elementSize = sizeof(utSym);
140     uint32 usedHeaderSize = (sizeof(utSymtab) + elementSize - 1)/elementSize;
141     uint32 freeHeaderSize = (sizeof(utSymtab) + sizeof(uint32) + elementSize - 1)/elementSize;
142     uint32 spaceNeeded = utMax(numTables + usedHeaderSize, freeHeaderSize);
143 
144 #if defined(DD_DEBUG)
145     utAssert(utSymtabGetNumTable(Symtab) == 0);
146 #endif
147     if(numTables == 0) {
148         return;
149     }
150     if(freeSpace < spaceNeeded) {
151         allocMoreSymtabTables(spaceNeeded);
152     }
153     utSymtabSetTableIndex(Symtab, utUsedSymtabTable() + usedHeaderSize);
154     utSymtabSetNumTable(Symtab, numTables);
155     utRecordArray(utModuleID, 2, utUsedSymtabTable(), numTables + usedHeaderSize, true);
156     *(utSymtab *)(void *)(utSymtabs.Table + utUsedSymtabTable()) = Symtab;
157     {
158         uint32 xSymtab;
159         for(xSymtab = (uint32)(utSymtabGetTableIndex(Symtab)); xSymtab < utSymtabGetTableIndex(Symtab) + numTables; xSymtab++) {
160             utSymtabs.Table[xSymtab] = utSymNull;
161         }
162     }
163     utRecordArray(utModuleID, 2, utUsedSymtabTable(), numTables + usedHeaderSize, false);
164     utSetUsedSymtabTable(utUsedSymtabTable() + spaceNeeded);
165 }
166 
167 /*----------------------------------------------------------------------------------------
168   Wrapper around utSymtabGetTables for the database manager.
169 ----------------------------------------------------------------------------------------*/
getSymtabTables(uint64 objectNumber,uint32 * numValues)170 static void *getSymtabTables(
171     uint64 objectNumber,
172     uint32 *numValues)
173 {
174     utSymtab Symtab = utIndex2Symtab((uint32)objectNumber);
175 
176     *numValues = utSymtabGetNumTable(Symtab);
177     return utSymtabGetTables(Symtab);
178 }
179 
180 /*----------------------------------------------------------------------------------------
181   Wrapper around utSymtabAllocTables for the database manager.
182 ----------------------------------------------------------------------------------------*/
allocSymtabTables(uint64 objectNumber,uint32 numValues)183 static void *allocSymtabTables(
184     uint64 objectNumber,
185     uint32 numValues)
186 {
187     utSymtab Symtab = utIndex2Symtab((uint32)objectNumber);
188 
189     utSymtabSetTableIndex(Symtab, 0);
190     utSymtabSetNumTable(Symtab, 0);
191     if(numValues == 0) {
192         return NULL;
193     }
194     utSymtabAllocTables(Symtab, numValues);
195     return utSymtabGetTables(Symtab);
196 }
197 
198 /*----------------------------------------------------------------------------------------
199   Free memory used by the Symtab.Table array.
200 ----------------------------------------------------------------------------------------*/
utSymtabFreeTables(utSymtab Symtab)201 void utSymtabFreeTables(
202     utSymtab Symtab)
203 {
204     uint32 elementSize = sizeof(utSym);
205     uint32 usedHeaderSize = (sizeof(utSymtab) + elementSize - 1)/elementSize;
206     uint32 freeHeaderSize = (sizeof(utSymtab) + sizeof(uint32) + elementSize - 1)/elementSize;
207     uint32 size = utMax(utSymtabGetNumTable(Symtab) + usedHeaderSize, freeHeaderSize);
208     utSym *dataPtr = utSymtabGetTables(Symtab) - usedHeaderSize;
209 
210     if(utSymtabGetNumTable(Symtab) == 0) {
211         return;
212     }
213     utRecordArray(utModuleID, 2, dataPtr - utSymtabs.Table, freeHeaderSize, true);
214     *(utSymtab *)(void *)(dataPtr) = utSymtabNull;
215     *(uint32 *)(void *)(((utSymtab *)(void *)dataPtr) + 1) = size;
216     utRecordArray(utModuleID, 2, dataPtr - utSymtabs.Table, freeHeaderSize, false);
217     utSymtabSetNumTable(Symtab, 0);
218     utSetFreeSymtabTable(utFreeSymtabTable() + size);
219 }
220 
221 /*----------------------------------------------------------------------------------------
222   Resize the Symtab.Table array.
223 ----------------------------------------------------------------------------------------*/
utSymtabResizeTables(utSymtab Symtab,uint32 numTables)224 void utSymtabResizeTables(
225     utSymtab Symtab,
226     uint32 numTables)
227 {
228     uint32 freeSpace;
229     uint32 elementSize = sizeof(utSym);
230     uint32 usedHeaderSize = (sizeof(utSymtab) + elementSize - 1)/elementSize;
231     uint32 freeHeaderSize = (sizeof(utSymtab) + sizeof(uint32) + elementSize - 1)/elementSize;
232     uint32 newSize = utMax(numTables + usedHeaderSize, freeHeaderSize);
233     uint32 oldSize = utMax(utSymtabGetNumTable(Symtab) + usedHeaderSize, freeHeaderSize);
234     utSym *dataPtr;
235 
236     if(numTables == 0) {
237         if(utSymtabGetNumTable(Symtab) != 0) {
238             utSymtabFreeTables(Symtab);
239         }
240         return;
241     }
242     if(utSymtabGetNumTable(Symtab) == 0) {
243         utSymtabAllocTables(Symtab, numTables);
244         return;
245     }
246     freeSpace = utAllocatedSymtabTable() - utUsedSymtabTable();
247     if(freeSpace < newSize) {
248         allocMoreSymtabTables(newSize);
249     }
250     dataPtr = utSymtabGetTables(Symtab) - usedHeaderSize;
251     utRecordArray(utModuleID, 2, utUsedSymtabTable(), newSize, true);
252     utRecordArray(utModuleID, 2, dataPtr - utSymtabs.Table, freeHeaderSize, true);
253     memcpy((void *)(utSymtabs.Table + utUsedSymtabTable()), dataPtr,
254         elementSize*utMin(oldSize, newSize));
255     if(newSize > oldSize) {
256         {
257             uint32 xSymtab;
258             for(xSymtab = (uint32)(utUsedSymtabTable() + oldSize); xSymtab < utUsedSymtabTable() + oldSize + newSize - oldSize; xSymtab++) {
259                 utSymtabs.Table[xSymtab] = utSymNull;
260             }
261         }
262     }
263     *(utSymtab *)(void *)dataPtr = utSymtabNull;
264     *(uint32 *)(void *)(((utSymtab *)(void *)dataPtr) + 1) = oldSize;
265     utRecordArray(utModuleID, 2, utUsedSymtabTable(), newSize, false);
266     utRecordArray(utModuleID, 2, dataPtr - utSymtabs.Table, freeHeaderSize, false);
267     utSetFreeSymtabTable(utFreeSymtabTable() + oldSize);
268     utSymtabSetTableIndex(Symtab, utUsedSymtabTable() + usedHeaderSize);
269     utSymtabSetNumTable(Symtab, numTables);
270     utSetUsedSymtabTable(utUsedSymtabTable() + newSize);
271 }
272 
273 /*----------------------------------------------------------------------------------------
274   Copy the properties of Symtab.
275 ----------------------------------------------------------------------------------------*/
utSymtabCopyProps(utSymtab oldSymtab,utSymtab newSymtab)276 void utSymtabCopyProps(
277     utSymtab oldSymtab,
278     utSymtab newSymtab)
279 {
280     utSymtabSetNumSym(newSymtab, utSymtabGetNumSym(oldSymtab));
281 }
282 
283 #if defined(DD_DEBUG)
284 /*----------------------------------------------------------------------------------------
285   Write out all the fields of an object.
286 ----------------------------------------------------------------------------------------*/
utShowSymtab(utSymtab Symtab)287 void utShowSymtab(
288     utSymtab Symtab)
289 {
290     utDatabaseShowObject("ut", "Symtab", utSymtab2Index(Symtab));
291 }
292 #endif
293 
294 /*----------------------------------------------------------------------------------------
295   Default constructor wrapper for the database manager.
296 ----------------------------------------------------------------------------------------*/
allocSym(void)297 static uint64 allocSym(void)
298 {
299     utSym Sym = utSymAlloc();
300 
301     return utSym2Index(Sym);
302 }
303 
304 /*----------------------------------------------------------------------------------------
305   Allocate the field arrays of Sym.
306 ----------------------------------------------------------------------------------------*/
allocSyms(void)307 static void allocSyms(void)
308 {
309     utSetAllocatedSym(2);
310     utSetUsedSym(0);
311     utSyms.NameIndex = utNewA(uint32, (utAllocatedSym()));
312     utSyms.NumName = utNewA(uint32, (utAllocatedSym()));
313     utSetUsedSymName(0);
314     utSetAllocatedSymName(2);
315     utSetFreeSymName(0);
316     utSyms.Name = utNewA(char, utAllocatedSymName());
317     utSyms.HashValue = utNewA(uint32, (utAllocatedSym()));
318     utSyms.Next = utNewA(utSym, (utAllocatedSym()));
319 }
320 
321 /*----------------------------------------------------------------------------------------
322   Realloc the arrays of properties for class Sym.
323 ----------------------------------------------------------------------------------------*/
reallocSyms(uint32 newSize)324 static void reallocSyms(
325     uint32 newSize)
326 {
327     utRecordResize(utModuleID, 4, (utAllocatedSym()), true);
328     utResizeArray(utSyms.NameIndex, (newSize));
329     utRecordResize(utModuleID, 4, (newSize), false);
330     utRecordResize(utModuleID, 5, (utAllocatedSym()), true);
331     utResizeArray(utSyms.NumName, (newSize));
332     utRecordResize(utModuleID, 5, (newSize), false);
333     utRecordResize(utModuleID, 7, (utAllocatedSym()), true);
334     utResizeArray(utSyms.HashValue, (newSize));
335     utRecordResize(utModuleID, 7, (newSize), false);
336     utRecordResize(utModuleID, 8, (utAllocatedSym()), true);
337     utResizeArray(utSyms.Next, (newSize));
338     utRecordResize(utModuleID, 8, (newSize), false);
339     utSetAllocatedSym(newSize);
340 }
341 
342 /*----------------------------------------------------------------------------------------
343   Allocate more Syms.
344 ----------------------------------------------------------------------------------------*/
utSymAllocMore(void)345 void utSymAllocMore(void)
346 {
347     reallocSyms((uint32)(utAllocatedSym() + (utAllocatedSym() >> 1)));
348 }
349 
350 /*----------------------------------------------------------------------------------------
351   Compact the Sym.Name heap to free memory.
352 ----------------------------------------------------------------------------------------*/
utCompactSymNames(void)353 void utCompactSymNames(void)
354 {
355     uint32 elementSize = sizeof(char);
356     uint32 usedHeaderSize = (sizeof(utSym) + elementSize - 1)/elementSize;
357     uint32 freeHeaderSize = (sizeof(utSym) + sizeof(uint32) + elementSize - 1)/elementSize;
358     char *toPtr = utSyms.Name;
359     char *fromPtr = toPtr;
360     utSym Sym;
361     uint32 size;
362 
363     while(fromPtr < utSyms.Name + utUsedSymName()) {
364         Sym = *(utSym *)(void *)fromPtr;
365         if(Sym != utSymNull) {
366             /* Need to move it to toPtr */
367             size = utMax(utSymGetNumName(Sym) + usedHeaderSize, freeHeaderSize);
368             utRecordArray(utModuleID, 6, toPtr - utSyms.Name, size, true);
369             memmove((void *)toPtr, (void *)fromPtr, size*elementSize);
370             utRecordArray(utModuleID, 6, toPtr - utSyms.Name, size, false);
371             utSymSetNameIndex(Sym, toPtr - utSyms.Name + usedHeaderSize);
372             toPtr += size;
373         } else {
374             /* Just skip it */
375             size = *(uint32 *)(void *)(((utSym *)(void *)fromPtr) + 1);
376         }
377         fromPtr += size;
378     }
379     utSetUsedSymName(toPtr - utSyms.Name);
380     utSetFreeSymName(0);
381 }
382 
383 /*----------------------------------------------------------------------------------------
384   Allocate more memory for the Sym.Name heap.
385 ----------------------------------------------------------------------------------------*/
allocMoreSymNames(uint32 spaceNeeded)386 static void allocMoreSymNames(
387     uint32 spaceNeeded)
388 {
389     uint32 freeSpace = utAllocatedSymName() - utUsedSymName();
390 
391     if((utFreeSymName() << 2) > utUsedSymName()) {
392         utCompactSymNames();
393         freeSpace = utAllocatedSymName() - utUsedSymName();
394     }
395     if(freeSpace < spaceNeeded) {
396         utRecordResize(utModuleID, 6, utAllocatedSymName(), true);
397         utSetAllocatedSymName(utAllocatedSymName() + spaceNeeded - freeSpace +
398             (utAllocatedSymName() >> 1));
399         utResizeArray(utSyms.Name, utAllocatedSymName());
400         utRecordResize(utModuleID, 6, utAllocatedSymName(), false);
401     }
402 }
403 
404 /*----------------------------------------------------------------------------------------
405   Allocate memory for a new Sym.Name array.
406 ----------------------------------------------------------------------------------------*/
utSymAllocNames(utSym Sym,uint32 numNames)407 void utSymAllocNames(
408     utSym Sym,
409     uint32 numNames)
410 {
411     uint32 freeSpace = utAllocatedSymName() - utUsedSymName();
412     uint32 elementSize = sizeof(char);
413     uint32 usedHeaderSize = (sizeof(utSym) + elementSize - 1)/elementSize;
414     uint32 freeHeaderSize = (sizeof(utSym) + sizeof(uint32) + elementSize - 1)/elementSize;
415     uint32 spaceNeeded = utMax(numNames + usedHeaderSize, freeHeaderSize);
416 
417 #if defined(DD_DEBUG)
418     utAssert(utSymGetNumName(Sym) == 0);
419 #endif
420     if(numNames == 0) {
421         return;
422     }
423     if(freeSpace < spaceNeeded) {
424         allocMoreSymNames(spaceNeeded);
425     }
426     utSymSetNameIndex(Sym, utUsedSymName() + usedHeaderSize);
427     utSymSetNumName(Sym, numNames);
428     utRecordArray(utModuleID, 6, utUsedSymName(), numNames + usedHeaderSize, true);
429     *(utSym *)(void *)(utSyms.Name + utUsedSymName()) = Sym;
430     memset(utSyms.Name + utSymGetNameIndex(Sym), 0, ((numNames))*sizeof(char));
431     utRecordArray(utModuleID, 6, utUsedSymName(), numNames + usedHeaderSize, false);
432     utSetUsedSymName(utUsedSymName() + spaceNeeded);
433 }
434 
435 /*----------------------------------------------------------------------------------------
436   Wrapper around utSymGetNames for the database manager.
437 ----------------------------------------------------------------------------------------*/
getSymNames(uint64 objectNumber,uint32 * numValues)438 static void *getSymNames(
439     uint64 objectNumber,
440     uint32 *numValues)
441 {
442     utSym Sym = utIndex2Sym((uint32)objectNumber);
443 
444     *numValues = utSymGetNumName(Sym);
445     return utSymGetNames(Sym);
446 }
447 
448 /*----------------------------------------------------------------------------------------
449   Wrapper around utSymAllocNames for the database manager.
450 ----------------------------------------------------------------------------------------*/
allocSymNames(uint64 objectNumber,uint32 numValues)451 static void *allocSymNames(
452     uint64 objectNumber,
453     uint32 numValues)
454 {
455     utSym Sym = utIndex2Sym((uint32)objectNumber);
456 
457     utSymSetNameIndex(Sym, 0);
458     utSymSetNumName(Sym, 0);
459     if(numValues == 0) {
460         return NULL;
461     }
462     utSymAllocNames(Sym, numValues);
463     return utSymGetNames(Sym);
464 }
465 
466 /*----------------------------------------------------------------------------------------
467   Free memory used by the Sym.Name array.
468 ----------------------------------------------------------------------------------------*/
utSymFreeNames(utSym Sym)469 void utSymFreeNames(
470     utSym Sym)
471 {
472     uint32 elementSize = sizeof(char);
473     uint32 usedHeaderSize = (sizeof(utSym) + elementSize - 1)/elementSize;
474     uint32 freeHeaderSize = (sizeof(utSym) + sizeof(uint32) + elementSize - 1)/elementSize;
475     uint32 size = utMax(utSymGetNumName(Sym) + usedHeaderSize, freeHeaderSize);
476     char *dataPtr = utSymGetNames(Sym) - usedHeaderSize;
477 
478     if(utSymGetNumName(Sym) == 0) {
479         return;
480     }
481     utRecordArray(utModuleID, 6, dataPtr - utSyms.Name, freeHeaderSize, true);
482     *(utSym *)(void *)(dataPtr) = utSymNull;
483     *(uint32 *)(void *)(((utSym *)(void *)dataPtr) + 1) = size;
484     utRecordArray(utModuleID, 6, dataPtr - utSyms.Name, freeHeaderSize, false);
485     utSymSetNumName(Sym, 0);
486     utSetFreeSymName(utFreeSymName() + size);
487 }
488 
489 /*----------------------------------------------------------------------------------------
490   Resize the Sym.Name array.
491 ----------------------------------------------------------------------------------------*/
utSymResizeNames(utSym Sym,uint32 numNames)492 void utSymResizeNames(
493     utSym Sym,
494     uint32 numNames)
495 {
496     uint32 freeSpace;
497     uint32 elementSize = sizeof(char);
498     uint32 usedHeaderSize = (sizeof(utSym) + elementSize - 1)/elementSize;
499     uint32 freeHeaderSize = (sizeof(utSym) + sizeof(uint32) + elementSize - 1)/elementSize;
500     uint32 newSize = utMax(numNames + usedHeaderSize, freeHeaderSize);
501     uint32 oldSize = utMax(utSymGetNumName(Sym) + usedHeaderSize, freeHeaderSize);
502     char *dataPtr;
503 
504     if(numNames == 0) {
505         if(utSymGetNumName(Sym) != 0) {
506             utSymFreeNames(Sym);
507         }
508         return;
509     }
510     if(utSymGetNumName(Sym) == 0) {
511         utSymAllocNames(Sym, numNames);
512         return;
513     }
514     freeSpace = utAllocatedSymName() - utUsedSymName();
515     if(freeSpace < newSize) {
516         allocMoreSymNames(newSize);
517     }
518     dataPtr = utSymGetNames(Sym) - usedHeaderSize;
519     utRecordArray(utModuleID, 6, utUsedSymName(), newSize, true);
520     utRecordArray(utModuleID, 6, dataPtr - utSyms.Name, freeHeaderSize, true);
521     memcpy((void *)(utSyms.Name + utUsedSymName()), dataPtr,
522         elementSize*utMin(oldSize, newSize));
523     if(newSize > oldSize) {
524         memset(utSyms.Name + utUsedSymName() + oldSize, 0, ((newSize - oldSize))*sizeof(char));
525     }
526     *(utSym *)(void *)dataPtr = utSymNull;
527     *(uint32 *)(void *)(((utSym *)(void *)dataPtr) + 1) = oldSize;
528     utRecordArray(utModuleID, 6, utUsedSymName(), newSize, false);
529     utRecordArray(utModuleID, 6, dataPtr - utSyms.Name, freeHeaderSize, false);
530     utSetFreeSymName(utFreeSymName() + oldSize);
531     utSymSetNameIndex(Sym, utUsedSymName() + usedHeaderSize);
532     utSymSetNumName(Sym, numNames);
533     utSetUsedSymName(utUsedSymName() + newSize);
534 }
535 
536 /*----------------------------------------------------------------------------------------
537   Copy the properties of Sym.
538 ----------------------------------------------------------------------------------------*/
utSymCopyProps(utSym oldSym,utSym newSym)539 void utSymCopyProps(
540     utSym oldSym,
541     utSym newSym)
542 {
543     utSymSetHashValue(newSym, utSymGetHashValue(oldSym));
544 }
545 
546 #if defined(DD_DEBUG)
547 /*----------------------------------------------------------------------------------------
548   Write out all the fields of an object.
549 ----------------------------------------------------------------------------------------*/
utShowSym(utSym Sym)550 void utShowSym(
551     utSym Sym)
552 {
553     utDatabaseShowObject("ut", "Sym", utSym2Index(Sym));
554 }
555 #endif
556 
557 /*----------------------------------------------------------------------------------------
558   Destroy Dynarray including everything in it. Remove from parents.
559 ----------------------------------------------------------------------------------------*/
utDynarrayDestroy(utDynarray Dynarray)560 void utDynarrayDestroy(
561     utDynarray Dynarray)
562 {
563     if(utDynarrayDestructorCallback != NULL) {
564         utDynarrayDestructorCallback(Dynarray);
565     }
566     utDynarrayFree(Dynarray);
567 }
568 
569 /*----------------------------------------------------------------------------------------
570   Default constructor wrapper for the database manager.
571 ----------------------------------------------------------------------------------------*/
allocDynarray(void)572 static uint64 allocDynarray(void)
573 {
574     utDynarray Dynarray = utDynarrayAlloc();
575 
576     return utDynarray2Index(Dynarray);
577 }
578 
579 /*----------------------------------------------------------------------------------------
580   Destructor wrapper for the database manager.
581 ----------------------------------------------------------------------------------------*/
destroyDynarray(uint64 objectIndex)582 static void destroyDynarray(
583     uint64 objectIndex)
584 {
585     utDynarrayDestroy(utIndex2Dynarray((uint32)objectIndex));
586 }
587 
588 /*----------------------------------------------------------------------------------------
589   Allocate the field arrays of Dynarray.
590 ----------------------------------------------------------------------------------------*/
allocDynarrays(void)591 static void allocDynarrays(void)
592 {
593     utSetAllocatedDynarray(2);
594     utSetUsedDynarray(0);
595     utSetFirstFreeDynarray(utDynarrayNull);
596     utDynarrays.ValueIndex = utNewA(uint32, (utAllocatedDynarray()));
597     utDynarrays.NumValue = utNewA(uint32, (utAllocatedDynarray()));
598     utSetUsedDynarrayValue(0);
599     utSetAllocatedDynarrayValue(2);
600     utSetFreeDynarrayValue(0);
601     utDynarrays.Value = utNewA(uint8, utAllocatedDynarrayValue());
602     utDynarrays.ValueSize = utNewA(uint16, (utAllocatedDynarray()));
603     utDynarrays.UsedValue = utNewA(uint32, (utAllocatedDynarray()));
604     utDynarrays.Size = utNewA(uint32, (utAllocatedDynarray()));
605     utDynarrays.FreeList = utNewA(utDynarray, (utAllocatedDynarray()));
606 }
607 
608 /*----------------------------------------------------------------------------------------
609   Realloc the arrays of properties for class Dynarray.
610 ----------------------------------------------------------------------------------------*/
reallocDynarrays(uint32 newSize)611 static void reallocDynarrays(
612     uint32 newSize)
613 {
614     utRecordResize(utModuleID, 9, (utAllocatedDynarray()), true);
615     utResizeArray(utDynarrays.ValueIndex, (newSize));
616     utRecordResize(utModuleID, 9, (newSize), false);
617     utRecordResize(utModuleID, 10, (utAllocatedDynarray()), true);
618     utResizeArray(utDynarrays.NumValue, (newSize));
619     utRecordResize(utModuleID, 10, (newSize), false);
620     utRecordResize(utModuleID, 12, (utAllocatedDynarray()), true);
621     utResizeArray(utDynarrays.ValueSize, (newSize));
622     utRecordResize(utModuleID, 12, (newSize), false);
623     utRecordResize(utModuleID, 13, (utAllocatedDynarray()), true);
624     utResizeArray(utDynarrays.UsedValue, (newSize));
625     utRecordResize(utModuleID, 13, (newSize), false);
626     utRecordResize(utModuleID, 14, (utAllocatedDynarray()), true);
627     utResizeArray(utDynarrays.Size, (newSize));
628     utRecordResize(utModuleID, 14, (newSize), false);
629     utRecordResize(utModuleID, 15, (utAllocatedDynarray()), true);
630     utResizeArray(utDynarrays.FreeList, (newSize));
631     utRecordResize(utModuleID, 15, (newSize), false);
632     utSetAllocatedDynarray(newSize);
633 }
634 
635 /*----------------------------------------------------------------------------------------
636   Allocate more Dynarrays.
637 ----------------------------------------------------------------------------------------*/
utDynarrayAllocMore(void)638 void utDynarrayAllocMore(void)
639 {
640     reallocDynarrays((uint32)(utAllocatedDynarray() + (utAllocatedDynarray() >> 1)));
641 }
642 
643 /*----------------------------------------------------------------------------------------
644   Compact the Dynarray.Value heap to free memory.
645 ----------------------------------------------------------------------------------------*/
utCompactDynarrayValues(void)646 void utCompactDynarrayValues(void)
647 {
648     uint32 elementSize = sizeof(uint8);
649     uint32 usedHeaderSize = (sizeof(utDynarray) + elementSize - 1)/elementSize;
650     uint32 freeHeaderSize = (sizeof(utDynarray) + sizeof(uint32) + elementSize - 1)/elementSize;
651     uint8 *toPtr = utDynarrays.Value;
652     uint8 *fromPtr = toPtr;
653     utDynarray Dynarray;
654     uint32 size;
655 
656     while(fromPtr < utDynarrays.Value + utUsedDynarrayValue()) {
657         Dynarray = *(utDynarray *)(void *)fromPtr;
658         if(Dynarray != utDynarrayNull) {
659             /* Need to move it to toPtr */
660             size = utMax(utDynarrayGetNumValue(Dynarray) + usedHeaderSize, freeHeaderSize);
661             utRecordArray(utModuleID, 11, toPtr - utDynarrays.Value, size, true);
662             memmove((void *)toPtr, (void *)fromPtr, size*elementSize);
663             utRecordArray(utModuleID, 11, toPtr - utDynarrays.Value, size, false);
664             utDynarraySetValueIndex(Dynarray, toPtr - utDynarrays.Value + usedHeaderSize);
665             toPtr += size;
666         } else {
667             /* Just skip it */
668             size = *(uint32 *)(void *)(((utDynarray *)(void *)fromPtr) + 1);
669         }
670         fromPtr += size;
671     }
672     utSetUsedDynarrayValue(toPtr - utDynarrays.Value);
673     utSetFreeDynarrayValue(0);
674 }
675 
676 /*----------------------------------------------------------------------------------------
677   Allocate more memory for the Dynarray.Value heap.
678 ----------------------------------------------------------------------------------------*/
allocMoreDynarrayValues(uint32 spaceNeeded)679 static void allocMoreDynarrayValues(
680     uint32 spaceNeeded)
681 {
682     uint32 freeSpace = utAllocatedDynarrayValue() - utUsedDynarrayValue();
683 
684     if((utFreeDynarrayValue() << 2) > utUsedDynarrayValue()) {
685         utCompactDynarrayValues();
686         freeSpace = utAllocatedDynarrayValue() - utUsedDynarrayValue();
687     }
688     if(freeSpace < spaceNeeded) {
689         utRecordResize(utModuleID, 11, utAllocatedDynarrayValue(), true);
690         utSetAllocatedDynarrayValue(utAllocatedDynarrayValue() + spaceNeeded - freeSpace +
691             (utAllocatedDynarrayValue() >> 1));
692         utResizeArray(utDynarrays.Value, utAllocatedDynarrayValue());
693         utRecordResize(utModuleID, 11, utAllocatedDynarrayValue(), false);
694     }
695 }
696 
697 /*----------------------------------------------------------------------------------------
698   Allocate memory for a new Dynarray.Value array.
699 ----------------------------------------------------------------------------------------*/
utDynarrayAllocValues(utDynarray Dynarray,uint32 numValues)700 void utDynarrayAllocValues(
701     utDynarray Dynarray,
702     uint32 numValues)
703 {
704     uint32 freeSpace = utAllocatedDynarrayValue() - utUsedDynarrayValue();
705     uint32 elementSize = sizeof(uint8);
706     uint32 usedHeaderSize = (sizeof(utDynarray) + elementSize - 1)/elementSize;
707     uint32 freeHeaderSize = (sizeof(utDynarray) + sizeof(uint32) + elementSize - 1)/elementSize;
708     uint32 spaceNeeded = utMax(numValues + usedHeaderSize, freeHeaderSize);
709 
710 #if defined(DD_DEBUG)
711     utAssert(utDynarrayGetNumValue(Dynarray) == 0);
712 #endif
713     if(numValues == 0) {
714         return;
715     }
716     if(freeSpace < spaceNeeded) {
717         allocMoreDynarrayValues(spaceNeeded);
718     }
719     utDynarraySetValueIndex(Dynarray, utUsedDynarrayValue() + usedHeaderSize);
720     utDynarraySetNumValue(Dynarray, numValues);
721     utRecordArray(utModuleID, 11, utUsedDynarrayValue(), numValues + usedHeaderSize, true);
722     *(utDynarray *)(void *)(utDynarrays.Value + utUsedDynarrayValue()) = Dynarray;
723     memset(utDynarrays.Value + utDynarrayGetValueIndex(Dynarray), 0, ((numValues))*sizeof(uint8));
724     utRecordArray(utModuleID, 11, utUsedDynarrayValue(), numValues + usedHeaderSize, false);
725     utSetUsedDynarrayValue(utUsedDynarrayValue() + spaceNeeded);
726 }
727 
728 /*----------------------------------------------------------------------------------------
729   Wrapper around utDynarrayGetValues for the database manager.
730 ----------------------------------------------------------------------------------------*/
getDynarrayValues(uint64 objectNumber,uint32 * numValues)731 static void *getDynarrayValues(
732     uint64 objectNumber,
733     uint32 *numValues)
734 {
735     utDynarray Dynarray = utIndex2Dynarray((uint32)objectNumber);
736 
737     *numValues = utDynarrayGetNumValue(Dynarray);
738     return utDynarrayGetValues(Dynarray);
739 }
740 
741 /*----------------------------------------------------------------------------------------
742   Wrapper around utDynarrayAllocValues for the database manager.
743 ----------------------------------------------------------------------------------------*/
allocDynarrayValues(uint64 objectNumber,uint32 numValues)744 static void *allocDynarrayValues(
745     uint64 objectNumber,
746     uint32 numValues)
747 {
748     utDynarray Dynarray = utIndex2Dynarray((uint32)objectNumber);
749 
750     utDynarraySetValueIndex(Dynarray, 0);
751     utDynarraySetNumValue(Dynarray, 0);
752     if(numValues == 0) {
753         return NULL;
754     }
755     utDynarrayAllocValues(Dynarray, numValues);
756     return utDynarrayGetValues(Dynarray);
757 }
758 
759 /*----------------------------------------------------------------------------------------
760   Free memory used by the Dynarray.Value array.
761 ----------------------------------------------------------------------------------------*/
utDynarrayFreeValues(utDynarray Dynarray)762 void utDynarrayFreeValues(
763     utDynarray Dynarray)
764 {
765     uint32 elementSize = sizeof(uint8);
766     uint32 usedHeaderSize = (sizeof(utDynarray) + elementSize - 1)/elementSize;
767     uint32 freeHeaderSize = (sizeof(utDynarray) + sizeof(uint32) + elementSize - 1)/elementSize;
768     uint32 size = utMax(utDynarrayGetNumValue(Dynarray) + usedHeaderSize, freeHeaderSize);
769     uint8 *dataPtr = utDynarrayGetValues(Dynarray) - usedHeaderSize;
770 
771     if(utDynarrayGetNumValue(Dynarray) == 0) {
772         return;
773     }
774     utRecordArray(utModuleID, 11, dataPtr - utDynarrays.Value, freeHeaderSize, true);
775     *(utDynarray *)(void *)(dataPtr) = utDynarrayNull;
776     *(uint32 *)(void *)(((utDynarray *)(void *)dataPtr) + 1) = size;
777     utRecordArray(utModuleID, 11, dataPtr - utDynarrays.Value, freeHeaderSize, false);
778     utDynarraySetNumValue(Dynarray, 0);
779     utSetFreeDynarrayValue(utFreeDynarrayValue() + size);
780 }
781 
782 /*----------------------------------------------------------------------------------------
783   Resize the Dynarray.Value array.
784 ----------------------------------------------------------------------------------------*/
utDynarrayResizeValues(utDynarray Dynarray,uint32 numValues)785 void utDynarrayResizeValues(
786     utDynarray Dynarray,
787     uint32 numValues)
788 {
789     uint32 freeSpace;
790     uint32 elementSize = sizeof(uint8);
791     uint32 usedHeaderSize = (sizeof(utDynarray) + elementSize - 1)/elementSize;
792     uint32 freeHeaderSize = (sizeof(utDynarray) + sizeof(uint32) + elementSize - 1)/elementSize;
793     uint32 newSize = utMax(numValues + usedHeaderSize, freeHeaderSize);
794     uint32 oldSize = utMax(utDynarrayGetNumValue(Dynarray) + usedHeaderSize, freeHeaderSize);
795     uint8 *dataPtr;
796 
797     if(numValues == 0) {
798         if(utDynarrayGetNumValue(Dynarray) != 0) {
799             utDynarrayFreeValues(Dynarray);
800         }
801         return;
802     }
803     if(utDynarrayGetNumValue(Dynarray) == 0) {
804         utDynarrayAllocValues(Dynarray, numValues);
805         return;
806     }
807     freeSpace = utAllocatedDynarrayValue() - utUsedDynarrayValue();
808     if(freeSpace < newSize) {
809         allocMoreDynarrayValues(newSize);
810     }
811     dataPtr = utDynarrayGetValues(Dynarray) - usedHeaderSize;
812     utRecordArray(utModuleID, 11, utUsedDynarrayValue(), newSize, true);
813     utRecordArray(utModuleID, 11, dataPtr - utDynarrays.Value, freeHeaderSize, true);
814     memcpy((void *)(utDynarrays.Value + utUsedDynarrayValue()), dataPtr,
815         elementSize*utMin(oldSize, newSize));
816     if(newSize > oldSize) {
817         memset(utDynarrays.Value + utUsedDynarrayValue() + oldSize, 0, ((newSize - oldSize))*sizeof(uint8));
818     }
819     *(utDynarray *)(void *)dataPtr = utDynarrayNull;
820     *(uint32 *)(void *)(((utDynarray *)(void *)dataPtr) + 1) = oldSize;
821     utRecordArray(utModuleID, 11, utUsedDynarrayValue(), newSize, false);
822     utRecordArray(utModuleID, 11, dataPtr - utDynarrays.Value, freeHeaderSize, false);
823     utSetFreeDynarrayValue(utFreeDynarrayValue() + oldSize);
824     utDynarraySetValueIndex(Dynarray, utUsedDynarrayValue() + usedHeaderSize);
825     utDynarraySetNumValue(Dynarray, numValues);
826     utSetUsedDynarrayValue(utUsedDynarrayValue() + newSize);
827 }
828 
829 /*----------------------------------------------------------------------------------------
830   Copy the properties of Dynarray.
831 ----------------------------------------------------------------------------------------*/
utDynarrayCopyProps(utDynarray oldDynarray,utDynarray newDynarray)832 void utDynarrayCopyProps(
833     utDynarray oldDynarray,
834     utDynarray newDynarray)
835 {
836     utDynarraySetValueSize(newDynarray, utDynarrayGetValueSize(oldDynarray));
837     utDynarraySetUsedValue(newDynarray, utDynarrayGetUsedValue(oldDynarray));
838     utDynarraySetSize(newDynarray, utDynarrayGetSize(oldDynarray));
839 }
840 
841 #if defined(DD_DEBUG)
842 /*----------------------------------------------------------------------------------------
843   Write out all the fields of an object.
844 ----------------------------------------------------------------------------------------*/
utShowDynarray(utDynarray Dynarray)845 void utShowDynarray(
846     utDynarray Dynarray)
847 {
848     utDatabaseShowObject("ut", "Dynarray", utDynarray2Index(Dynarray));
849 }
850 #endif
851 
852 /*----------------------------------------------------------------------------------------
853   Destroy SymArray including everything in it. Remove from parents.
854 ----------------------------------------------------------------------------------------*/
utSymArrayDestroy(utSymArray SymArray)855 void utSymArrayDestroy(
856     utSymArray SymArray)
857 {
858     if(utSymArrayDestructorCallback != NULL) {
859         utSymArrayDestructorCallback(SymArray);
860     }
861     utSymArrayFree(SymArray);
862 }
863 
864 /*----------------------------------------------------------------------------------------
865   Default constructor wrapper for the database manager.
866 ----------------------------------------------------------------------------------------*/
allocSymArray(void)867 static uint64 allocSymArray(void)
868 {
869     utSymArray SymArray = utSymArrayAlloc();
870 
871     return utSymArray2Index(SymArray);
872 }
873 
874 /*----------------------------------------------------------------------------------------
875   Destructor wrapper for the database manager.
876 ----------------------------------------------------------------------------------------*/
destroySymArray(uint64 objectIndex)877 static void destroySymArray(
878     uint64 objectIndex)
879 {
880     utSymArrayDestroy(utIndex2SymArray((uint32)objectIndex));
881 }
882 
883 /*----------------------------------------------------------------------------------------
884   Allocate the field arrays of SymArray.
885 ----------------------------------------------------------------------------------------*/
allocSymArrays(void)886 static void allocSymArrays(void)
887 {
888     utSetAllocatedSymArray(2);
889     utSetUsedSymArray(0);
890     utSetFirstFreeSymArray(utSymArrayNull);
891     utSymArrays.SymIndex = utNewA(uint32, (utAllocatedSymArray()));
892     utSymArrays.NumSym = utNewA(uint32, (utAllocatedSymArray()));
893     utSetUsedSymArraySym(0);
894     utSetAllocatedSymArraySym(2);
895     utSetFreeSymArraySym(0);
896     utSymArrays.Sym = utNewA(utSym, utAllocatedSymArraySym());
897     utSymArrays.UsedSym = utNewA(uint32, (utAllocatedSymArray()));
898     utSymArrays.FreeList = utNewA(utSymArray, (utAllocatedSymArray()));
899 }
900 
901 /*----------------------------------------------------------------------------------------
902   Realloc the arrays of properties for class SymArray.
903 ----------------------------------------------------------------------------------------*/
reallocSymArrays(uint32 newSize)904 static void reallocSymArrays(
905     uint32 newSize)
906 {
907     utRecordResize(utModuleID, 16, (utAllocatedSymArray()), true);
908     utResizeArray(utSymArrays.SymIndex, (newSize));
909     utRecordResize(utModuleID, 16, (newSize), false);
910     utRecordResize(utModuleID, 17, (utAllocatedSymArray()), true);
911     utResizeArray(utSymArrays.NumSym, (newSize));
912     utRecordResize(utModuleID, 17, (newSize), false);
913     utRecordResize(utModuleID, 19, (utAllocatedSymArray()), true);
914     utResizeArray(utSymArrays.UsedSym, (newSize));
915     utRecordResize(utModuleID, 19, (newSize), false);
916     utRecordResize(utModuleID, 20, (utAllocatedSymArray()), true);
917     utResizeArray(utSymArrays.FreeList, (newSize));
918     utRecordResize(utModuleID, 20, (newSize), false);
919     utSetAllocatedSymArray(newSize);
920 }
921 
922 /*----------------------------------------------------------------------------------------
923   Allocate more SymArrays.
924 ----------------------------------------------------------------------------------------*/
utSymArrayAllocMore(void)925 void utSymArrayAllocMore(void)
926 {
927     reallocSymArrays((uint32)(utAllocatedSymArray() + (utAllocatedSymArray() >> 1)));
928 }
929 
930 /*----------------------------------------------------------------------------------------
931   Compact the SymArray.Sym heap to free memory.
932 ----------------------------------------------------------------------------------------*/
utCompactSymArraySyms(void)933 void utCompactSymArraySyms(void)
934 {
935     uint32 elementSize = sizeof(utSym);
936     uint32 usedHeaderSize = (sizeof(utSymArray) + elementSize - 1)/elementSize;
937     uint32 freeHeaderSize = (sizeof(utSymArray) + sizeof(uint32) + elementSize - 1)/elementSize;
938     utSym *toPtr = utSymArrays.Sym;
939     utSym *fromPtr = toPtr;
940     utSymArray SymArray;
941     uint32 size;
942 
943     while(fromPtr < utSymArrays.Sym + utUsedSymArraySym()) {
944         SymArray = *(utSymArray *)(void *)fromPtr;
945         if(SymArray != utSymArrayNull) {
946             /* Need to move it to toPtr */
947             size = utMax(utSymArrayGetNumSym(SymArray) + usedHeaderSize, freeHeaderSize);
948             utRecordArray(utModuleID, 18, toPtr - utSymArrays.Sym, size, true);
949             memmove((void *)toPtr, (void *)fromPtr, size*elementSize);
950             utRecordArray(utModuleID, 18, toPtr - utSymArrays.Sym, size, false);
951             utSymArraySetSymIndex(SymArray, toPtr - utSymArrays.Sym + usedHeaderSize);
952             toPtr += size;
953         } else {
954             /* Just skip it */
955             size = *(uint32 *)(void *)(((utSymArray *)(void *)fromPtr) + 1);
956         }
957         fromPtr += size;
958     }
959     utSetUsedSymArraySym(toPtr - utSymArrays.Sym);
960     utSetFreeSymArraySym(0);
961 }
962 
963 /*----------------------------------------------------------------------------------------
964   Allocate more memory for the SymArray.Sym heap.
965 ----------------------------------------------------------------------------------------*/
allocMoreSymArraySyms(uint32 spaceNeeded)966 static void allocMoreSymArraySyms(
967     uint32 spaceNeeded)
968 {
969     uint32 freeSpace = utAllocatedSymArraySym() - utUsedSymArraySym();
970 
971     if((utFreeSymArraySym() << 2) > utUsedSymArraySym()) {
972         utCompactSymArraySyms();
973         freeSpace = utAllocatedSymArraySym() - utUsedSymArraySym();
974     }
975     if(freeSpace < spaceNeeded) {
976         utRecordResize(utModuleID, 18, utAllocatedSymArraySym(), true);
977         utSetAllocatedSymArraySym(utAllocatedSymArraySym() + spaceNeeded - freeSpace +
978             (utAllocatedSymArraySym() >> 1));
979         utResizeArray(utSymArrays.Sym, utAllocatedSymArraySym());
980         utRecordResize(utModuleID, 18, utAllocatedSymArraySym(), false);
981     }
982 }
983 
984 /*----------------------------------------------------------------------------------------
985   Allocate memory for a new SymArray.Sym array.
986 ----------------------------------------------------------------------------------------*/
utSymArrayAllocSyms(utSymArray SymArray,uint32 numSyms)987 void utSymArrayAllocSyms(
988     utSymArray SymArray,
989     uint32 numSyms)
990 {
991     uint32 freeSpace = utAllocatedSymArraySym() - utUsedSymArraySym();
992     uint32 elementSize = sizeof(utSym);
993     uint32 usedHeaderSize = (sizeof(utSymArray) + elementSize - 1)/elementSize;
994     uint32 freeHeaderSize = (sizeof(utSymArray) + sizeof(uint32) + elementSize - 1)/elementSize;
995     uint32 spaceNeeded = utMax(numSyms + usedHeaderSize, freeHeaderSize);
996 
997 #if defined(DD_DEBUG)
998     utAssert(utSymArrayGetNumSym(SymArray) == 0);
999 #endif
1000     if(numSyms == 0) {
1001         return;
1002     }
1003     if(freeSpace < spaceNeeded) {
1004         allocMoreSymArraySyms(spaceNeeded);
1005     }
1006     utSymArraySetSymIndex(SymArray, utUsedSymArraySym() + usedHeaderSize);
1007     utSymArraySetNumSym(SymArray, numSyms);
1008     utRecordArray(utModuleID, 18, utUsedSymArraySym(), numSyms + usedHeaderSize, true);
1009     *(utSymArray *)(void *)(utSymArrays.Sym + utUsedSymArraySym()) = SymArray;
1010     {
1011         uint32 xSymArray;
1012         for(xSymArray = (uint32)(utSymArrayGetSymIndex(SymArray)); xSymArray < utSymArrayGetSymIndex(SymArray) + numSyms; xSymArray++) {
1013             utSymArrays.Sym[xSymArray] = utSymNull;
1014         }
1015     }
1016     utRecordArray(utModuleID, 18, utUsedSymArraySym(), numSyms + usedHeaderSize, false);
1017     utSetUsedSymArraySym(utUsedSymArraySym() + spaceNeeded);
1018 }
1019 
1020 /*----------------------------------------------------------------------------------------
1021   Wrapper around utSymArrayGetSyms for the database manager.
1022 ----------------------------------------------------------------------------------------*/
getSymArraySyms(uint64 objectNumber,uint32 * numValues)1023 static void *getSymArraySyms(
1024     uint64 objectNumber,
1025     uint32 *numValues)
1026 {
1027     utSymArray SymArray = utIndex2SymArray((uint32)objectNumber);
1028 
1029     *numValues = utSymArrayGetNumSym(SymArray);
1030     return utSymArrayGetSyms(SymArray);
1031 }
1032 
1033 /*----------------------------------------------------------------------------------------
1034   Wrapper around utSymArrayAllocSyms for the database manager.
1035 ----------------------------------------------------------------------------------------*/
allocSymArraySyms(uint64 objectNumber,uint32 numValues)1036 static void *allocSymArraySyms(
1037     uint64 objectNumber,
1038     uint32 numValues)
1039 {
1040     utSymArray SymArray = utIndex2SymArray((uint32)objectNumber);
1041 
1042     utSymArraySetSymIndex(SymArray, 0);
1043     utSymArraySetNumSym(SymArray, 0);
1044     if(numValues == 0) {
1045         return NULL;
1046     }
1047     utSymArrayAllocSyms(SymArray, numValues);
1048     return utSymArrayGetSyms(SymArray);
1049 }
1050 
1051 /*----------------------------------------------------------------------------------------
1052   Free memory used by the SymArray.Sym array.
1053 ----------------------------------------------------------------------------------------*/
utSymArrayFreeSyms(utSymArray SymArray)1054 void utSymArrayFreeSyms(
1055     utSymArray SymArray)
1056 {
1057     uint32 elementSize = sizeof(utSym);
1058     uint32 usedHeaderSize = (sizeof(utSymArray) + elementSize - 1)/elementSize;
1059     uint32 freeHeaderSize = (sizeof(utSymArray) + sizeof(uint32) + elementSize - 1)/elementSize;
1060     uint32 size = utMax(utSymArrayGetNumSym(SymArray) + usedHeaderSize, freeHeaderSize);
1061     utSym *dataPtr = utSymArrayGetSyms(SymArray) - usedHeaderSize;
1062 
1063     if(utSymArrayGetNumSym(SymArray) == 0) {
1064         return;
1065     }
1066     utRecordArray(utModuleID, 18, dataPtr - utSymArrays.Sym, freeHeaderSize, true);
1067     *(utSymArray *)(void *)(dataPtr) = utSymArrayNull;
1068     *(uint32 *)(void *)(((utSymArray *)(void *)dataPtr) + 1) = size;
1069     utRecordArray(utModuleID, 18, dataPtr - utSymArrays.Sym, freeHeaderSize, false);
1070     utSymArraySetNumSym(SymArray, 0);
1071     utSetFreeSymArraySym(utFreeSymArraySym() + size);
1072 }
1073 
1074 /*----------------------------------------------------------------------------------------
1075   Resize the SymArray.Sym array.
1076 ----------------------------------------------------------------------------------------*/
utSymArrayResizeSyms(utSymArray SymArray,uint32 numSyms)1077 void utSymArrayResizeSyms(
1078     utSymArray SymArray,
1079     uint32 numSyms)
1080 {
1081     uint32 freeSpace;
1082     uint32 elementSize = sizeof(utSym);
1083     uint32 usedHeaderSize = (sizeof(utSymArray) + elementSize - 1)/elementSize;
1084     uint32 freeHeaderSize = (sizeof(utSymArray) + sizeof(uint32) + elementSize - 1)/elementSize;
1085     uint32 newSize = utMax(numSyms + usedHeaderSize, freeHeaderSize);
1086     uint32 oldSize = utMax(utSymArrayGetNumSym(SymArray) + usedHeaderSize, freeHeaderSize);
1087     utSym *dataPtr;
1088 
1089     if(numSyms == 0) {
1090         if(utSymArrayGetNumSym(SymArray) != 0) {
1091             utSymArrayFreeSyms(SymArray);
1092         }
1093         return;
1094     }
1095     if(utSymArrayGetNumSym(SymArray) == 0) {
1096         utSymArrayAllocSyms(SymArray, numSyms);
1097         return;
1098     }
1099     freeSpace = utAllocatedSymArraySym() - utUsedSymArraySym();
1100     if(freeSpace < newSize) {
1101         allocMoreSymArraySyms(newSize);
1102     }
1103     dataPtr = utSymArrayGetSyms(SymArray) - usedHeaderSize;
1104     utRecordArray(utModuleID, 18, utUsedSymArraySym(), newSize, true);
1105     utRecordArray(utModuleID, 18, dataPtr - utSymArrays.Sym, freeHeaderSize, true);
1106     memcpy((void *)(utSymArrays.Sym + utUsedSymArraySym()), dataPtr,
1107         elementSize*utMin(oldSize, newSize));
1108     if(newSize > oldSize) {
1109         {
1110             uint32 xSymArray;
1111             for(xSymArray = (uint32)(utUsedSymArraySym() + oldSize); xSymArray < utUsedSymArraySym() + oldSize + newSize - oldSize; xSymArray++) {
1112                 utSymArrays.Sym[xSymArray] = utSymNull;
1113             }
1114         }
1115     }
1116     *(utSymArray *)(void *)dataPtr = utSymArrayNull;
1117     *(uint32 *)(void *)(((utSymArray *)(void *)dataPtr) + 1) = oldSize;
1118     utRecordArray(utModuleID, 18, utUsedSymArraySym(), newSize, false);
1119     utRecordArray(utModuleID, 18, dataPtr - utSymArrays.Sym, freeHeaderSize, false);
1120     utSetFreeSymArraySym(utFreeSymArraySym() + oldSize);
1121     utSymArraySetSymIndex(SymArray, utUsedSymArraySym() + usedHeaderSize);
1122     utSymArraySetNumSym(SymArray, numSyms);
1123     utSetUsedSymArraySym(utUsedSymArraySym() + newSize);
1124 }
1125 
1126 /*----------------------------------------------------------------------------------------
1127   Copy the properties of SymArray.
1128 ----------------------------------------------------------------------------------------*/
utSymArrayCopyProps(utSymArray oldSymArray,utSymArray newSymArray)1129 void utSymArrayCopyProps(
1130     utSymArray oldSymArray,
1131     utSymArray newSymArray)
1132 {
1133 }
1134 
1135 /*----------------------------------------------------------------------------------------
1136   Add the indexed Sym to the SymArray.
1137 ----------------------------------------------------------------------------------------*/
utSymArrayInsertSym(utSymArray SymArray,uint32 x,utSym _Sym)1138 void utSymArrayInsertSym(
1139     utSymArray SymArray,
1140     uint32 x,
1141     utSym _Sym)
1142 {
1143 #if defined(DD_DEBUG)
1144     if(SymArray == utSymArrayNull) {
1145         utExit("Non existent SymArray");
1146     }
1147 #endif
1148     utSymArraySetiSym(SymArray, x, _Sym);
1149     utSymArraySetUsedSym(SymArray, utMax(utSymArrayGetUsedSym(SymArray), x + 1));
1150 }
1151 
1152 /*----------------------------------------------------------------------------------------
1153   Add the Sym to the end of the SymArraySym array.
1154 ----------------------------------------------------------------------------------------*/
utSymArrayAppendSym(utSymArray SymArray,utSym _Sym)1155 void utSymArrayAppendSym(
1156     utSymArray SymArray,
1157     utSym _Sym)
1158 {
1159     uint32 usedSym = utSymArrayGetUsedSym(SymArray);
1160 
1161 #if defined(DD_DEBUG)
1162     if(SymArray == utSymArrayNull) {
1163         utExit("Non existent SymArray");
1164     }
1165 #endif
1166     if(usedSym >= utSymArrayGetNumSym(SymArray)) {
1167         utSymArrayResizeSyms(SymArray, usedSym + (usedSym << 1) + 1);
1168     }
1169     utSymArraySetiSym(SymArray, usedSym, _Sym);
1170     utSymArraySetUsedSym(SymArray, usedSym + 1);
1171 }
1172 
1173 #if defined(DD_DEBUG)
1174 /*----------------------------------------------------------------------------------------
1175   Write out all the fields of an object.
1176 ----------------------------------------------------------------------------------------*/
utShowSymArray(utSymArray SymArray)1177 void utShowSymArray(
1178     utSymArray SymArray)
1179 {
1180     utDatabaseShowObject("ut", "SymArray", utSymArray2Index(SymArray));
1181 }
1182 #endif
1183 
1184 /*----------------------------------------------------------------------------------------
1185   Free memory used by the ut database.
1186 ----------------------------------------------------------------------------------------*/
utDatabaseStop(void)1187 void utDatabaseStop(void)
1188 {
1189     utFree(utSymtabs.TableIndex);
1190     utFree(utSymtabs.NumTable);
1191     utFree(utSymtabs.Table);
1192     utFree(utSymtabs.NumSym);
1193     utFree(utSyms.NameIndex);
1194     utFree(utSyms.NumName);
1195     utFree(utSyms.Name);
1196     utFree(utSyms.HashValue);
1197     utFree(utSyms.Next);
1198     utFree(utDynarrays.ValueIndex);
1199     utFree(utDynarrays.NumValue);
1200     utFree(utDynarrays.Value);
1201     utFree(utDynarrays.ValueSize);
1202     utFree(utDynarrays.UsedValue);
1203     utFree(utDynarrays.Size);
1204     utFree(utDynarrays.FreeList);
1205     utFree(utSymArrays.SymIndex);
1206     utFree(utSymArrays.NumSym);
1207     utFree(utSymArrays.Sym);
1208     utFree(utSymArrays.UsedSym);
1209     utFree(utSymArrays.FreeList);
1210     utUnregisterModule(utModuleID);
1211 }
1212 
1213 /*----------------------------------------------------------------------------------------
1214   Allocate memory used by the ut database.
1215 ----------------------------------------------------------------------------------------*/
utDatabaseStart(void)1216 void utDatabaseStart(void)
1217 {
1218     if(!utInitialized()) {
1219         utStart();
1220     }
1221     utRootData.hash = 0x36c29ca6;
1222     utModuleID = utRegisterModule("ut", false, utHash(), 4, 21, 1, sizeof(struct utRootType_),
1223         &utRootData, utDatabaseStart, utDatabaseStop);
1224     utRegisterEnum("FieldType", 12);
1225     utRegisterEntry("UT_BIT", 0);
1226     utRegisterEntry("UT_BOOL", 1);
1227     utRegisterEntry("UT_INT", 2);
1228     utRegisterEntry("UT_UINT", 3);
1229     utRegisterEntry("UT_CHAR", 4);
1230     utRegisterEntry("UT_FLOAT", 5);
1231     utRegisterEntry("UT_DOUBLE", 6);
1232     utRegisterEntry("UT_POINTER", 7);
1233     utRegisterEntry("UT_TYPEDEF", 8);
1234     utRegisterEntry("UT_ENUM", 9);
1235     utRegisterEntry("UT_SYM", 10);
1236     utRegisterEntry("UT_UNION", 11);
1237     utRegisterClass("Symtab", 4, &utRootData.usedSymtab, &utRootData.allocatedSymtab,
1238         NULL, 65535, 4, allocSymtab, NULL);
1239     utRegisterField("TableIndex", &utSymtabs.TableIndex, sizeof(uint32), UT_UINT, NULL);
1240     utSetFieldHidden();
1241     utRegisterField("NumTable", &utSymtabs.NumTable, sizeof(uint32), UT_UINT, NULL);
1242     utSetFieldHidden();
1243     utRegisterField("Table", &utSymtabs.Table, sizeof(utSym), UT_SYM, NULL);
1244     utRegisterArray(&utRootData.usedSymtabTable, &utRootData.allocatedSymtabTable,
1245         getSymtabTables, allocSymtabTables, utCompactSymtabTables);
1246     utRegisterField("NumSym", &utSymtabs.NumSym, sizeof(uint32), UT_UINT, NULL);
1247     utRegisterClass("Sym", 5, &utRootData.usedSym, &utRootData.allocatedSym,
1248         NULL, 65535, 4, allocSym, NULL);
1249     utRegisterField("NameIndex", &utSyms.NameIndex, sizeof(uint32), UT_UINT, NULL);
1250     utSetFieldHidden();
1251     utRegisterField("NumName", &utSyms.NumName, sizeof(uint32), UT_UINT, NULL);
1252     utSetFieldHidden();
1253     utRegisterField("Name", &utSyms.Name, sizeof(char), UT_CHAR, NULL);
1254     utRegisterArray(&utRootData.usedSymName, &utRootData.allocatedSymName,
1255         getSymNames, allocSymNames, utCompactSymNames);
1256     utRegisterField("HashValue", &utSyms.HashValue, sizeof(uint32), UT_UINT, NULL);
1257     utRegisterField("Next", &utSyms.Next, sizeof(utSym), UT_POINTER, "Sym");
1258     utRegisterClass("Dynarray", 7, &utRootData.usedDynarray, &utRootData.allocatedDynarray,
1259         &utRootData.firstFreeDynarray, 15, 4, allocDynarray, destroyDynarray);
1260     utRegisterField("ValueIndex", &utDynarrays.ValueIndex, sizeof(uint32), UT_UINT, NULL);
1261     utSetFieldHidden();
1262     utRegisterField("NumValue", &utDynarrays.NumValue, sizeof(uint32), UT_UINT, NULL);
1263     utSetFieldHidden();
1264     utRegisterField("Value", &utDynarrays.Value, sizeof(uint8), UT_UINT, NULL);
1265     utRegisterArray(&utRootData.usedDynarrayValue, &utRootData.allocatedDynarrayValue,
1266         getDynarrayValues, allocDynarrayValues, utCompactDynarrayValues);
1267     utRegisterField("ValueSize", &utDynarrays.ValueSize, sizeof(uint16), UT_UINT, NULL);
1268     utRegisterField("UsedValue", &utDynarrays.UsedValue, sizeof(uint32), UT_UINT, NULL);
1269     utRegisterField("Size", &utDynarrays.Size, sizeof(uint32), UT_UINT, NULL);
1270     utRegisterField("FreeList", &utDynarrays.FreeList, sizeof(utDynarray), UT_POINTER, "Dynarray");
1271     utSetFieldHidden();
1272     utRegisterClass("SymArray", 5, &utRootData.usedSymArray, &utRootData.allocatedSymArray,
1273         &utRootData.firstFreeSymArray, 20, 4, allocSymArray, destroySymArray);
1274     utRegisterField("SymIndex", &utSymArrays.SymIndex, sizeof(uint32), UT_UINT, NULL);
1275     utSetFieldHidden();
1276     utRegisterField("NumSym", &utSymArrays.NumSym, sizeof(uint32), UT_UINT, NULL);
1277     utSetFieldHidden();
1278     utRegisterField("Sym", &utSymArrays.Sym, sizeof(utSym), UT_POINTER, "Sym");
1279     utRegisterArray(&utRootData.usedSymArraySym, &utRootData.allocatedSymArraySym,
1280         getSymArraySyms, allocSymArraySyms, utCompactSymArraySyms);
1281     utRegisterField("UsedSym", &utSymArrays.UsedSym, sizeof(uint32), UT_UINT, NULL);
1282     utRegisterField("FreeList", &utSymArrays.FreeList, sizeof(utSymArray), UT_POINTER, "SymArray");
1283     utSetFieldHidden();
1284     allocSymtabs();
1285     allocSyms();
1286     allocDynarrays();
1287     allocSymArrays();
1288 }
1289 
1290 #if defined(DD_DEBUG)
1291 #undef utSymtabGetTableIndex
utSymtabGetTableIndex(utSymtab _Symtab)1292 uint32 utSymtabGetTableIndex(
1293     utSymtab _Symtab)
1294 {
1295     return utSymtabs.TableIndex[utSymtab2Index(_Symtab)];
1296 }
1297 
1298 #undef utSymtabSetTableIndex
utSymtabSetTableIndex(utSymtab _Symtab,uint32 value)1299 void utSymtabSetTableIndex(
1300     utSymtab _Symtab,
1301     uint32 value)
1302 {
1303     utSymtabs.TableIndex[utSymtab2Index(_Symtab)] = value;
1304 }
1305 
1306 #undef utSymtabGetNumTable
utSymtabGetNumTable(utSymtab _Symtab)1307 uint32 utSymtabGetNumTable(
1308     utSymtab _Symtab)
1309 {
1310     return utSymtabs.NumTable[utSymtab2Index(_Symtab)];
1311 }
1312 
1313 #undef utSymtabSetNumTable
utSymtabSetNumTable(utSymtab _Symtab,uint32 value)1314 void utSymtabSetNumTable(
1315     utSymtab _Symtab,
1316     uint32 value)
1317 {
1318     utSymtabs.NumTable[utSymtab2Index(_Symtab)] = value;
1319 }
1320 
1321 #undef utSymtabGetiTable
utSymtabGetiTable(utSymtab _Symtab,uint32 x)1322 utSym utSymtabGetiTable(
1323     utSymtab _Symtab,
1324     uint32 x)
1325 {
1326     return (utSymtabs.Table)[utSymtabGetTableIndex(_Symtab) + x];
1327 }
1328 
1329 #undef utSymtabSetiTable
utSymtabSetiTable(utSymtab Symtab,uint32 x,utSym value)1330 void utSymtabSetiTable(
1331     utSymtab Symtab,
1332     uint32 x,
1333     utSym value)
1334 {
1335     utSymtabs.Table[utSymtabGetTableIndex(Symtab) + x] = value;
1336 }
1337 
1338 #undef utSymtabGetTable
utSymtabGetTable(utSymtab Symtab)1339 utSym *utSymtabGetTable(
1340     utSymtab Symtab)
1341 {
1342     return utSymtabs.Table + utSymtabGetTableIndex(Symtab);
1343 }
1344 
1345 #undef utSymtabGetNumSym
utSymtabGetNumSym(utSymtab _Symtab)1346 uint32 utSymtabGetNumSym(
1347     utSymtab _Symtab)
1348 {
1349     return utSymtabs.NumSym[utSymtab2Index(_Symtab)];
1350 }
1351 
1352 #undef utSymtabSetNumSym
utSymtabSetNumSym(utSymtab _Symtab,uint32 value)1353 void utSymtabSetNumSym(
1354     utSymtab _Symtab,
1355     uint32 value)
1356 {
1357     utSymtabs.NumSym[utSymtab2Index(_Symtab)] = value;
1358 }
1359 
1360 #undef utSymGetNameIndex
utSymGetNameIndex(utSym _Sym)1361 uint32 utSymGetNameIndex(
1362     utSym _Sym)
1363 {
1364     return utSyms.NameIndex[utSym2Index(_Sym)];
1365 }
1366 
1367 #undef utSymSetNameIndex
utSymSetNameIndex(utSym _Sym,uint32 value)1368 void utSymSetNameIndex(
1369     utSym _Sym,
1370     uint32 value)
1371 {
1372     utSyms.NameIndex[utSym2Index(_Sym)] = value;
1373 }
1374 
1375 #undef utSymGetNumName
utSymGetNumName(utSym _Sym)1376 uint32 utSymGetNumName(
1377     utSym _Sym)
1378 {
1379     return utSyms.NumName[utSym2Index(_Sym)];
1380 }
1381 
1382 #undef utSymSetNumName
utSymSetNumName(utSym _Sym,uint32 value)1383 void utSymSetNumName(
1384     utSym _Sym,
1385     uint32 value)
1386 {
1387     utSyms.NumName[utSym2Index(_Sym)] = value;
1388 }
1389 
1390 #undef utSymGetiName
utSymGetiName(utSym _Sym,uint32 x)1391 char utSymGetiName(
1392     utSym _Sym,
1393     uint32 x)
1394 {
1395     return (utSyms.Name)[utSymGetNameIndex(_Sym) + x];
1396 }
1397 
1398 #undef utSymSetiName
utSymSetiName(utSym Sym,uint32 x,char value)1399 void utSymSetiName(
1400     utSym Sym,
1401     uint32 x,
1402     char value)
1403 {
1404     utSyms.Name[utSymGetNameIndex(Sym) + x] = value;
1405 }
1406 
1407 #undef utSymGetName
utSymGetName(utSym Sym)1408 char *utSymGetName(
1409     utSym Sym)
1410 {
1411     return utSyms.Name + utSymGetNameIndex(Sym);
1412 }
1413 
1414 #undef utSymGetHashValue
utSymGetHashValue(utSym _Sym)1415 uint32 utSymGetHashValue(
1416     utSym _Sym)
1417 {
1418     return utSyms.HashValue[utSym2Index(_Sym)];
1419 }
1420 
1421 #undef utSymSetHashValue
utSymSetHashValue(utSym _Sym,uint32 value)1422 void utSymSetHashValue(
1423     utSym _Sym,
1424     uint32 value)
1425 {
1426     utSyms.HashValue[utSym2Index(_Sym)] = value;
1427 }
1428 
1429 #undef utSymGetNext
utSymGetNext(utSym _Sym)1430 utSym utSymGetNext(
1431     utSym _Sym)
1432 {
1433     return utSyms.Next[utSym2Index(_Sym)];
1434 }
1435 
1436 #undef utSymSetNext
utSymSetNext(utSym _Sym,utSym value)1437 void utSymSetNext(
1438     utSym _Sym,
1439     utSym value)
1440 {
1441     utSyms.Next[utSym2Index(_Sym)] = value;
1442 }
1443 
1444 #undef utDynarrayGetValueIndex
utDynarrayGetValueIndex(utDynarray _Dynarray)1445 uint32 utDynarrayGetValueIndex(
1446     utDynarray _Dynarray)
1447 {
1448     return utDynarrays.ValueIndex[utDynarray2Index(_Dynarray)];
1449 }
1450 
1451 #undef utDynarraySetValueIndex
utDynarraySetValueIndex(utDynarray _Dynarray,uint32 value)1452 void utDynarraySetValueIndex(
1453     utDynarray _Dynarray,
1454     uint32 value)
1455 {
1456     utDynarrays.ValueIndex[utDynarray2Index(_Dynarray)] = value;
1457 }
1458 
1459 #undef utDynarrayGetNumValue
utDynarrayGetNumValue(utDynarray _Dynarray)1460 uint32 utDynarrayGetNumValue(
1461     utDynarray _Dynarray)
1462 {
1463     return utDynarrays.NumValue[utDynarray2Index(_Dynarray)];
1464 }
1465 
1466 #undef utDynarraySetNumValue
utDynarraySetNumValue(utDynarray _Dynarray,uint32 value)1467 void utDynarraySetNumValue(
1468     utDynarray _Dynarray,
1469     uint32 value)
1470 {
1471     utDynarrays.NumValue[utDynarray2Index(_Dynarray)] = value;
1472 }
1473 
1474 #undef utDynarrayGetiValue
utDynarrayGetiValue(utDynarray _Dynarray,uint32 x)1475 uint8 utDynarrayGetiValue(
1476     utDynarray _Dynarray,
1477     uint32 x)
1478 {
1479     return (utDynarrays.Value)[utDynarrayGetValueIndex(_Dynarray) + x];
1480 }
1481 
1482 #undef utDynarraySetiValue
utDynarraySetiValue(utDynarray Dynarray,uint32 x,uint8 value)1483 void utDynarraySetiValue(
1484     utDynarray Dynarray,
1485     uint32 x,
1486     uint8 value)
1487 {
1488     utDynarrays.Value[utDynarrayGetValueIndex(Dynarray) + x] = value;
1489 }
1490 
1491 #undef utDynarrayGetValue
utDynarrayGetValue(utDynarray Dynarray)1492 uint8 *utDynarrayGetValue(
1493     utDynarray Dynarray)
1494 {
1495     return utDynarrays.Value + utDynarrayGetValueIndex(Dynarray);
1496 }
1497 
1498 #undef utDynarrayGetValueSize
utDynarrayGetValueSize(utDynarray _Dynarray)1499 uint16 utDynarrayGetValueSize(
1500     utDynarray _Dynarray)
1501 {
1502     return utDynarrays.ValueSize[utDynarray2Index(_Dynarray)];
1503 }
1504 
1505 #undef utDynarraySetValueSize
utDynarraySetValueSize(utDynarray _Dynarray,uint16 value)1506 void utDynarraySetValueSize(
1507     utDynarray _Dynarray,
1508     uint16 value)
1509 {
1510     utDynarrays.ValueSize[utDynarray2Index(_Dynarray)] = value;
1511 }
1512 
1513 #undef utDynarrayGetUsedValue
utDynarrayGetUsedValue(utDynarray _Dynarray)1514 uint32 utDynarrayGetUsedValue(
1515     utDynarray _Dynarray)
1516 {
1517     return utDynarrays.UsedValue[utDynarray2Index(_Dynarray)];
1518 }
1519 
1520 #undef utDynarraySetUsedValue
utDynarraySetUsedValue(utDynarray _Dynarray,uint32 value)1521 void utDynarraySetUsedValue(
1522     utDynarray _Dynarray,
1523     uint32 value)
1524 {
1525     utDynarrays.UsedValue[utDynarray2Index(_Dynarray)] = value;
1526 }
1527 
1528 #undef utDynarrayGetSize
utDynarrayGetSize(utDynarray _Dynarray)1529 uint32 utDynarrayGetSize(
1530     utDynarray _Dynarray)
1531 {
1532     return utDynarrays.Size[utDynarray2Index(_Dynarray)];
1533 }
1534 
1535 #undef utDynarraySetSize
utDynarraySetSize(utDynarray _Dynarray,uint32 value)1536 void utDynarraySetSize(
1537     utDynarray _Dynarray,
1538     uint32 value)
1539 {
1540     utDynarrays.Size[utDynarray2Index(_Dynarray)] = value;
1541 }
1542 
1543 #undef utDynarrayGetFreeList
utDynarrayGetFreeList(utDynarray _Dynarray)1544 utDynarray utDynarrayGetFreeList(
1545     utDynarray _Dynarray)
1546 {
1547     return utDynarrays.FreeList[utDynarray2Index(_Dynarray)];
1548 }
1549 
1550 #undef utDynarraySetFreeList
utDynarraySetFreeList(utDynarray _Dynarray,utDynarray value)1551 void utDynarraySetFreeList(
1552     utDynarray _Dynarray,
1553     utDynarray value)
1554 {
1555     utDynarrays.FreeList[utDynarray2Index(_Dynarray)] = value;
1556 }
1557 
1558 #undef utSymArrayGetSymIndex
utSymArrayGetSymIndex(utSymArray _SymArray)1559 uint32 utSymArrayGetSymIndex(
1560     utSymArray _SymArray)
1561 {
1562     return utSymArrays.SymIndex[utSymArray2Index(_SymArray)];
1563 }
1564 
1565 #undef utSymArraySetSymIndex
utSymArraySetSymIndex(utSymArray _SymArray,uint32 value)1566 void utSymArraySetSymIndex(
1567     utSymArray _SymArray,
1568     uint32 value)
1569 {
1570     utSymArrays.SymIndex[utSymArray2Index(_SymArray)] = value;
1571 }
1572 
1573 #undef utSymArrayGetNumSym
utSymArrayGetNumSym(utSymArray _SymArray)1574 uint32 utSymArrayGetNumSym(
1575     utSymArray _SymArray)
1576 {
1577     return utSymArrays.NumSym[utSymArray2Index(_SymArray)];
1578 }
1579 
1580 #undef utSymArraySetNumSym
utSymArraySetNumSym(utSymArray _SymArray,uint32 value)1581 void utSymArraySetNumSym(
1582     utSymArray _SymArray,
1583     uint32 value)
1584 {
1585     utSymArrays.NumSym[utSymArray2Index(_SymArray)] = value;
1586 }
1587 
1588 #undef utSymArrayGetiSym
utSymArrayGetiSym(utSymArray _SymArray,uint32 x)1589 utSym utSymArrayGetiSym(
1590     utSymArray _SymArray,
1591     uint32 x)
1592 {
1593     return (utSymArrays.Sym)[utSymArrayGetSymIndex(_SymArray) + x];
1594 }
1595 
1596 #undef utSymArraySetiSym
utSymArraySetiSym(utSymArray SymArray,uint32 x,utSym value)1597 void utSymArraySetiSym(
1598     utSymArray SymArray,
1599     uint32 x,
1600     utSym value)
1601 {
1602     utSymArrays.Sym[utSymArrayGetSymIndex(SymArray) + x] = value;
1603 }
1604 
1605 #undef utSymArrayGetSym
utSymArrayGetSym(utSymArray SymArray)1606 utSym *utSymArrayGetSym(
1607     utSymArray SymArray)
1608 {
1609     return utSymArrays.Sym + utSymArrayGetSymIndex(SymArray);
1610 }
1611 
1612 #undef utSymArrayGetUsedSym
utSymArrayGetUsedSym(utSymArray _SymArray)1613 uint32 utSymArrayGetUsedSym(
1614     utSymArray _SymArray)
1615 {
1616     return utSymArrays.UsedSym[utSymArray2Index(_SymArray)];
1617 }
1618 
1619 #undef utSymArraySetUsedSym
utSymArraySetUsedSym(utSymArray _SymArray,uint32 value)1620 void utSymArraySetUsedSym(
1621     utSymArray _SymArray,
1622     uint32 value)
1623 {
1624     utSymArrays.UsedSym[utSymArray2Index(_SymArray)] = value;
1625 }
1626 
1627 #undef utSymArrayGetFreeList
utSymArrayGetFreeList(utSymArray _SymArray)1628 utSymArray utSymArrayGetFreeList(
1629     utSymArray _SymArray)
1630 {
1631     return utSymArrays.FreeList[utSymArray2Index(_SymArray)];
1632 }
1633 
1634 #undef utSymArraySetFreeList
utSymArraySetFreeList(utSymArray _SymArray,utSymArray value)1635 void utSymArraySetFreeList(
1636     utSymArray _SymArray,
1637     utSymArray value)
1638 {
1639     utSymArrays.FreeList[utSymArray2Index(_SymArray)] = value;
1640 }
1641 
1642 #endif
1643