From: Ivan Maidanski Date: Thu, 8 Feb 2018 08:56:44 +0000 (+0300) Subject: Convert remaining GC tests to valid C++ code X-Git-Tag: v8.0.0~359 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=58241e9ff196d3c957ed7367f64ac35b2f80ef5d;p=gc Convert remaining GC tests to valid C++ code (fix of commit 8086c72) Issue #201 (bdwgc). * tests/disclaim_bench.c (testobj_new): Replace GC_MALLOC(sizeof T) with GC_NEW(T). * tests/staticrootslib.c (libsrl_mktree): Likewise. * tests/trace_test.c (mktree): Likewise. * tests/disclaim_bench.c (testobj_new): Cast GC_finalized_malloc() result to testobj_t. * tests/disclaim_bench.c (main): Cast GC_MALLOC() result to testobj_t*. * tests/disclaim_test.c (pair_dct): Cast obj to pair_t. * tests/disclaim_test.c (pair_dct): Cast cd to pair_t. * tests/disclaim_test.c (GC_finalized_malloc): Cast GC_finalized_malloc() result to pair_t. * tests/staticrootslib.c (root_nz): Cast element to struct treenode*. * tests/staticrootstest.c (root_nz): Likewise. * tests/staticrootslib.c (libsrl_mktree): Cast GC_MALLOC_ATOMIC() result to struct treenode*. * tests/trace_test.c (mktree): Likewise. * tests/staticrootstest.c (init_staticroot): Cast libsrl_init() result to char*. * tests/thread_leak_test.c (main): Cast malloc() result to int*. --- diff --git a/tests/disclaim_bench.c b/tests/disclaim_bench.c index cf952324..8be81cf6 100644 --- a/tests/disclaim_bench.c +++ b/tests/disclaim_bench.c @@ -63,16 +63,17 @@ testobj_t testobj_new(int model) testobj_t obj; switch (model) { case 0: - obj = GC_MALLOC(sizeof(struct testobj_s)); + obj = GC_NEW(struct testobj_s); if (obj != NULL) GC_REGISTER_FINALIZER_NO_ORDER(obj, testobj_finalize, &free_count, NULL, NULL); break; case 1: - obj = GC_finalized_malloc(sizeof(struct testobj_s), &fclos); + obj = (testobj_t)GC_finalized_malloc(sizeof(struct testobj_s), + &fclos); break; case 2: - obj = GC_MALLOC(sizeof(struct testobj_s)); + obj = GC_NEW(struct testobj_s); break; default: exit(-1); @@ -121,7 +122,7 @@ int main(int argc, char **argv) model_max = 2; } - keep_arr = GC_MALLOC(sizeof(void *) * KEEP_CNT); + keep_arr = (testobj_t *)GC_MALLOC(sizeof(void *) * KEEP_CNT); if (NULL == keep_arr) { fprintf(stderr, "Out of memory!\n"); exit(3); diff --git a/tests/disclaim_test.c b/tests/disclaim_test.c index 95f74afd..3850942e 100644 --- a/tests/disclaim_test.c +++ b/tests/disclaim_test.c @@ -106,7 +106,7 @@ int is_pair(pair_t p) void GC_CALLBACK pair_dct(void *obj, void *cd) { - pair_t p = obj; + pair_t p = (pair_t)obj; int checksum; /* Check that obj and its car and cdr are not trashed. */ @@ -126,7 +126,7 @@ void GC_CALLBACK pair_dct(void *obj, void *cd) /* Invalidate it. */ memset(p->magic, '*', sizeof(p->magic)); p->checksum = 0; - p->car = cd; + p->car = (pair_t)cd; p->cdr = NULL; } @@ -136,7 +136,7 @@ pair_new(pair_t car, pair_t cdr) pair_t p; static const struct GC_finalizer_closure fc = { pair_dct, NULL }; - p = GC_finalized_malloc(sizeof(struct pair_s), &fc); + p = (pair_t)GC_finalized_malloc(sizeof(struct pair_s), &fc); if (p == NULL) { fprintf(stderr, "Out of memory!\n"); exit(3); diff --git a/tests/staticrootslib.c b/tests/staticrootslib.c index ef828c7b..f5725c6e 100644 --- a/tests/staticrootslib.c +++ b/tests/staticrootslib.c @@ -23,7 +23,7 @@ struct treenode { }; static struct treenode *root[10] = { 0 }; -static struct treenode *root_nz[10] = { (void *)(GC_word)2 }; +static struct treenode *root_nz[10] = { (struct treenode *)(GC_word)2 }; #ifdef STATICROOTSLIB2 # define libsrl_getpelem libsrl_getpelem2 @@ -31,9 +31,11 @@ static struct treenode *root_nz[10] = { (void *)(GC_word)2 }; 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)); + struct treenode * r = GC_NEW(struct treenode); + if (0 == i) + return 0; + if (1 == i) + r = (struct treenode *)GC_MALLOC_ATOMIC(sizeof(struct treenode)); if (r) { r -> x = libsrl_mktree(i-1); r -> y = libsrl_mktree(i-1); diff --git a/tests/staticrootstest.c b/tests/staticrootstest.c index fc2b9b36..b43765d0 100644 --- a/tests/staticrootstest.c +++ b/tests/staticrootstest.c @@ -23,7 +23,7 @@ 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 }; +struct treenode *root_nz[10] = { (struct treenode *)(GC_word)1 }; static char *staticroot; /* intentionally static */ @@ -38,7 +38,7 @@ void init_staticroot(void) /* Intentionally put staticroot initialization in a function other */ /* than main to prevent CSA warning that staticroot variable can be */ /* changed to be a local one). */ - staticroot = libsrl_init(); + staticroot = (char *)libsrl_init(); } int main(void) diff --git a/tests/thread_leak_test.c b/tests/thread_leak_test.c index 6cb7ab39..c4fb74e9 100644 --- a/tests/thread_leak_test.c +++ b/tests/thread_leak_test.c @@ -27,7 +27,7 @@ int *p[10]; int i; for (i = 0; i < 10; ++i) { - p[i] = malloc(sizeof(int)+i); + p[i] = (int *)malloc(sizeof(int) + i); } CHECK_LEAKS(); for (i = 1; i < 10; ++i) { diff --git a/tests/trace_test.c b/tests/trace_test.c index 79c353f7..d5af8917 100644 --- a/tests/trace_test.c +++ b/tests/trace_test.c @@ -14,9 +14,11 @@ struct treenode { } * root[10]; 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)); + struct treenode * r = GC_NEW(struct treenode); + if (0 == i) + return 0; + if (1 == i) + r = (struct treenode *)GC_MALLOC_ATOMIC(sizeof(struct treenode)); if (r == NULL) { fprintf(stderr, "Out of memory\n"); exit(1);