ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since 4c1403c was
4c1403c,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
fixed small issues with gcpointers and added method to validate them
|
-
Property mode set to
100644
|
File size:
957 bytes
|
Line | |
---|
1 | #include "gc.h" |
---|
2 | |
---|
3 | #include <stdio.h> |
---|
4 | |
---|
5 | struct List_t |
---|
6 | { |
---|
7 | gcpointer(List_t) next; |
---|
8 | int val; |
---|
9 | }; |
---|
10 | |
---|
11 | typedef gcpointer(List_t) LLL; |
---|
12 | |
---|
13 | #define MAX (1024 * 1) |
---|
14 | |
---|
15 | LLL buildLLL(int sz) |
---|
16 | { |
---|
17 | int i = 0; |
---|
18 | LLL ll0; |
---|
19 | |
---|
20 | gcmalloc( &ll0 ); |
---|
21 | List_t* ll0_ptr = get( &ll0 ); |
---|
22 | ll0_ptr->val = i; |
---|
23 | LLL lll = ll0; |
---|
24 | |
---|
25 | for (i = 1; i < sz; i++) |
---|
26 | { |
---|
27 | LLL llc; |
---|
28 | gcmalloc( &llc ); |
---|
29 | List_t* llc_ptr = get( &llc ); |
---|
30 | llc_ptr->val = i; |
---|
31 | List_t* lll_ptr = get( &lll ); |
---|
32 | lll_ptr->next = llc; |
---|
33 | |
---|
34 | lll = llc; |
---|
35 | } |
---|
36 | |
---|
37 | check(is_valid( &ll0.internal )); |
---|
38 | |
---|
39 | return ll0; |
---|
40 | } |
---|
41 | |
---|
42 | void testLLL(LLL lll) |
---|
43 | { |
---|
44 | unsigned char *counted; |
---|
45 | |
---|
46 | counted = (unsigned char *) calloc(MAX, sizeof(unsigned char)); |
---|
47 | while (lll) |
---|
48 | { |
---|
49 | List_t* lll_ptr = get( &lll ); |
---|
50 | counted[lll_ptr->val]++; |
---|
51 | if (counted[lll_ptr->val] > 1) |
---|
52 | { |
---|
53 | fprintf(stderr, "ERROR! Encountered %d twice!\n", lll_ptr->val); |
---|
54 | exit(1); |
---|
55 | } |
---|
56 | lll = lll_ptr->next; |
---|
57 | } |
---|
58 | |
---|
59 | return; |
---|
60 | } |
---|
61 | |
---|
62 | int main(void) |
---|
63 | { |
---|
64 | LLL mylll; |
---|
65 | |
---|
66 | mylll = buildLLL(MAX); |
---|
67 | |
---|
68 | testLLL(mylll); |
---|
69 | |
---|
70 | return 0; |
---|
71 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.