source: tests/zombies/gc_no_raii/test/badlll.c @ 474d610

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 474d610 was 87b9332, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Moved 'examples/' to 'tests/zombies/'.

  • Property mode set to 100644
File size: 957 bytes
Line 
1#include "gc.h"
2
3#include <stdio.h>
4
5struct List_t
6{
7        gcpointer(List_t) next;
8        int val;
9};
10
11typedef gcpointer(List_t) LLL;
12
13#define MAX (1024 * 1)
14
15LLL 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
42void 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
62int 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.