[Gc] Addition of GC_API_PRIV declarator

Ivan Maidanski ivmai at mail.ru
Wed Oct 29 14:57:03 PST 2008


Hi!

Some functions and vars are declared with GC_API in gc_priv.h and gc_locks.h but they are really used outside only for testing/debugging and shouldn't be normally exported (from a DLL).

So, this patch adds GC_API_PRIV macro (which is defined equal to GC_API unless NO_DEBUGGING) and replaces (to it) most of occurrences of GC_API in gc_priv.h and gc_locks.h (plus in win32_threads.c and test.c).

This patch also eliminates some warnings in test.c (like "code has no effect" and "assigned value is unused").

And, this patch also eliminates "possible extraneous ';' in for" warning in return_single_freelist() ("thread_local_alloc.c" file).

Bye.

-------------- next part --------------
diff -ru bdwgc/include/private/gc_locks.h updated/bdwgc/include/private/gc_locks.h
--- bdwgc/include/private/gc_locks.h	2008-10-25 10:03:02.000000000 +0400
+++ updated/bdwgc/include/private/gc_locks.h	2008-10-29 12:06:51.822768500 +0300
@@ -52,7 +52,7 @@
 #    include <windows.h>
 #    define NO_THREAD (DWORD)(-1)
      extern DWORD GC_lock_holder;
-     GC_API CRITICAL_SECTION GC_allocate_ml;
+     GC_API_PRIV CRITICAL_SECTION GC_allocate_ml;
 #    ifdef GC_ASSERTIONS
 #        define UNCOND_LOCK() \
 		{ EnterCriticalSection(&GC_allocate_ml); \
@@ -192,7 +192,7 @@
 # endif /* !THREADS */
 
 #if defined(UNCOND_LOCK) && !defined(LOCK) 
-     GC_API GC_bool GC_need_to_lock;
+     GC_API_PRIV GC_bool GC_need_to_lock;
      		/* At least two thread running; need to lock.	*/
 #    define LOCK() if (GC_need_to_lock) { UNCOND_LOCK(); }
 #    define UNLOCK() if (GC_need_to_lock) { UNCOND_UNLOCK(); }
diff -ru bdwgc/include/private/gc_priv.h updated/bdwgc/include/private/gc_priv.h
--- bdwgc/include/private/gc_priv.h	2008-10-28 17:07:58.000000000 +0300
+++ updated/bdwgc/include/private/gc_priv.h	2008-10-29 12:17:32.000000000 +0300
@@ -85,6 +85,14 @@
 # define INLINE
 #endif /* __GNUC__ */
 
+#ifndef GC_API_PRIV
+# ifndef NO_DEBUGGING
+#  define GC_API_PRIV GC_API
+# else
+#  define GC_API_PRIV extern
+# endif
+#endif
+
 # ifndef GC_LOCKS_H
 #   include "gc_locks.h"
 # endif
@@ -337,7 +345,7 @@
 #   ifdef SMALL_CONFIG
 #	define ABORT(msg) abort()
 #   else
-	GC_API void GC_abort(const char * msg);
+	GC_API_PRIV void GC_abort(const char * msg);
 #       define ABORT(msg) GC_abort(msg)
 #   endif
 # endif
@@ -1043,7 +1051,7 @@
 #endif
 };
 
-GC_API GC_FAR struct _GC_arrays GC_arrays; 
+GC_API_PRIV GC_FAR struct _GC_arrays GC_arrays; 
 
 # ifndef SEPARATE_GLOBALS
 #   define GC_objfreelist GC_arrays._objfreelist
@@ -1179,7 +1187,7 @@
 
 extern unsigned GC_n_kinds;
 
-GC_API word GC_fo_entries;
+GC_API_PRIV word GC_fo_entries;
 
 extern word GC_n_heap_sects;	/* Number of separately added heap	*/
 				/* sections.				*/
@@ -1758,8 +1766,9 @@
 			/* finalizers to be run, and we haven't called	*/
 			/* this procedure yet this GC cycle.		*/
 
-GC_API void * GC_make_closure(GC_finalization_proc fn, void * data);
-GC_API void GC_CALLBACK GC_debug_invoke_finalizer(void * obj, void * data);
+GC_API_PRIV void * GC_make_closure(GC_finalization_proc fn, void * data);
+GC_API_PRIV void GC_CALLBACK GC_debug_invoke_finalizer(void * obj,
+							void * data);
 			/* Auxiliary fns to make finalization work	*/
 			/* correctly with displaced pointers introduced	*/
 			/* by the debugging allocators.			*/
@@ -1881,7 +1890,7 @@
 void GC_dirty_init(void);
   
 /* Slow/general mark bit manipulation: */
-GC_API GC_bool GC_is_marked(ptr_t p);
+GC_API_PRIV GC_bool GC_is_marked(ptr_t p);
 void GC_clear_mark_bit(ptr_t p);
 void GC_set_mark_bit(ptr_t p);
   
@@ -1916,22 +1925,22 @@
     void GC_noop(void*, ...);
 # else
 #   ifdef __DMC__
-      GC_API void GC_noop(...);
+      GC_API_PRIV void GC_noop(...);
 #   else
