]> granicus.if.org Git - gc/commitdiff
Add 'const' qualifier to pointer argument of GC_clear/set_mark_bit,
authorIvan Maidanski <ivmai@mail.ru>
Tue, 17 Jan 2012 15:44:39 +0000 (19:44 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 17 Jan 2012 15:44:39 +0000 (19:44 +0400)
GC_finalized_malloc, GC_general_register_disappearing_link

* dbg_mlc.c (GC_debug_change_stubborn, GC_debug_end_stubborn_change):
Make argument pointer const.
* finalize.c (GC_general_register_disappearing_link): Likewise.
* fnlz_mlc.c (GC_core_finalized_malloc, GC_finalized_malloc): Likewise.
* include/gc.h (GC_change_stubborn, GC_end_stubborn_change,
GC_debug_change_stubborn, GC_debug_end_stubborn_change,
GC_general_register_disappearing_link): Likewise.
* include/gc_disclaim.h (GC_finalized_malloc): Likewise.
* include/gc_mark.h (GC_clear_mark_bit, GC_set_mark_bit): Likewise.
* mark.c (GC_set_mark_bit, GC_clear_mark_bit): Likewise.
* stubborn.c (GC_end_stubborn_change, GC_change_stubborn): Likewise.
* finalize.c (GC_general_register_disappearing_link): Remove redundant
pointer type casts.
* tests/test.c (cons, print_int_list, mktree): Likewise.
* include/gc.h (GC_GENERAL_REGISTER_DISAPPEARING_LINK): Add cast
removing potential 'const' qualifier.

dbg_mlc.c
finalize.c
fnlz_mlc.c
include/gc.h
include/gc_disclaim.h
include/gc_mark.h
mark.c
stubborn.c
tests/test.c

index eee93a0d9204052eaad3ee265a20c1b2cb286dd8..1eb25eb50834c364cf71b79bcb8c5bb318d3ef88 100644 (file)
--- a/dbg_mlc.c
+++ b/dbg_mlc.c
@@ -569,9 +569,9 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb,
     return (GC_store_debug_info(result, (word)lb, s, i));
   }
 
