| 1 |
|
| 2 |
/* This test file is intended to be compiled into a DLL. */ |
| 3 |
|
| 4 |
#include <stdio.h> |
| 5 |
#include <stdlib.h> |
| 6 |
|
| 7 |
#ifndef GC_DEBUG |
| 8 |
# define GC_DEBUG |
| 9 |
#endif |
| 10 |
|
| 11 |
#include "gc.h" |
| 12 |
|
| 13 |
#ifndef GC_TEST_EXPORT_API |
| 14 |
# if defined(GC_VISIBILITY_HIDDEN_SET) \ |
| 15 |
&& !defined(__CEGCC__) && !defined(__CYGWIN__) && !defined(__MINGW32__) |
| 16 |
# define GC_TEST_EXPORT_API \ |
| 17 |
extern __attribute__((__visibility__("default"))) |
| 18 |
# else |
| 19 |
# define GC_TEST_EXPORT_API extern |
| 20 |
# endif |
| 21 |
#endif |
| 22 |
|
| 23 |
#define CHECK_OUT_OF_MEMORY(p) \ |
| 24 |
do { \ |
| 25 |
if (NULL == (p)) { \ |
| 26 |
fprintf(stderr, "Out of memory\n"); \ |
| 27 |
exit(69); \ |
| 28 |
} \ |
| 29 |
} while (0) |
| 30 |
|
| 31 |
struct treenode { |
| 32 |
struct treenode *x; |
| 33 |
struct treenode *y; |
| 34 |
}; |
| 35 |
|
| 36 |
static struct treenode *root[10] = { 0 }; |
| 37 |
static struct treenode *root_nz[10] = { (struct treenode *)(GC_word)2 }; |
| 38 |
|
| 39 |
#ifdef STATICROOTSLIB2 |
| 40 |
# define libsrl_getpelem libsrl_getpelem2 |
| 41 |
#else |
| 42 |
|
| 43 |
GC_TEST_EXPORT_API struct treenode * libsrl_mktree(int i) |
| 44 |
{ |
| 45 |
struct treenode *r = GC_NEW(struct treenode); |
| 46 |
struct treenode *x, *y; |
| 47 |
|
| 48 |
CHECK_OUT_OF_MEMORY(r); |
| 49 |
if (0 == i) |
| 50 |
return 0; |
| 51 |
if (1 == i) { |
| 52 |
r = (struct treenode *)GC_MALLOC_ATOMIC(sizeof(struct treenode)); |
| 53 |
CHECK_OUT_OF_MEMORY(r); |
| 54 |
} |
| 55 |
x = libsrl_mktree(i - 1); |
| 56 |
y = libsrl_mktree(i - 1); |
| 57 |
r -> x = x; |
| 58 |
r -> y = y; |
| 59 |
if (i != 1) { |
| 60 |
GC_END_STUBBORN_CHANGE(r); |
| 61 |
GC_reachable_here(x); |
| 62 |
GC_reachable_here(y); |
| 63 |
} |
| 64 |
return r; |
| 65 |
} |
| 66 |
|
| 67 |
GC_TEST_EXPORT_API void * libsrl_init(void) |
| 68 |
{ |
| 69 |
# ifdef TEST_MANUAL_VDB |
| 70 |
GC_set_manual_vdb_allowed(1); |
| 71 |
# endif |
| 72 |
# ifndef STATICROOTSLIB_INIT_IN_MAIN |
| 73 |
GC_INIT(); |
| 74 |
# endif |
| 75 |
# ifndef NO_INCREMENTAL |
| 76 |
GC_enable_incremental(); |
| 77 |
# endif |
| 78 |
return GC_MALLOC(sizeof(struct treenode)); |
| 79 |
} |
| 80 |
|
| 81 |
#endif /* !STATICROOTSLIB2 */ |
| 82 |
|
| 83 |
GC_TEST_EXPORT_API struct treenode ** libsrl_getpelem(int i, int j) |
| 84 |
{ |
| 85 |
return &((j & 1) != 0 ? root_nz : root)[i]; |
| 86 |
} |