File: staticrootslib.c

package info (click to toggle)
libgc 1%3A8.2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,128 kB
  • sloc: ansic: 40,056; sh: 4,449; cpp: 1,066; makefile: 200; asm: 77
file content (86 lines) | stat: -rw-r--r-- 1,916 bytes parent folder | download | duplicates (3)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

/* This test file is intended to be compiled into a DLL. */

#include <stdio.h>
#include <stdlib.h>

#ifndef GC_DEBUG
# define GC_DEBUG
#endif

#include "gc.h"

#ifndef GC_TEST_EXPORT_API
# if defined(GC_VISIBILITY_HIDDEN_SET) \
     && !defined(__CEGCC__) && !defined(__CYGWIN__) && !defined(__MINGW32__)
#   define GC_TEST_EXPORT_API \
                        extern __attribute__((__visibility__("default")))
# else
#   define GC_TEST_EXPORT_API extern
# endif
#endif

#define CHECK_OUT_OF_MEMORY(p) \
    do { \
        if (NULL == (p)) { \
            fprintf(stderr, "Out of memory\n"); \
            exit(69); \
        } \
    } while (0)

struct treenode {
    struct treenode *x;
    struct treenode *y;
};

static struct treenode *root[10] = { 0 };
static struct treenode *root_nz[10] = { (struct treenode *)(GC_word)2 };

#ifdef STATICROOTSLIB2
# define libsrl_getpelem libsrl_getpelem2
#else

  GC_TEST_EXPORT_API struct treenode * libsrl_mktree(int i)
  {
    struct treenode *r = GC_NEW(struct treenode);
    struct treenode *x, *y;

    CHECK_OUT_OF_MEMORY(r);
    if (0 == i)
      return 0;
    if (1 == i) {
      r = (struct treenode *)GC_MALLOC_ATOMIC(sizeof(struct treenode));
      CHECK_OUT_OF_MEMORY(r);
    }
    x = libsrl_mktree(i - 1);
    y = libsrl_mktree(i - 1);
    r -> x = x;
    r -> y = y;
    if (i != 1) {
      GC_END_STUBBORN_CHANGE(r);
      GC_reachable_here(x);
      GC_reachable_here(y);
    }
    return r;
  }

  GC_TEST_EXPORT_API void * libsrl_init(void)
  {
#   ifdef TEST_MANUAL_VDB
      GC_set_manual_vdb_allowed(1);
#   endif
#   ifndef STATICROOTSLIB_INIT_IN_MAIN
      GC_INIT();
#   endif
#   ifndef NO_INCREMENTAL
      GC_enable_incremental();
#   endif
    return GC_MALLOC(sizeof(struct treenode));
  }

#endif /* !STATICROOTSLIB2 */

GC_TEST_EXPORT_API struct treenode ** libsrl_getpelem(int i, int j)
{
  return &((j & 1) != 0 ? root_nz : root)[i];
}