boehm-gc: revert all CACAO-specific modifications; this is now an exact copy of the...
[cacao.git] / src / mm / boehm-gc / ptr_chck.c
index dd0529c359629abfef0bbbcfa91ae175b470b68c..6b72ee2fa79640b45f6162e49e384049d7be9202 100644 (file)
  * preprocessor to validate C pointer arithmetic.
  */
 
-#include "config.h"
-
 #include "private/gc_pmark.h"
 
-void GC_default_same_obj_print_proc(void * p, void * q)
+STATIC void GC_CALLBACK GC_default_same_obj_print_proc(void * p, void * q)
 {
     GC_err_printf("%p and %p are not in the same object\n", p, q);
     ABORT("GC_same_obj test failed");
 }
 
-void (*GC_same_obj_print_proc) (void *, void *)
+void (GC_CALLBACK *GC_same_obj_print_proc) (void *, void *)
                = GC_default_same_obj_print_proc;
 
 /* Check that p and q point to the same object.  Call          */
@@ -38,7 +36,7 @@ void (*GC_same_obj_print_proc) (void *, void *)
 /* We assume this is performance critical.  (It shouldn't      */
 /* be called by production code, but this can easily make      */
 /* debugging intolerably slow.)                                        */
-void * GC_same_obj(void *p, void *q)
+GC_API void * GC_CALL GC_same_obj(void *p, void *q)
 {
     struct hblk *h;
     hdr *hhdr;
@@ -101,13 +99,13 @@ fail:
     return(p);
 }
 
-void GC_default_is_valid_displacement_print_proc (void *p)
+STATIC void GC_CALLBACK GC_default_is_valid_displacement_print_proc (void *p)
 {
     GC_err_printf("%p does not point to valid object displacement\n", p);
     ABORT("GC_is_valid_displacement test failed");
 }
 
-void (*GC_is_valid_displacement_print_proc)(void *) = 
+void (GC_CALLBACK *GC_is_valid_displacement_print_proc)(void *) = 
        GC_default_is_valid_displacement_print_proc;
 
 /* Check that if p is a pointer to a heap page, then it points to      */
@@ -116,7 +114,7 @@ void (*GC_is_valid_displacement_print_proc)(void *) =
 /* Always returns its argument.                                                */
 /* Note that we don't lock, since nothing relevant about the header    */
 /* should change while we have a valid object pointer to the block.    */
-void * GC_is_valid_displacement(void *p)
+GC_API void * GC_CALL GC_is_valid_displacement(void *p)
 {
     hdr *hhdr;
     word pdispl;
@@ -151,20 +149,19 @@ fail:
     return(p);
 }
 
-void GC_default_is_visible_print_proc(void * p)
+STATIC void GC_CALLBACK GC_default_is_visible_print_proc(void * p)
 {
     GC_err_printf("%p is not a GC visible pointer location\n", p);
     ABORT("GC_is_visible test failed");
 }
 
-void (*GC_is_visible_print_proc)(void * p) = GC_default_is_visible_print_proc;
+void (GC_CALLBACK *GC_is_visible_print_proc)(void * p) =
+               GC_default_is_visible_print_proc;
 
+#ifndef THREADS
 /* Could p be a stack address? */
-GC_bool GC_on_stack(ptr_t p)
-{
-#   ifdef THREADS
-       return(TRUE);
-#   else
+   STATIC GC_bool GC_on_stack(ptr_t p)
+   {
        int dummy;
 #      ifdef STACK_GROWS_DOWN
            if ((ptr_t)p >= (ptr_t)(&dummy) && (ptr_t)p < GC_stackbottom ) {
@@ -176,8 +173,8 @@ GC_bool GC_on_stack(ptr_t p)
            }
 #      endif
        return(FALSE);
-#   endif
-}
+   }
+#endif
 
 /* Check that p is visible                                             */
 /* to the collector as a possibly pointer containing location.         */
@@ -187,7 +184,7 @@ GC_bool GC_on_stack(ptr_t p)
 /* untyped allocations.  The idea is that it should be possible, though        */
 /* slow, to add such a call to all indirect pointer stores.)           */
 /* Currently useless for multithreaded worlds.                         */
-void * GC_is_visible(void *p)
+GC_API void * GC_CALL GC_is_visible(void *p)
 {
     hdr *hhdr;
     
@@ -206,15 +203,13 @@ void * GC_is_visible(void *p)
          if (GC_on_stack(p)) return(p);
        hhdr = HDR((word)p);
        if (hhdr == 0) {
-           GC_bool result;
-           
            if (GC_is_static_root(p)) return(p);
            /* Else do it again correctly:      */
 #           if (defined(DYNAMIC_LOADING) || defined(MSWIN32) || \
                defined(MSWINCE) || defined(PCR))
                GC_register_dynamic_libraries();
-               result = GC_is_static_root(p);
-               if (result) return(p);
+               if (GC_is_static_root(p))
+                   return(p);
 #          endif
            goto fail;
        } else {
@@ -234,7 +229,7 @@ void * GC_is_visible(void *p)
                    if ((ptr_t)p - (ptr_t)base
                         >= WORDS_TO_BYTES(BITMAP_BITS)
                         || ((word)p & (sizeof(word) - 1))) goto fail;
-                   if (!((1 << (WORDSZ - ((ptr_t)p - (ptr_t)base) - 1))
+                   if (!(((word)1 << (WORDSZ - ((ptr_t)p - (ptr_t)base) - 1))
                          & descr)) goto fail;
                    break;
                case GC_DS_PROC:
@@ -261,10 +256,10 @@ fail:
 }
 
 
-void * GC_pre_incr (void **p, size_t how_much)
+GC_API void * GC_CALL GC_pre_incr (void **p, ptrdiff_t how_much)
 {
     void * initial = *p;
-    void * result = GC_same_obj((void *)((word)initial + how_much), initial);
+    void * result = GC_same_obj((void *)((ptr_t)initial + how_much), initial);
     
     if (!GC_all_interior_pointers) {
        (void) GC_is_valid_displacement(result);
@@ -272,10 +267,10 @@ void * GC_pre_incr (void **p, size_t how_much)
     return (*p = result);
 }
 
-void * GC_post_incr (void **p, size_t how_much)
+GC_API void * GC_CALL GC_post_incr (void **p, ptrdiff_t how_much)
 {
     void * initial = *p;
-    void * result = GC_same_obj((void *)((word)initial + how_much), initial);
+    void * result = GC_same_obj((void *)((ptr_t)initial + how_much), initial);
  
     if (!GC_all_interior_pointers) {
        (void) GC_is_valid_displacement(result);