From: Ivan Maidanski Date: Sun, 5 May 2013 13:13:54 +0000 (+0400) Subject: Improve staticrootstest: add global data to library, add lib w/o GC_INIT X-Git-Tag: gc7_4_0~80 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a1103330ed427d13cb5f08c30785945efb720238;p=platform%2Fupstream%2Flibgc.git Improve staticrootstest: add global data to library, add lib w/o GC_INIT * tests/staticrootslib.c: Do not include stdio.h (not needed). * tests/staticrootslib.c (root, root_nz): New static variables. * tests/staticrootstest.c (root_nz): Likewise. * tests/staticrootslib.c (libsrl_getpelem): New exported function (exported as "libsrl_getpelem2" if STATICROOTSLIB2). * tests/staticrootslib.c (libsrl_mktree, libsrl_init): Do not define if STATICROOTSLIB2. * tests/staticrootslib.c (libsrl_init): Do not call GC_INIT if STATICROOTSLIB_INIT_IN_MAIN defined. * tests/staticrootstest.c (libsrl_getpelem, libsrl_getpelem2): Declare imported function. * tests/staticrootstest.c (main): Call GC_INIT if STATICROOTSLIB_INIT_IN_MAIN defined; set *libsrl_getpelem2() (only if STATICROOTSLIB2 defined), *libsrl_getpelem() and root_nz[] elements (similar to that of root[]). --- diff --git a/tests/staticrootslib.c b/tests/staticrootslib.c index c80d79c..ef828c7 100644 --- a/tests/staticrootslib.c +++ b/tests/staticrootslib.c @@ -1,8 +1,6 @@ /* This test file is intended to be compiled into a DLL. */ -#include - #ifndef GC_DEBUG # define GC_DEBUG #endif @@ -24,20 +22,36 @@ struct treenode { struct treenode *y; }; -GC_TEST_EXPORT_API struct treenode * libsrl_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)); - if (r) { - r -> x = libsrl_mktree(i-1); - r -> y = libsrl_mktree(i-1); +static struct treenode *root[10] = { 0 }; +static struct treenode *root_nz[10] = { (void *)(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_MALLOC(sizeof(struct treenode)); + if (0 == i) return 0; + if (1 == i) r = GC_MALLOC_ATOMIC(sizeof(struct treenode)); + if (r) { + r -> x = libsrl_mktree(i-1); + r -> y = libsrl_mktree(i-1); + } + return r; } - return r; -} -GC_TEST_EXPORT_API void * libsrl_init(void) + GC_TEST_EXPORT_API void * libsrl_init(void) + { +# ifndef STATICROOTSLIB_INIT_IN_MAIN + GC_INIT(); +# endif + return GC_MALLOC(sizeof(struct treenode)); + } + +#endif /* !STATICROOTSLIB2 */ + +GC_TEST_EXPORT_API struct treenode ** libsrl_getpelem(int i, int j) { - GC_INIT(); - return GC_MALLOC(sizeof(struct treenode)); + return &((j & 1) != 0 ? root_nz : root)[i]; } diff --git a/tests/staticrootstest.c b/tests/staticrootstest.c index 162f02b..34ce9b4 100644 --- a/tests/staticrootstest.c +++ b/tests/staticrootstest.c @@ -21,15 +21,25 @@ struct treenode { 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"); @@ -37,9 +47,13 @@ int main(void) } memset(staticroot, 0x42, sizeof(struct treenode)); GC_gcollect(); - for (j = 0; j < 2; j++) { - for (i = 0; i < 10; ++i) { - root[i] = libsrl_mktree(12); + 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) {