source:
src/examples/gc_no_raii/test/badlll.c
@
f9cebb5
Last change on this file since f9cebb5 was 85951a6, checked in by , 8 years ago | |
---|---|
|
|
File size: 735 bytes |
Rev | Line | |
---|---|---|
[9421588a] | 1 | #include "gc.h" |
2 | ||
3 | struct List_t | |
4 | { | |
5 | gcpointer(List_t) next; | |
6 | int val; | |
7 | }; | |
[f1e42c1] | 8 | |
9 | typedef gcpointer(List_t) LLL; | |
10 | ||
11 | #define MAX (1024 * 1024) | |
12 | ||
13 | LLL buildLLL(int sz) | |
14 | { | |
15 | int i; | |
16 | LLL ll0, lll, llc; | |
17 | ||
18 | ll0 = gcmalloc(); | |
19 | ll0->val = 0; | |
20 | lll = ll0; | |
21 | ||
[bf5a70da] | 22 | for (i = 1; i < sz; i++) |
23 | { | |
[85951a6] | 24 | llc = gcmalloc(); |
[bf5a70da] | 25 | llc->val = i; |
26 | lll->next = llc; | |
27 | lll = llc; | |
28 | } | |
29 | ||
[f1e42c1] | 30 | return ll0; |
31 | } | |
[bf5a70da] | 32 | |
33 | void testLLL(LLL lll) | |
34 | { | |
35 | unsigned char *counted; | |
36 | ||
37 | counted = (unsigned char *) calloc(MAX, sizeof(unsigned char)); | |
38 | while (lll) | |
39 | { | |
40 | counted[lll->val]++; | |
41 | if (counted[lll->val] > 1) | |
42 | { | |
43 | fprintf(stderr, "ERROR! Encountered %d twice!\n", lll->val); | |
44 | exit(1); | |
45 | } | |
46 | lll = lll->next; | |
47 | } | |
48 | ||
49 | return; | |
50 | } | |
51 | ||
52 | int main(void) | |
53 | { | |
54 | LLL mylll; | |
55 | ||
56 | mylll = buildLLL(MAX); | |
57 | ||
58 | testLLL(mylll); | |
59 | ||
60 | return 0; | |
61 | } |
Note: See TracBrowser
for help on using the repository browser.