Fix some issues and avoid warnings in disclaim-related code.
authorPetter Urkedal <paurkedal@gmail.com>
Sat, 10 Sep 2011 12:03:16 +0000 (14:03 +0200)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 30 Sep 2011 13:35:07 +0000 (17:35 +0400)
* disclaim.c, include/gc_disclaim.h: Fix prototype.
* include/private/gc_priv.h, mark.c: Avoid missing initializer warning.
* mark.c: Fix type of a size_t variable in GC_reclaim_block.
* misc.c: Initialize ok_mark_unconditionally.
* reclaim.c: Tweak and avoid unused label warning.
* tests/disclaim_bench.c, tests/disclaim_test.c: Remove or
conditionalize unused variables.

disclaim.c
include/gc_disclaim.h
include/private/gc_priv.h
mark.c
misc.c
reclaim.c
tests/disclaim_bench.c
tests/disclaim_test.c

index b4f2046..5c86658 100644 (file)
@@ -5,9 +5,9 @@
 
 /* Low level interface for reclaim callbacks. */
 
-int GC_register_disclaim_proc(int kind,
-                              int (*proc)(void *obj, void *cd), void *cd,
-                              int mark_unconditionally)
+void GC_register_disclaim_proc(int kind,
+                               int (*proc)(void *obj, void *cd), void *cd,
+                               int mark_unconditionally)
 {
     GC_obj_kinds[kind].ok_disclaim_proc = proc;
     GC_obj_kinds[kind].ok_disclaim_cd = cd;
index bf4987a..d867813 100644 (file)
@@ -23,9 +23,9 @@
 /* will be protected from collection if "mark_from_all" is non-zero,    */
 /* but at the expense that long chains of objects will take many cycles */
 /* to reclaim.                                                          */
-int GC_register_disclaim_proc(int kind,
-                             int (*proc)(void *obj, void *cd), void *cd,
-                             int mark_from_all);
+void GC_register_disclaim_proc(int kind,
+                               int (*proc)(void *obj, void *cd), void *cd,
+                               int mark_from_all);
 
 /* The finalizer closure used by GC_finalized_malloc.                   */
 struct GC_finalizer_closure {
index 77020f1..eaefbd8 100644 (file)
@@ -1243,6 +1243,9 @@ GC_EXTERN struct obj_kind {
                         /* is reclaimed, but must also tolerate being   */
                         /* called with object from freelist.  Non-zero  */
                         /* exit prevents object from being reclaimed.   */
+#    define OK_DISCLAIM_INITZ FALSE, NULL, NULL
+#  else
+#    define OK_DISCLAIM_INITZ
 #  endif
 } GC_obj_kinds[MAXOBJKINDS];
 
diff --git a/mark.c b/mark.c
index f706e82..14e6afe 100644 (file)
--- a/mark.c
+++ b/mark.c
@@ -51,21 +51,26 @@ GC_INNER unsigned GC_n_mark_procs = GC_RESERVED_MARK_PROCS;
 /* It's done here, since we need to deal with mark descriptors.         */
 GC_INNER struct obj_kind GC_obj_kinds[MAXOBJKINDS] = {
 /* PTRFREE */ { &GC_aobjfreelist[0], 0 /* filled in dynamically */,
-                0 | GC_DS_LENGTH, FALSE, FALSE },
+                0 | GC_DS_LENGTH, FALSE, FALSE,
+                OK_DISCLAIM_INITZ },
 /* NORMAL  */ { &GC_objfreelist[0], 0,
                 0 | GC_DS_LENGTH,  /* Adjusted in GC_init for EXTRA_BYTES */
-                TRUE /* add length to descr */, TRUE },
+                TRUE /* add length to descr */, TRUE,
+                OK_DISCLAIM_INITZ },
 /* UNCOLLECTABLE */
               { &GC_uobjfreelist[0], 0,
-                0 | GC_DS_LENGTH, TRUE /* add length to descr */, TRUE },
+                0 | GC_DS_LENGTH, TRUE /* add length to descr */, TRUE,
+                OK_DISCLAIM_INITZ },
 # ifdef ATOMIC_UNCOLLECTABLE
    /* AUNCOLLECTABLE */
               { &GC_auobjfreelist[0], 0,
-                0 | GC_DS_LENGTH, FALSE /* add length to descr */, FALSE },
+                0 | GC_DS_LENGTH, FALSE /* add length to descr */, FALSE,
+                OK_DISCLAIM_INITZ },
 # endif
 # ifdef STUBBORN_ALLOC
 /*STUBBORN*/ { (void **)&GC_sobjfreelist[0], 0,
-                0 | GC_DS_LENGTH, TRUE /* add length to descr */, TRUE },
+                0 | GC_DS_LENGTH, TRUE /* add length to descr */, TRUE,
+                OK_DISCLAIM_INITZ },
 # endif
 };
 
