source:
examples/gc_no_raii/test/badlll.c
@
97c3159
Last change on this file since 97c3159 was bf71cfd, checked in by , 6 years ago | |
---|---|
|
|
File size: 957 bytes |
Rev | Line | |
---|---|---|
[9421588a] | 1 | #include "gc.h" |
2 | ||
[46f1d20] | 3 | #include <stdio.h> |
4 | ||
[9421588a] | 5 | struct List_t |
6 | { | |
7 | gcpointer(List_t) next; | |
8 | int val; | |
9 | }; | |
[f1e42c1] | 10 | |
11 | typedef gcpointer(List_t) LLL; | |
12 | ||
[76af36f] | 13 | #define MAX (1024 * 1) |
[f1e42c1] | 14 | |
[46f1d20] | 15 | LLL buildLLL(int sz) |
16 | { | |
17 | int i = 0; | |
[76af36f] | 18 | LLL ll0; |
[46f1d20] | 19 | |
20 | gcmalloc( &ll0 ); | |
21 | List_t* ll0_ptr = get( &ll0 ); | |
22 | ll0_ptr->val = i; | |
[76af36f] | 23 | LLL lll = ll0; |
[46f1d20] | 24 | |
25 | for (i = 1; i < sz; i++) | |
26 | { | |
[76af36f] | 27 | LLL llc; |
[46f1d20] | 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 | ||
[4c1403c] | 37 | check(is_valid( &ll0.internal )); |
38 | ||
[46f1d20] | 39 | return ll0; |
40 | } | |
41 | ||
42 | void testLLL(LLL lll) | |
[f1e42c1] | 43 | { |
[46f1d20] | 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; | |
[bf5a70da] | 60 | } |
61 | ||
62 | int main(void) | |
63 | { | |
64 | LLL mylll; | |
65 | ||
[46f1d20] | 66 | mylll = buildLLL(MAX); |
67 | ||
68 | testLLL(mylll); | |
[bf5a70da] | 69 | |
70 | return 0; | |
71 | } |
Note: See TracBrowser
for help on using the repository browser.