blob: 34ce9b40be76a333d1fa05696199d920bc6aef43 (
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
|
#include <stdio.h>
#include <string.h>
#ifndef GC_DEBUG
# define GC_DEBUG
#endif
#include "gc.h"
#include "gc_backptr.h"
#ifndef GC_TEST_IMPORT_API
# define GC_TEST_IMPORT_API extern
#endif
/* Should match that in staticrootslib.c. */
struct treenode {
struct treenode *x;
struct treenode *y;
};
struct treenode *root[10] = { NULL };
/* Same as "root" variable but initialized to some non-zero value (to */
/* be placed to .data section instead of .bss). */
struct treenode *root_nz[10] = { (void *)(GC_word)1 };
static char *staticroot = 0;
GC_TEST_IMPORT_API struct treenode * libsrl_mktree(int i);
GC_TEST_IMPORT_API void * libsrl_init(void);
GC_TEST_IMPORT_API struct treenode ** libsrl_getpelem(int i, int j);
GC_TEST_IMPORT_API struct treenode ** libsrl_getpelem2(int i, int j);
int main(void)
{
int i, j;
# ifdef STATICROOTSLIB_INIT_IN_MAIN
GC_INIT();
# endif
staticroot = libsrl_init();
if (NULL == staticroot) {
fprintf(stderr, "GC_malloc returned NULL\n");
return 2;
}
memset(staticroot, 0x42, sizeof(struct treenode));
GC_gcollect();
for (j = 0; j < 4; j++) {
for (i = 0; i < (int)(sizeof(root) / sizeof(root[0])); ++i) {
# ifdef STATICROOTSLIB2
*libsrl_getpelem2(i, j) = libsrl_mktree(12);
# endif
*libsrl_getpelem(i, j) = libsrl_mktree(12);
((j & 1) != 0 ? root_nz : root)[i] = libsrl_mktree(12);
GC_gcollect();
}
for (i = 0; i < (int)sizeof(struct treenode); ++i) {
if (staticroot[i] != 0x42) {
fprintf(stderr, "Memory check failed\n");
return -1;
}
}
}
return 0;
}
|