@@ -1771,8 +1776,8 @@ STATIC void GC_push_marked(struct hblk *h, hdr *hhdr)
 /* first word.                                                          */
 void GC_push_unconditionally(struct hblk *h, hdr *hhdr)
 {
-    int sz = hhdr -> hb_sz;
-    int descr = hhdr -> hb_descr;
+    size_t sz = hhdr -> hb_sz;
+    word descr = hhdr -> hb_descr;
     ptr_t p;
     ptr_t lim;
     mse * GC_mark_stack_top_reg;
diff --git a/misc.c b/misc.c
index 1f87c49..10bf1c9 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1474,6 +1474,9 @@ GC_API unsigned GC_CALL GC_new_kind_inner(void **fl, GC_word descr,
     GC_obj_kinds[result].ok_descriptor = descr;
     GC_obj_kinds[result].ok_relocate_descr = adjust;
     GC_obj_kinds[result].ok_init = clear;
+#   ifdef MARK_UNCONDITIONALLY
+        GC_obj_kinds[result].ok_mark_unconditionally = 0;
+#   endif
 #   ifdef ENABLE_DISCLAIM
         GC_obj_kinds[result].ok_disclaim_proc = 0;
         GC_obj_kinds[result].ok_disclaim_cd = 0;
index 9e8fd4c..ef87f07 100644 (file)
--- a/reclaim.c
+++ b/reclaim.c
@@ -382,9 +382,8 @@ STATIC void GC_reclaim_block(struct hblk *hbp, word report_if_found)
 #             ifdef ENABLE_DISCLAIM
                 if (EXPECT(hhdr->hb_flags & HAS_DISCLAIM, 0)) {
                   struct obj_kind *ok = &GC_obj_kinds[hhdr->hb_obj_kind];
-                  int resurrect;
-                  resurrect = (*ok->ok_disclaim_proc)(hbp, ok->ok_disclaim_cd);
-                  if (resurrect) {
+                  if ((*ok->ok_disclaim_proc)(hbp, ok->ok_disclaim_cd)) {
+                    /* Not disclaimed => resurrect the object. */
                     set_mark_bit_from_hdr(hhdr, 0);
                     /* excuse me, */ goto in_use;
                   }
@@ -397,7 +396,9 @@ STATIC void GC_reclaim_block(struct hblk *hbp, word report_if_found)
               GC_freehblk(hbp);
             }
         } else {
+#        ifdef ENABLE_DISCLAIM
           in_use:
+#        endif
             if (hhdr -> hb_descr != 0) {
               GC_composite_in_use += sz;
             } else {
index 1c90d83..df67bf4 100644 (file)
@@ -56,7 +56,6 @@ testobj_t testobj_new(int model)
 int main(int argc, char **argv)
 {
     int i;
-    int repeat;
     int model;
     testobj_t *keep_arr;
     double t;
index bc8462a..6e005ad 100644 (file)
@@ -113,8 +113,11 @@ void *test(void *data)
 
 int main()
 {
+#if THREAD_CNT > 1
     pthread_t th[THREAD_CNT];
     int i;
+#endif
+
     GC_init();
     GC_init_finalized_malloc();
 #if THREAD_CNT > 1