[Gc] GC API: addition of calling conventions. Part 4/4

Ivan Maidanski ivmai at mail.ru
Fri Oct 17 13:10:50 PDT 2008


Part 4 (last).

-------------- next part --------------
diff -ru bdwgc/os_dep.c updated/bdwgc/os_dep.c
--- bdwgc/os_dep.c	2008-10-11 13:43:40.000000000 +0400
+++ updated/bdwgc/os_dep.c	2008-10-16 16:28:27.000000000 +0400
@@ -652,7 +652,7 @@
     return(buf.RegionSize);
 }
 
-GC_API int GC_get_stack_base(struct GC_stack_base *sb)
+GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *sb)
 {
     int dummy;
     ptr_t sp = (ptr_t)(&dummy);
@@ -1071,7 +1071,7 @@
   	/* From pthread_support.c */
 #endif
 
-GC_API int GC_get_stack_base(struct GC_stack_base *b)
+GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *b)
 {
     pthread_attr_t attr;
     size_t size;
@@ -1121,7 +1121,7 @@
 /* next.  Thus this is likely to identify way too large a	*/
 /* "stack" and thus at least result in disastrous performance.	*/
 /* FIXME - Implement better strategies here.			*/
-GC_API int GC_get_stack_base(struct GC_stack_base *b)
+GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *b)
 {
 #   ifdef NEED_FIND_LIMIT
       int dummy;
@@ -1870,7 +1870,7 @@
     return(result);			  
 }
 
-GC_API void GC_win32_free_heap(void)
+GC_API void GC_CALL GC_win32_free_heap(void)
 {
     if (GC_no_win32_dlls) {
  	while (GC_n_heap_bases > 0) {
@@ -2882,7 +2882,7 @@
 }
 #endif /* !DARWIN */
 
-GC_API int GC_incremental_protection_needs(void)
+GC_API int GC_CALL GC_incremental_protection_needs(void)
 {
     if (GC_page_size == HBLKSIZE) {
 	return GC_PROTECTS_POINTER_HEAP;
@@ -3895,7 +3895,7 @@
 #endif /* DARWIN && MPROTECT_VDB */
 
 # ifndef HAVE_INCREMENTAL_PROTECTION_NEEDS
-  GC_API int GC_incremental_protection_needs(void)
+  GC_API int GC_CALL GC_incremental_protection_needs(void)
   {
     return GC_PROTECTS_NONE;
   }
diff -ru bdwgc/pthread_support.c updated/bdwgc/pthread_support.c
--- bdwgc/pthread_support.c	2008-10-11 13:26:05.000000000 +0400
+++ updated/bdwgc/pthread_support.c	2008-10-16 23:05:32.000000000 +0400
@@ -870,7 +870,7 @@
 /* length of time.							*/
 
 struct blocking_data {
-    void (*fn)(void *);
+    void (GC_CALLBACK *fn)(void *);
     void *arg;
 };
 
@@ -897,7 +897,7 @@
     UNLOCK();
 }
 
-void GC_do_blocking(void (*fn)(void *), void *arg) {
+void GC_CALL GC_do_blocking(void (GC_CALLBACK *fn)(void *), void *arg) {
     struct blocking_data my_data;
 
     my_data.fn = fn;
@@ -913,7 +913,7 @@
 				/* parent hasn't yet noticed.		*/
 };
 
-GC_API int GC_unregister_my_thread(void)
+GC_API int GC_CALL GC_unregister_my_thread(void)
 {
     GC_thread me;
 
@@ -1024,7 +1024,7 @@
     return me;
 }
 
-GC_API int GC_register_my_thread(struct GC_stack_base *sb)
+GC_API int GC_CALL GC_register_my_thread(struct GC_stack_base *sb)
 {
     pthread_t my_pthread = pthread_self();
     GC_thread me;
@@ -1047,7 +1047,8 @@
     }
 }
 
-STATIC void * GC_inner_start_routine(struct GC_stack_base *sb, void * arg)
+STATIC void * GC_CALLBACK GC_inner_start_routine(struct GC_stack_base *sb,
+						void * arg)
 {
     struct start_info * si = arg;
     void * result;
diff -ru bdwgc/ptr_chck.c updated/bdwgc/ptr_chck.c
--- bdwgc/ptr_chck.c	2008-09-26 11:42:40.000000000 +0400
+++ updated/bdwgc/ptr_chck.c	2008-10-16 19:10:38.000000000 +0400
@@ -18,13 +18,13 @@
 
 #include "private/gc_pmark.h"
 
-STATIC 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		*/
@@ -36,7 +36,7 @@
 /* We assume this is performance critical.  (It shouldn't	*/
 /* be called by production code, but this can easily make	*/
 /* debugging intolerably slow.)					*/
-GC_API 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;
@@ -99,13 +99,13 @@
     return(p);
 }
 
-STATIC 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	*/
@@ -114,7 +114,7 @@
 /* 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.	*/
-GC_API void * GC_is_valid_displacement(void *p)
+GC_API void * GC_CALL GC_is_valid_displacement(void *p)
 {
     hdr *hhdr;
     word pdispl;
@@ -149,13 +149,14 @@
     return(p);
 }
 
-STATIC 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? */
@@ -183,7 +184,7 @@
 /* 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.				*/
-GC_API void * GC_is_visible(void *p)
+GC_API void * GC_CALL GC_is_visible(void *p)
 {
     hdr *hhdr;
     
@@ -255,7 +256,7 @@
 }
 
 
-GC_API void * GC_pre_incr (void **p, ptrdiff_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 *)((ptr_t)initial + how_much), initial);
@@ -266,7 +267,7 @@
     return (*p = result);
 }
 
-GC_API void * GC_post_incr (void **p, ptrdiff_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 *)((ptr_t)initial + how_much), initial);
diff -ru bdwgc/stubborn.c updated/bdwgc/stubborn.c
--- bdwgc/stubborn.c	2008-07-26 04:51:34.000000000 +0400
+++ updated/bdwgc/stubborn.c	2008-10-16 16:30:37.000000000 +0400
@@ -22,35 +22,35 @@
 /* MANUAL_VDB.  But that imposes the additional constraint that	  */
 /* written, but not yet GC_dirty()ed objects must be referenced	  */
 /* by a stack.							  */
