vinix-ports / ports / gc / collect.c
28 lines · 26 sloc · 599 bytes · c33d8afc2906b8dd9a8b905224eccd49a44f7ad5
Raw
1#include <gc.h>
2#include <stddef.h>
3
4struct link {
5 struct link *previous;
6 size_t value;
7};
8
9int main(void)
10{
11 GC_INIT();
12 struct link *root = NULL;
13 for (size_t i = 0; i < 8192; ++i) {
14 struct link *next = GC_MALLOC(sizeof(*next));
15 if (next == NULL)
16 return 1;
17 next->previous = root;
18 next->value = i;
19 root = next;
20 }
21 GC_gcollect();
22 for (size_t count = 8192; count != 0; --count) {
23 if (root == NULL || root->value != count - 1)
24 return 2;
25 root = root->previous;
26 }
27 return root != NULL;
28}
29