summaryrefslogtreecommitdiff
path: root/tests/staticrootstest.c
blob: f0b45bb68bd822cc9412a0c993981975ab914cff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

#include <stdio.h>
#include <string.h>

#ifndef GC_DEBUG
# define GC_DEBUG
#endif

#include "gc.h"
#include "gc_backptr.h"

#ifndef GC_VISIBILITY_HIDDEN_SET

struct treenode {
    struct treenode *x;
    struct treenode *y;
} * root[10];

static char *staticroot = 0;

extern struct treenode * libsrl_mktree(int i);
extern void * libsrl_init(void);

/*
struct treenode * mktree(int i) {
  struct treenode * r = GC_MALLOC(sizeof(struct treenode));
  if (0 == i) return 0;
  if (1 == i) r = GC_MALLOC_ATOMIC(sizeof(struct treenode));
  r -> x = mktree(i-1);
  r -> y = mktree(i-1);
  return r;
}*/

int main(void)
{
  int i;
  /*GC_INIT();
  staticroot = GC_MALLOC(sizeof(struct treenode));*/
  staticroot = libsrl_init();
  memset(staticroot, 0x42, sizeof(struct treenode));
  GC_gcollect();
  for (i = 0; i < 10; ++i) {
    root[i] = libsrl_mktree(12);
    GC_gcollect();
  }
  for (i = 0; i < (int)sizeof(struct treenode); ++i) {
    if (staticroot[i] != 0x42)
      return -1;
  }
  for (i = 0; i < 10; ++i) {
    root[i] = libsrl_mktree(12);
    GC_gcollect();
  }
  for (i = 0; i < (int)sizeof(struct treenode); ++i) {
    if (staticroot[i] != 0x42)
      return -1;
  }
  return 0;
}

#else

/* Skip since symbols defined in staticrootslib are not visible */

int main(void)
{
  printf("staticrootstest skipped\n");
  return 0;
}

#endif