-  GC_API void GC_CALL GC_debug_change_stubborn(void *p)
+  GC_API void GC_CALL GC_debug_change_stubborn(const void *p)
   {
-    void * q = GC_base(p);
+    const void * q = GC_base((void *)p);
     hdr * hhdr;
 
     if (q == 0) {
@@ -586,9 +586,9 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb,
     GC_change_stubborn(q);
   }
 
-  GC_API void GC_CALL GC_debug_end_stubborn_change(void *p)
+  GC_API void GC_CALL GC_debug_end_stubborn_change(const void *p)
   {
-    void * q = GC_base(p);
+    const void * q = GC_base((void *)p);
     hdr * hhdr;
 
     if (q == 0) {
@@ -610,9 +610,11 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb,
     return GC_debug_malloc(lb, OPT_RA s, i);
   }
 
-  GC_API void GC_CALL GC_debug_change_stubborn(void * p GC_ATTR_UNUSED) {}
+  GC_API void GC_CALL GC_debug_change_stubborn(
+                                const void * p GC_ATTR_UNUSED) {}
 
-  GC_API void GC_CALL GC_debug_end_stubborn_change(void * p GC_ATTR_UNUSED) {}
+  GC_API void GC_CALL GC_debug_end_stubborn_change(
+                                const void * p GC_ATTR_UNUSED) {}
 #endif /* !STUBBORN_ALLOC */
 
 GC_API void * GC_CALL GC_debug_malloc_atomic(size_t lb, GC_EXTRA_PARAMS)
index 2cb1dd265426d53eaee1bd26829a5bc6f2b1a6b5..56f62f1f9985ce7ef18e22684d3d475e4c9decde 100644 (file)
@@ -144,7 +144,7 @@ GC_API int GC_CALL GC_register_disappearing_link(void * * link)
 }
 
 GC_API int GC_CALL GC_general_register_disappearing_link(void * * link,
-                                                         void * obj)
+                                                         const void * obj)
 {
     struct disappearing_link *curr_dl;
     size_t index;
@@ -154,7 +154,7 @@ GC_API int GC_CALL GC_general_register_disappearing_link(void * * link,
     if (((word)link & (ALIGNMENT-1)) || link == NULL)
         ABORT("Bad arg to GC_general_register_disappearing_link");
     LOCK();
-    GC_ASSERT(obj != NULL && GC_base(obj) == obj);
+    GC_ASSERT(obj != NULL && GC_base((void *)obj) == obj);
     if (log_dl_table_size == -1
         || GC_dl_entries > ((word)1 << log_dl_table_size)) {
         GC_grow_table((struct hash_chain_entry ***)(&dl_head),
@@ -609,7 +609,7 @@ GC_INNER void GC_finalize(void)
             } else {
                 dl_set_next(prev_dl, next_dl);
             }
-            GC_clear_mark_bit((ptr_t)curr_dl);
+            GC_clear_mark_bit(curr_dl);
             GC_dl_entries--;
             curr_dl = next_dl;
         } else {
@@ -737,7 +737,7 @@ GC_INNER void GC_finalize(void)
             } else {
                 dl_set_next(prev_dl, next_dl);
             }
-            GC_clear_mark_bit((ptr_t)curr_dl);
+            GC_clear_mark_bit(curr_dl);
             GC_dl_entries--;
             curr_dl = next_dl;
         } else {
index f7fd0db7a2845203ab5b305adff54c82b1d339d8..4c7a4501ab53af10e455455c2078a9aeea968650 100644 (file)
@@ -69,10 +69,10 @@ GC_API void GC_CALL GC_init_finalized_malloc(void)
 
 #ifdef THREAD_LOCAL_ALLOC
   STATIC void * GC_core_finalized_malloc(size_t lb,
-                                         struct GC_finalizer_closure *fclos)
+                                const struct GC_finalizer_closure *fclos)
 #else
   GC_API void * GC_CALL GC_finalized_malloc(size_t lb,
-                                         struct GC_finalizer_closure *fclos)
+                                const struct GC_finalizer_closure *fclos)
 #endif
 {
     ptr_t op;
@@ -104,7 +104,7 @@ GC_API void GC_CALL GC_init_finalized_malloc(void)
 
 #ifdef THREAD_LOCAL_ALLOC
   GC_API void * GC_CALL GC_finalized_malloc(size_t client_lb,
-                                        struct GC_finalizer_closure *fclos)
+                                const struct GC_finalizer_closure *fclos)
   {
     size_t lb = client_lb + sizeof(void *);
     size_t lg = ROUNDED_UP_GRANULES(lb);
index 10e93afbc9670d014fd5966e430872e5dcc03add..6ae6f772a5db4ef303605eeec5ee26f6741d5738 100644 (file)
@@ -404,8 +404,8 @@ GC_API void GC_CALL GC_free(void *);
 /* allowing more than one stubborn object to be changed at once, but it */
 /* is acceptable to do so.  The same applies to dropping stubborn       */
 /* objects that are still changeable.                                   */
-GC_API void GC_CALL GC_change_stubborn(void *);
-GC_API void GC_CALL GC_end_stubborn_change(void *);
+GC_API void GC_CALL GC_change_stubborn(const void *);
+GC_API void GC_CALL GC_end_stubborn_change(const void *);
 
 /* Return a pointer to the base (lowest address) of an object given     */
 /* a pointer to a location within the object.                           */
@@ -684,8 +684,8 @@ GC_API void GC_CALL GC_debug_free(void *);
 GC_API void * GC_CALL GC_debug_realloc(void * /* old_object */,
                         size_t /* new_size_in_bytes */, GC_EXTRA_PARAMS)
                         /* 'realloc' attr */ GC_ATTR_ALLOC_SIZE(2);
-GC_API void GC_CALL GC_debug_change_stubborn(void *);
-GC_API void GC_CALL GC_debug_end_stubborn_change(void *);
+GC_API void GC_CALL GC_debug_change_stubborn(const void *);
+GC_API void GC_CALL GC_debug_end_stubborn_change(const void *);
 
 /* Routines that allocate objects with debug information (like the      */
 /* above), but just fill in dummy file and line number information.     */
@@ -741,7 +741,8 @@ GC_API void * GC_CALL GC_debug_realloc_replacement(void * /* object_addr */,
 # define GC_CHANGE_STUBBORN(p) GC_debug_change_stubborn(p)
 # define GC_END_STUBBORN_CHANGE(p) GC_debug_end_stubborn_change(p)
 # define GC_GENERAL_REGISTER_DISAPPEARING_LINK(link, obj) \
-      GC_general_register_disappearing_link(link, GC_base(obj))
+      GC_general_register_disappearing_link(link, \
+                                        GC_base((/* no const */ void *)(obj)))
 # define GC_REGISTER_DISPLACEMENT(n) GC_debug_register_displacement(n)
 #else
 # define GC_MALLOC_ATOMIC(sz) GC_malloc_atomic(sz)
@@ -929,7 +930,7 @@ GC_API int GC_CALL GC_register_disappearing_link(void ** /* link */);
         /* Only exists for backward compatibility.  See below:  */
 
 GC_API int GC_CALL GC_general_register_disappearing_link(void ** /* link */,
-                                                         void * /* obj */);
+                                                    const void * /* obj */);
         /* A slight generalization of the above. *link is       */
         /* cleared when obj first becomes inaccessible.  This   */
         /* can be used to implement weak pointers easily and    */
index 2e8013d2922e79557a50f5157cd251f7b036b30e..3f0ed6bf001c76a7c3060c46698a699fab45da64 100644 (file)
@@ -51,6 +51,6 @@ struct GC_finalizer_closure {
 /* efficient than GC_register_finalizer and friends.                    */
 /* GC_init_finalized_malloc must be called before using this.           */
 GC_API void *GC_CALL GC_finalized_malloc(size_t /*size*/,
-                                        struct GC_finalizer_closure * /*fc*/);
+                                const struct GC_finalizer_closure * /*fc*/);
 
 #endif
index e3141cefc4b9c93e2955d7e71b198513ff08fafa..e8d7ece4fb9feda601493588241630922abd3de2 100644 (file)
@@ -222,8 +222,8 @@ GC_API GC_start_callback_proc GC_CALL GC_get_start_callback(void);
 /* Slow/general mark bit manipulation.  The caller must hold the        */
 /* allocation lock.  GC_is_marked returns 1 (TRUE) or 0.                */
 GC_API int GC_CALL GC_is_marked(const void *);
-GC_API void GC_CALL GC_clear_mark_bit(void *);
-GC_API void GC_CALL GC_set_mark_bit(void *);
+GC_API void GC_CALL GC_clear_mark_bit(const void *);
+GC_API void GC_CALL GC_set_mark_bit(const void *);
 
 #ifdef __cplusplus
   } /* end of extern "C" */
