]> granicus.if.org Git - gc/commitdiff
Convert remaining GC tests to valid C++ code
authorIvan Maidanski <ivmai@mail.ru>
Thu, 8 Feb 2018 08:56:44 +0000 (11:56 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 8 Feb 2018 10:45:37 +0000 (13:45 +0300)
(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*.

tests/disclaim_bench.c
tests/disclaim_test.c
tests/staticrootslib.c
tests/staticrootstest.c
tests/thread_leak_test.c
tests/trace_test.c

index cf9523245500b6943b2115cd269eca5be0ec4c6a..8be81cf69b951888ffcf06996375ea16daba6935 100644 (file)
@@ -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);
index 95f74afdcf849d808b5ba77e440598db5ffe4125..3850942e40a14655179119e049d5c766d6941650 100644 (file)
@@ -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);
index ef828c7be64ca5603cf3d6497800e781c26e2344..f5725c6e05669299be410da26029377002c4cad9 100644 (file)
@@ -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);
index fc2b9b36ad0c9146f11aff738ccf2048ee91649c..b43765d08ba3b966a713b945f12557db419c9ac9 100644 (file)
@@ -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)
index 6cb7ab39ef6d0a171cdd717bd8add8ed2588433c..c4fb74e9b7b12c2d272675c06152873cb729a5dd 100644 (file)
@@ -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) {
index 79c353f71a61bd32fe35dc056b75db29239eefc7..d5af89176d11f1f8a20a89245a20db538868675b 100644 (file)
@@ -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);