[Gc] Addition of GC_API/GC_CALL declspec to "backptr" API

Ivan Maidanski ivmai at mail.ru
Fri Oct 31 15:35:33 PST 2008


Hi!

This patch adds GC_API and GC_CALL declarator specifiers to the exported functions declared in "gc_backptr.c" file (and defined in "dbg_mlc.c" file).

The patch also adds the conditional "extern C" clause to "gc_backptr.c", "gc_gcj.h" and "gc_mark.h" files.

And, also, "trace_test.c" is changed ("include gc_backptr" and GC_INIT() call are added).

Bye.

-------------- next part --------------
diff -ru bdwgc/dbg_mlc.c updated/bdwgc/dbg_mlc.c
--- bdwgc/dbg_mlc.c	2008-10-29 01:08:22.000000000 +0300
+++ updated/bdwgc/dbg_mlc.c	2008-10-31 13:46:24.000000000 +0300
@@ -91,7 +91,8 @@
   /*   source is heap object ==> *base_p != 0, *offset_p = offset 	*/
   /*   Returns 1 on success, 0 if source couldn't be determined.	*/
   /* Dest can be any address within a heap object.			*/
-  GC_ref_kind GC_get_back_ptr_info(void *dest, void **base_p, size_t *offset_p)
+  GC_API GC_ref_kind GC_CALL GC_get_back_ptr_info(void *dest, void **base_p,
+						size_t *offset_p)
   {
     oh * hdr = (oh *)GC_base(dest);
     ptr_t bp;
@@ -133,7 +134,7 @@
   /* Generate a random heap address.		*/
   /* The resulting address is in the heap, but	*/
   /* not necessarily inside a valid object.	*/
-  void *GC_generate_random_heap_address(void)
+  GC_API void * GC_CALL GC_generate_random_heap_address(void)
   {
     size_t i;
     word heap_offset = RANDOM();
@@ -159,7 +160,7 @@
   }
 
   /* Generate a random address inside a valid marked heap object. */
-  void *GC_generate_random_valid_address(void)
+  GC_API void * GC_CALL GC_generate_random_valid_address(void)
   {
     ptr_t result;
     ptr_t base;
@@ -173,7 +174,7 @@
   }
 
   /* Print back trace for p */
-  void GC_print_backtrace(void *p)
+  GC_API void GC_CALL GC_print_backtrace(void *p)
   {
     void *current = p;
     int i;
@@ -229,7 +230,7 @@
     GC_print_backtrace(current);
   }
     
-  void GC_generate_random_backtrace(void)
+  GC_API void GC_CALL GC_generate_random_backtrace(void)
   {
     GC_gcollect();
     GC_generate_random_backtrace_no_gc();
diff -ru bdwgc/include/gc_backptr.h updated/bdwgc/include/gc_backptr.h
--- bdwgc/include/gc_backptr.h	2005-10-11 03:33:34.000000000 +0400
+++ updated/bdwgc/include/gc_backptr.h	2008-10-31 13:56:56.000000000 +0300
@@ -22,6 +22,15 @@
 
 #ifndef GC_BACKPTR_H
 #define GC_BACKPTR_H
+
+# ifndef _GC_H
+#   include "gc.h"
+# endif
+
+# ifdef __cplusplus
+    extern "C" {
+# endif
+
 /* Store information about the object referencing dest in *base_p     */
 /* and *offset_p.                                                     */
 /* If multiple objects or roots point to dest, the one reported	      */
@@ -40,26 +49,31 @@
 		GC_FINALIZER_REFD /* Finalizable and hence accessible.  */
 } GC_ref_kind;
 
-GC_ref_kind GC_get_back_ptr_info(void *dest, void **base_p, size_t *offset_p);
+GC_API GC_ref_kind GC_CALL GC_get_back_ptr_info(void *dest, void **base_p,
+						size_t *offset_p);
 
 /* Generate a random heap address.            */
 /* The resulting address is in the heap, but  */
 /* not necessarily inside a valid object.     */
-void * GC_generate_random_heap_address(void);
+GC_API void * GC_CALL GC_generate_random_heap_address(void);
 
 /* Generate a random address inside a valid marked heap object. */
-void * GC_generate_random_valid_address(void);
+GC_API void * GC_CALL GC_generate_random_valid_address(void);
 
 /* Force a garbage collection and generate a backtrace from a */
 /* random heap address.                                       */
 /* This uses the GC logging mechanism (GC_printf) to produce  */
 /* output.  It can often be called from a debugger.  The      */
 /* source in dbg_mlc.c also serves as a sample client.	      */
-void GC_generate_random_backtrace(void);
+GC_API void GC_CALL GC_generate_random_backtrace(void);
 
 /* Print a backtrace from a specific address.  Used by the 	*/
 /* above.  The client should call GC_gcollect() immediately	*/
 /* before invocation.						*/
-void GC_print_backtrace(void *);
+GC_API void GC_CALL GC_print_backtrace(void *);
+
+# ifdef __cplusplus
+    }  /* end of extern "C" */
+# endif
 
 #endif /* GC_BACKPTR_H */
diff -ru bdwgc/include/gc_gcj.h updated/bdwgc/include/gc_gcj.h
--- bdwgc/include/gc_gcj.h	2008-10-25 10:03:02.000000000 +0400
+++ updated/bdwgc/include/gc_gcj.h	2008-10-31 13:52:34.000000000 +0300
@@ -43,6 +43,10 @@
 #   include "gc.h"
 #endif
 
+# ifdef __cplusplus
+    extern "C" {
+# endif
+
 /* The following allocators signal an out of memory condition with	*/
 /* return GC_oom_fn(bytes);						*/
 
@@ -92,4 +96,8 @@
 	GC_gcj_malloc_ignore_off_page(s,d)
 # endif
 
+# ifdef __cplusplus
+    }  /* end of extern "C" */
+# endif
+
 #endif /* GC_GCJ_H */
diff -ru bdwgc/include/gc_mark.h updated/bdwgc/include/gc_mark.h
--- bdwgc/include/gc_mark.h	2008-10-27 16:00:04.000000000 +0300
+++ updated/bdwgc/include/gc_mark.h	2008-10-31 13:51:24.000000000 +0300
@@ -29,6 +29,10 @@
 #   include "gc.h"
 # endif
 
+# ifdef __cplusplus
+    extern "C" {
+# endif
+
 /* A client supplied mark procedure.  Returns new mark stack pointer.	*/
 /* Primary effect should be to push new entries on the mark stack.	*/
 /* Mark stack pointer values are passed and returned explicitly.	*/
@@ -202,5 +206,9 @@
 				/* to be used when printing objects	*/
 				/* of a particular kind.		*/
 
+# ifdef __cplusplus
+    }  /* end of extern "C" */
+# endif
+
 #endif  /* GC_MARK_H */
 
diff -ru bdwgc/tests/trace_test.c updated/bdwgc/tests/trace_test.c
--- bdwgc/tests/trace_test.c	2005-10-11 02:33:34.000000000 +0400
+++ updated/bdwgc/tests/trace_test.c	2008-10-31 15:06:30.000000000 +0300
@@ -1,6 +1,11 @@
 #include <stdio.h>
-#define GC_DEBUG
+
+#ifndef GC_DEBUG
+# define GC_DEBUG
+#endif
+
 #include "gc.h"
+#include "gc_backptr.h"
 
 struct treenode {
     struct treenode *x;
@@ -16,9 +21,10 @@
   return r;
 }
 
-main()
+int main(void)
 {
   int i;
+  GC_INIT();
   for (i = 0; i < 10; ++i) {
     root[i] = mktree(12);
   }
@@ -26,4 +32,5 @@
   GC_generate_random_backtrace();
   GC_generate_random_backtrace();
   GC_generate_random_backtrace();
+  return 0;
 }


More information about the Gc mailing list