-GC_API void * GC_malloc_stubborn(size_t lb)
+GC_API void * GC_CALL GC_malloc_stubborn(size_t lb)
 {
     return(GC_malloc(lb));
 }
 
-GC_API void GC_end_stubborn_change(void *p)
+GC_API void GC_CALL GC_end_stubborn_change(void *p)
 {
     GC_dirty(p);
 }
 
 /*ARGSUSED*/
-GC_API void GC_change_stubborn(void *p)
+GC_API void GC_CALL GC_change_stubborn(void *p)
 {
 }
 
 #else /* !MANUAL_VDB */
 
-GC_API void * GC_malloc_stubborn(size_t lb)
+GC_API void * GC_CALL GC_malloc_stubborn(size_t lb)
 {
     return(GC_malloc(lb));
 }
 
 /*ARGSUSED*/
-GC_API void GC_end_stubborn_change(void *p)
+GC_API void GC_CALL GC_end_stubborn_change(void *p)
 {
 }
 
 /*ARGSUSED*/
-GC_API void GC_change_stubborn(void *p)
+GC_API void GC_CALL GC_change_stubborn(void *p)
 {
 }
 
diff -ru bdwgc/tests/test.c updated/bdwgc/tests/test.c
--- bdwgc/tests/test.c	2008-09-11 05:37:58.000000000 +0400
+++ updated/bdwgc/tests/test.c	2008-10-16 20:48:57.000000000 +0400
@@ -63,9 +63,7 @@
     static CRITICAL_SECTION incr_cs;
 # endif
 
-#ifdef __STDC__
 # include <stdarg.h>