-      GC_API void GC_noop();
+      GC_API_PRIV void GC_noop();
 #   endif
 # endif
 
 GC_API void GC_CALL GC_noop1(word);
 
 /* Logging and diagnostic output: 	*/
-GC_API void GC_printf (const char * format, ...);
+GC_API_PRIV void GC_printf (const char * format, ...);
 			/* A version of printf that doesn't allocate,	*/
 			/* 1K total output length.			*/
 			/* (We use sprintf.  Hopefully that doesn't	*/
 			/* allocate for long arguments.)  		*/
-GC_API void GC_err_printf(const char * format, ...);
-GC_API void GC_log_printf(const char * format, ...);
+GC_API_PRIV void GC_err_printf(const char * format, ...);
+GC_API_PRIV void GC_log_printf(const char * format, ...);
 void GC_err_puts(const char *s);
 			/* Write s to stderr, don't buffer, don't add	*/
 			/* newlines, don't ...				*/
diff -ru bdwgc/tests/test.c updated/bdwgc/tests/test.c
--- bdwgc/tests/test.c	2008-10-27 16:17:50.000000000 +0300
+++ updated/bdwgc/tests/test.c	2008-10-29 13:03:24.000000000 +0300
@@ -127,7 +127,7 @@
 #     define FAIL DebugBreak()
 #   else
 #     ifdef SMALL_CONFIG
-	void GC_abort(const char * msg);
+	GC_API_PRIV void GC_abort(const char * msg);
 #     endif
 #     define FAIL GC_abort("Test failed");
 #   endif
@@ -485,16 +485,8 @@
     	}
     }
 
-# else
-
-#   define fork_a_thread()
-
 # endif
 
-#else
-
-# define fork_a_thread()
-
 #endif 
 
 /* Try to force a to be strangely aligned */
@@ -586,7 +578,9 @@
     check_ints(b,1,50);
     check_ints(a,1,49);
     for (i = 0; i < 60; i++) {
-	if (i % 10 == 0) fork_a_thread();
+#	if defined(GC_PTHREADS) || defined(GC_WIN32_THREADS)
+	    if (i % 10 == 0) fork_a_thread();
+#	endif
     	/* This maintains the invariant that a always points to a list of */
     	/* 49 integers.  Thus this is thread safe without locks,	  */
     	/* assuming atomic pointer assignments.				  */
@@ -615,7 +609,8 @@
 #   ifndef THREADS
 	a = 0;
 #   endif  
-    b = c = 0;
+    *(volatile void **)&b = 0;
+    *(volatile void **)&c = 0;
 }
 
 #undef a
@@ -1207,7 +1202,9 @@
     size_t max_heap_sz;
     int i;
     int still_live;
-    int late_finalize_count = 0;
+#   ifdef FINALIZE_ON_DEMAND
+	int late_finalize_count = 0;
+#   endif
     
 #   ifdef VERY_SMALL_CONFIG
     /* these are something of a guess */
@@ -1237,7 +1234,10 @@
       while (GC_collect_a_little()) { }
       for (i = 0; i < 16; i++) {
         GC_gcollect();
-        late_finalize_count += GC_invoke_finalizers();
+#   ifdef FINALIZE_ON_DEMAND
+	   late_finalize_count +=
+#   endif
+		GC_invoke_finalizers();
       }
     (void)GC_printf("Completed %u tests\n", n_tests);
     (void)GC_printf("Allocated %d collectable objects\n", collectable_count);
diff -ru bdwgc/thread_local_alloc.c updated/bdwgc/thread_local_alloc.c
--- bdwgc/thread_local_alloc.c	2008-10-27 12:51:16.000000000 +0300
+++ updated/bdwgc/thread_local_alloc.c	2008-10-29 14:42:52.000000000 +0300
@@ -40,8 +40,9 @@
     } else {
       GC_ASSERT(GC_size(fl) == GC_size(*gfl));
       /* Concatenate: */
-	for (qptr = &(obj_link(fl)), q = *qptr;
-	     (word)q >= HBLKSIZE; qptr = &(obj_link(q)), q = *qptr);
+	qptr = &(obj_link(fl));
+	while ((word)(q = *qptr) >= HBLKSIZE)
+	  qptr = &(obj_link(q));
 	GC_ASSERT(0 == q);
 	*qptr = *gfl;
 	*gfl = fl;
diff -ru bdwgc/win32_threads.c updated/bdwgc/win32_threads.c
--- bdwgc/win32_threads.c	2008-10-28 21:59:00.000000000 +0300
+++ updated/bdwgc/win32_threads.c	2008-10-29 12:35:20.000000000 +0300
@@ -23,11 +23,7 @@
 
 /* Allocation lock declarations.	*/
 #if !defined(USE_PTHREAD_LOCKS)
-# if defined(GC_DLL)
-    __declspec(dllexport) CRITICAL_SECTION GC_allocate_ml;
-# else
-    CRITICAL_SECTION GC_allocate_ml;
-# endif
+  CRITICAL_SECTION GC_allocate_ml;
   DWORD GC_lock_holder = NO_THREAD;
   	/* Thread id for current holder of allocation lock */
 #else


More information about the Gc mailing list