diff --git a/mark.c b/mark.c
index b2a5d7c6e1299948eb5a1b30c50685836a425e9e..858cf1fe8b16d3e2ff0ce9f7c8e3f35134c1cbfc 100644 (file)
--- a/mark.c
+++ b/mark.c
@@ -190,7 +190,7 @@ static void clear_marks_for_block(struct hblk *h, word dummy GC_ATTR_UNUSED)
 }
 
 /* Slow but general routines for setting/clearing/asking about mark bits */
-GC_API void GC_CALL GC_set_mark_bit(void *p)
+GC_API void GC_CALL GC_set_mark_bit(const void *p)
 {
     struct hblk *h = HBLKPTR(p);
     hdr * hhdr = HDR(h);
@@ -202,7 +202,7 @@ GC_API void GC_CALL GC_set_mark_bit(void *p)
     }
 }
 
-GC_API void GC_CALL GC_clear_mark_bit(void *p)
+GC_API void GC_CALL GC_clear_mark_bit(const void *p)
 {
     struct hblk *h = HBLKPTR(p);
     hdr * hhdr = HDR(h);
index 10863e820e17eaabcea72d9dd05a97dfc7c974e7..82f113896f985f6576c76afe129a4faaee12c369 100644 (file)
     return(GC_malloc(lb));
   }
 
-  GC_API void GC_CALL GC_end_stubborn_change(void *p)
+  GC_API void GC_CALL GC_end_stubborn_change(const void *p)
   {
-    GC_dirty(p);
+    GC_dirty((ptr_t)p);
   }
 
-  GC_API void GC_CALL GC_change_stubborn(void *p GC_ATTR_UNUSED)
+  GC_API void GC_CALL GC_change_stubborn(const void *p GC_ATTR_UNUSED)
   {
   }
 
     return(GC_malloc(lb));
   }
 
-  GC_API void GC_CALL GC_end_stubborn_change(void *p GC_ATTR_UNUSED)
+  GC_API void GC_CALL GC_end_stubborn_change(const void *p GC_ATTR_UNUSED)
   {
   }
 
-  GC_API void GC_CALL GC_change_stubborn(void *p GC_ATTR_UNUSED)
+  GC_API void GC_CALL GC_change_stubborn(const void *p GC_ATTR_UNUSED)
   {
   }
 
index ca7c6d42c81d206647a3fe193390cf35ce827884..863d0c971ce254b0f6a9d3040e7e613548cf8633 100644 (file)
@@ -221,7 +221,7 @@ sexpr cons (sexpr x, sexpr y)
     } else {
         extra_count = my_extra;
     }
-    GC_END_STUBBORN_CHANGE((char *)r);
+    GC_END_STUBBORN_CHANGE(r);
     return(r);
 }
 # endif
@@ -430,14 +430,14 @@ void print_int_list(sexpr x)
 /* ditto: */
 void check_marks_int_list(sexpr x)
 {
-    if (!GC_is_marked((ptr_t)x))
+    if (!GC_is_marked(x))
         GC_printf("[unm:%p]", (void *)x);
     else
         GC_printf("[mkd:%p]", (void *)x);
     if (is_nil(x)) {
         GC_printf("NIL\n");
     } else {
-        if (!GC_is_marked((ptr_t)car(x)))
+        if (!GC_is_marked(car(x)))
           GC_printf("[unm car:%p]", (void *)car(x));
         GC_printf("(%d)", SEXPR_TO_INT(car(car(x))));
         if (!is_nil(cdr(x))) {
@@ -770,8 +770,7 @@ tn * mktree(int n)
         }
         live_indicators[my_index] = 13;
         if (GC_GENERAL_REGISTER_DISAPPEARING_LINK(
-                (void * *)(&(live_indicators[my_index])),
-                (void *)result) != 0) {
+            (void * *)(&(live_indicators[my_index])), result) != 0) {
                 GC_printf("GC_general_register_disappearing_link failed\n");
                 FAIL;
         }
@@ -796,8 +795,7 @@ tn * mktree(int n)
                 FAIL;
         }
         if (GC_GENERAL_REGISTER_DISAPPEARING_LINK(
-                (void * *)(&(live_indicators[my_index])),
-                (void *)result) != 0) {
+            (void * *)(&(live_indicators[my_index])), result) != 0) {
                 GC_printf("GC_general_register_disappearing_link failed 2\n");
                 FAIL;
         }