-#endif
 
 /* Call GC_INIT only on platforms on which we think we really need it,	*/
 /* so that we can test automatic initialization on the rest.		*/
@@ -128,6 +126,9 @@
 #   ifdef MSWINCE
 #     define FAIL DebugBreak()
 #   else
+#     ifdef SMALL_CONFIG
+	void GC_abort(const char * msg);
+#     endif
 #     define FAIL GC_abort("Test failed");
 #   endif
 # endif
@@ -280,7 +281,6 @@
 {
     GC_word * r;
     sexpr result;
-    static int count = 0;
     
     r = (GC_word *) GC_GCJ_MALLOC(sizeof(struct SEXPR)
 		   		  + sizeof(struct fake_vtable*),
@@ -575,11 +575,8 @@
       c = (sexpr)((char *)c + sizeof(char *));
       d = (sexpr)((char *)d + sizeof(char *));
 
-#   ifdef __STDC__
-        GC_FREE((void *)e);
-#   else
-        GC_FREE((char *)e);
-#   endif
+    GC_FREE((void *)e);
+
     check_ints(b,1,50);
     check_ints(a,1,49);
     for (i = 0; i < 50; i++) {
@@ -637,13 +634,7 @@
 int finalized_count = 0;
 volatile int dropped_something = 0;
 
-# ifdef __STDC__
-  void finalizer(void * obj, void * client_data)
-# else
-  void finalizer(obj, client_data)
-  char * obj;
-  char * client_data;
-# endif
+void GC_CALLBACK finalizer(void * obj, void * client_data)
 {
   tn * t = (tn *)obj;
 
@@ -981,18 +972,8 @@
 
 int fail_count = 0;
 
-#ifndef __STDC__
-/*ARGSUSED*/
-void fail_proc1(x)
-void * x;
-{
-    fail_count++;
-}
-
-#else
-
 /*ARGSUSED*/
-void fail_proc1(void * x)
+void GC_CALLBACK fail_proc1(void * x)
 {
     fail_count++;
 }   
@@ -1003,7 +984,7 @@
   int n = 0, i, j;
   q[n++] = p;
   va_start(a,p);
-  for (;(q[n] = va_arg(a,void *));n++) ;
+  for (;(q[n] = va_arg(a,void *)) != NULL;n++) ;
   va_end(a);
   for (i=0; i<n; i++)
     for (j=0; j<i; j++)
@@ -1016,8 +997,6 @@
       }
 }
 
-#endif /* __STDC__ */
-
 #ifdef THREADS
 #   define TEST_FAIL_COUNT(n) 1
 #else 
@@ -1026,16 +1005,18 @@
 
 void run_one_test()
 {
-    char *x;
-    char **z;
-#   ifdef LINT
-    	char *y = 0;
-#   else
-    	char *y = (char *)(size_t)fail_proc1;
+#   ifndef DBG_HDRS_ALL
+	char *x;
+	char **z;
+#	ifdef LINT
+	    char *y = 0;
+#  	else
+	    char *y = (char *)(size_t)fail_proc1;
+#	endif
+	CLOCK_TYPE typed_time;
 #   endif
     CLOCK_TYPE start_time;
     CLOCK_TYPE reverse_time;
-    CLOCK_TYPE typed_time;
     CLOCK_TYPE tree_time;
     unsigned long time_diff;
     DCL_LOCK_STATE;
@@ -1117,7 +1098,7 @@
     		"GC_is_valid_displacement produced incorrect result\n");
 	FAIL;
       }
-#     if defined(__STDC__) && !defined(MSWIN32) && !defined(MSWINCE)
+#     if !defined(MSWIN32) && !defined(MSWINCE)
         /* Harder to test under Windows without a gc.h declaration.  */
         {
 	  size_t i;
@@ -1134,8 +1115,8 @@
 #      if defined(RS6000) || defined(POWERPC)
         if (!TEST_FAIL_COUNT(1)) {
 #      else
-        if (GC_all_interior_pointers && !TEST_FAIL_COUNT(1)
-	    || !GC_all_interior_pointers && !TEST_FAIL_COUNT(2)) {
+        if ((GC_all_interior_pointers && !TEST_FAIL_COUNT(1))
+	    || (!GC_all_interior_pointers && !TEST_FAIL_COUNT(2))) {
 #      endif
     	  GC_printf("GC_is_valid_displacement produced wrong failure indication\n");
     	  FAIL;
@@ -1161,7 +1142,6 @@
       GC_init_gcj_malloc(0, (void *)fake_gcj_mark_proc);
 #   endif
     /* Make sure that fn arguments are visible to the collector.	*/
-#   ifdef __STDC__
       uniq(
         GC_malloc(12), GC_malloc(12), GC_malloc(12),
         (GC_gcollect(),GC_malloc(12)),
@@ -1174,7 +1154,6 @@
         GC_malloc(12), GC_malloc(12), GC_malloc(12),
 	(GC_gcollect(),GC_malloc(12)),
         (void *)0);
-#   endif
     /* GC_malloc(0) must return NULL or something we can deallocate. */
         GC_free(GC_malloc(0));
         GC_free(GC_malloc_atomic(0));
@@ -1335,13 +1314,7 @@
 
 #endif
 
-#ifdef __STDC__
-    void warn_proc(char *msg, GC_word p)
-#else
-    void warn_proc(msg, p)
-    char *msg;
-    GC_word p;
-#endif
+void GC_CALLBACK warn_proc(char *msg, GC_word p)
 {
     GC_printf(msg, (unsigned long)p);
     /*FAIL;*/
diff -ru bdwgc/thread_local_alloc.c updated/bdwgc/thread_local_alloc.c
--- bdwgc/thread_local_alloc.c	2008-10-11 14:49:26.000000000 +0400
+++ updated/bdwgc/thread_local_alloc.c	2008-10-16 16:30:50.000000000 +0400
@@ -134,7 +134,7 @@
   void * /*GC_thread*/ GC_lookup_thread_inner(unsigned /*DWORD*/ thread_id);
 #endif
 
-GC_API void * GC_malloc(size_t bytes)
+GC_API void * GC_CALL GC_malloc(size_t bytes)
 {
     size_t granules = ROUNDED_UP_GRANULES(bytes);
     void *tsd;
@@ -181,7 +181,7 @@
     return result;
 }
 
-GC_API void * GC_malloc_atomic(size_t bytes)
+GC_API void * GC_CALL GC_malloc_atomic(size_t bytes)
 {
     size_t granules = ROUNDED_UP_GRANULES(bytes);
     void *tsd;
@@ -241,7 +241,7 @@
 /* incremental GC should be enabled before we fork a second thread.	*/
 /* Unlike the other thread local allocation calls, we assume that the	*/
 /* collector has been explicitly initialized.				*/
-GC_API void * GC_gcj_malloc(size_t bytes,
+GC_API void * GC_CALL GC_gcj_malloc(size_t bytes,
 			    void * ptr_to_struct_containing_descr)
 {
   if (GC_EXPECT(GC_incremental, 0)) {
diff -ru bdwgc/typd_mlc.c updated/bdwgc/typd_mlc.c
--- bdwgc/typd_mlc.c	2008-10-11 13:16:38.000000000 +0400
+++ updated/bdwgc/typd_mlc.c	2008-10-16 16:32:38.000000000 +0400
@@ -529,7 +529,7 @@
     return new_mark_stack_ptr;
 }
 
-GC_API GC_descr GC_make_descriptor(GC_bitmap bm, size_t len)
+GC_API GC_descr GC_CALL GC_make_descriptor(GC_bitmap bm, size_t len)
 {
     signed_word last_set_bit = len - 1;
     GC_descr result;
@@ -584,7 +584,7 @@
 #define GENERAL_MALLOC_IOP(lb,k) \
     (void *)GC_clear_stack(GC_generic_malloc_ignore_off_page(lb, k))
 
-GC_API void * GC_malloc_explicitly_typed(size_t lb, GC_descr d)
+GC_API void * GC_CALL GC_malloc_explicitly_typed(size_t lb, GC_descr d)
 {
     ptr_t op;
     ptr_t * opp;
@@ -618,7 +618,8 @@
    return((void *) op);
 }
 
-GC_API void * GC_malloc_explicitly_typed_ignore_off_page(size_t lb, GC_descr d)
+GC_API void * GC_CALL GC_malloc_explicitly_typed_ignore_off_page(size_t lb,
+								GC_descr d)
 {
 ptr_t op;
 ptr_t * opp;
@@ -652,7 +653,8 @@
    return((void *) op);
 }
 
-GC_API void * GC_calloc_explicitly_typed(size_t n, size_t lb, GC_descr d)
+GC_API void * GC_CALL GC_calloc_explicitly_typed(size_t n, size_t lb,
+						GC_descr d)
 {
 ptr_t op;
 ptr_t * opp;
diff -ru bdwgc/win32_threads.c updated/bdwgc/win32_threads.c
--- bdwgc/win32_threads.c	2008-10-11 14:44:24.000000000 +0400
+++ updated/bdwgc/win32_threads.c	2008-10-16 19:24:41.000000000 +0400
@@ -137,7 +137,7 @@
 
 #ifdef GC_DLL
   /* Turn on GC_win32_dll_threads	*/
-  GC_API void GC_use_DllMain(void)
+  GC_API void GC_CALL GC_use_DllMain(void)
   {
 #     ifdef THREAD_LOCAL_ALLOC
 	  ABORT("Cannot use thread local allocation with DllMain-based "
@@ -150,7 +150,7 @@
       GC_init_parallel();
   }
 #else
-  GC_API void GC_use_DllMain(void)
+  GC_API void GC_CALL GC_use_DllMain(void)
   {
       ABORT("GC not configured as DLL");
   }
@@ -565,7 +565,7 @@
   }
 }
 
-GC_API int GC_register_my_thread(struct GC_stack_base *sb) {
+GC_API int GC_CALL GC_register_my_thread(struct GC_stack_base *sb) {
   DWORD t = GetCurrentThreadId();
 
   if (0 == GC_lookup_thread(t)) {
@@ -579,7 +579,7 @@
   }
 }
 
-GC_API int GC_unregister_my_thread(void)
+GC_API int GC_CALL GC_unregister_my_thread(void)
 {
     DWORD t = GetCurrentThreadId();
 
@@ -1076,7 +1076,8 @@
     LPVOID param;
 } thread_args;
 
-STATIC void * GC_win32_start_inner(struct GC_stack_base *sb, LPVOID arg)
+STATIC void * GC_CALLBACK GC_win32_start_inner(struct GC_stack_base *sb,
+						void *arg)
 {
     void * ret;
     thread_args *args = (thread_args *)arg;
@@ -1162,7 +1163,7 @@
   ExitThread(dwExitCode);
 }
 
-GC_API GC_uintptr_t GC_beginthreadex(
+GC_API GC_uintptr_t GC_CALL GC_beginthreadex(
     void *security, unsigned stack_size,
     unsigned ( __stdcall *start_address )( void * ),
     void *arglist, unsigned initflag, unsigned *thrdaddr)
@@ -1202,7 +1203,7 @@
     }
 }
 
-GC_API void GC_endthreadex(unsigned retval)
+GC_API void GC_CALL GC_endthreadex(unsigned retval)
 {
   GC_unregister_my_thread();
   _endthreadex(retval);
@@ -1387,7 +1388,8 @@
     return(result);
 }
 
-STATIC void * GC_pthread_start_inner(struct GC_stack_base *sb, void * arg)
+STATIC void * GC_CALLBACK GC_pthread_start_inner(struct GC_stack_base *sb,
+						void * arg)
 {
     struct start_info * si = arg;
     void * result;


More information about the Gc mailing list