From 9676e68e4086948002a00faccfe2b5b6b164f011 Mon Sep 17 00:00:00 2001
From: Ivan Maidanski <ivmai@mail.ru>
Date: Mon, 17 Aug 2015 14:32:19 +0300
Subject: [PATCH] Code refactoring of GC_push_finalizer/thread/typed_structures

* finalize.c (GC_push_finalizer_structures): Replace GC_push_all with
GC_PUSH_ALL_SYM invocation.
* pthread_support.c (GC_push_thread_structures): Likewise.
* typd_mlc.c (GC_push_typed_structures_proc): Likewise.
* win32_threads.c (GC_push_thread_structures): Likewise.
* include/private/gc_priv.h (GC_PUSH_ALL_SYM): New macro (handy one to
push a symbol content).
---
 finalize.c                | 19 +++++++------------
 include/private/gc_priv.h |  3 +++
 pthread_support.c         |  5 ++---
 typd_mlc.c                |  3 +--
 win32_threads.c           |  5 ++---
 5 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/finalize.c b/finalize.c
index c7d78e34..beb0d613 100644
--- a/finalize.c
+++ b/finalize.c
@@ -76,21 +76,16 @@ static signed_word log_fo_table_size = -1;
 
 GC_API void GC_CALL GC_push_finalizer_structures(void)
 {
-    GC_ASSERT((word)&GC_dl_hashtbl.head % sizeof(word) == 0);
-    GC_ASSERT((word)&GC_fo_head % sizeof(word) == 0);
-    GC_ASSERT((word)&GC_finalize_now % sizeof(word) == 0);
-
+  GC_ASSERT((word)&GC_dl_hashtbl.head % sizeof(word) == 0);
+  GC_ASSERT((word)&GC_fo_head % sizeof(word) == 0);
+  GC_ASSERT((word)&GC_finalize_now % sizeof(word) == 0);
 # ifndef GC_LONG_REFS_NOT_NEEDED
     GC_ASSERT((word)&GC_ll_hashtbl.head % sizeof(word) == 0);
-    GC_push_all((ptr_t)(&GC_ll_hashtbl.head),
-                (ptr_t)(&GC_ll_hashtbl.head) + sizeof(word));
+    GC_PUSH_ALL_SYM(GC_ll_hashtbl.head);
 # endif
-
-    GC_push_all((ptr_t)(&GC_dl_hashtbl.head),
-                (ptr_t)(&GC_dl_hashtbl.head) + sizeof(word));
-    GC_push_all((ptr_t)(&GC_fo_head), (ptr_t)(&GC_fo_head) + sizeof(word));
-    GC_push_all((ptr_t)(&GC_finalize_now),
-                (ptr_t)(&GC_finalize_now) + sizeof(word));
+  GC_PUSH_ALL_SYM(GC_dl_hashtbl.head);
+  GC_PUSH_ALL_SYM(GC_fo_head);
+  GC_PUSH_ALL_SYM(GC_finalize_now);
 }
 
 /* Double the size of a hash table. *size_ptr is the log of its current */
diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h
index f3a26d2b..bb652c6e 100644
--- a/include/private/gc_priv.h
+++ b/include/private/gc_priv.h
@@ -1603,6 +1603,9 @@ GC_INNER GC_bool GC_collection_in_progress(void);
 # define GC_PUSH_CONDITIONAL(b, t, all) GC_push_all((ptr_t)(b), (ptr_t)(t))
 #endif
 
+#define GC_PUSH_ALL_SYM(sym) \
+                GC_push_all((ptr_t)&(sym), (ptr_t)&(sym) + sizeof(sym))
+
 GC_INNER void GC_push_all_stack(ptr_t b, ptr_t t);
                                     /* As GC_push_all but consider      */
                                     /* interior pointers as valid.      */
diff --git a/pthread_support.c b/pthread_support.c
index bb56f4bf..e15912b6 100644
--- a/pthread_support.c
+++ b/pthread_support.c
@@ -458,10 +458,9 @@ GC_INNER volatile GC_thread GC_threads[THREAD_TABLE_SZ] = {0};
 void GC_push_thread_structures(void)
 {
     GC_ASSERT(I_HOLD_LOCK());
-    GC_push_all((ptr_t)(GC_threads), (ptr_t)(GC_threads)+sizeof(GC_threads));
+    GC_PUSH_ALL_SYM(GC_threads);
 #   if defined(THREAD_LOCAL_ALLOC)
-      GC_push_all((ptr_t)(&GC_thread_key),
-                  (ptr_t)(&GC_thread_key) + sizeof(GC_thread_key));
+      GC_PUSH_ALL_SYM(GC_thread_key);
 #   endif
 }
 
diff --git a/typd_mlc.c b/typd_mlc.c
index d39c3810..43affccd 100644
--- a/typd_mlc.c
+++ b/typd_mlc.c
@@ -102,8 +102,7 @@ STATIC int GC_array_mark_proc_index = 0; /* procedures.                 */
 
 STATIC void GC_push_typed_structures_proc(void)
 {
-  GC_push_all((ptr_t)&GC_ext_descriptors,
-              (ptr_t)&GC_ext_descriptors + sizeof(word));
+  GC_PUSH_ALL_SYM(GC_ext_descriptors);
 }
 
 /* Add a multiword bitmap to GC_ext_descriptors arrays.  Return */
diff --git a/win32_threads.c b/win32_threads.c
index 7032a26f..91137089 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -1134,11 +1134,10 @@ void GC_push_thread_structures(void)
     } else
 # endif
   /* else */ {
-    GC_push_all((ptr_t)(GC_threads), (ptr_t)(GC_threads)+sizeof(GC_threads));
+    GC_PUSH_ALL_SYM(GC_threads);
   }
 # if defined(THREAD_LOCAL_ALLOC)
-    GC_push_all((ptr_t)(&GC_thread_key),
-                (ptr_t)(&GC_thread_key) + sizeof(GC_thread_key));
+    GC_PUSH_ALL_SYM(GC_thread_key);
     /* Just in case we ever use our own TLS implementation.     */
 # endif
 }
-- 
2.40.0