]> granicus.if.org Git - gc/commitdiff
Fix GC_finalizer_nested size to workaround alignment problem in Watcom
authorIvan Maidanski <ivmai@mail.ru>
Thu, 16 Feb 2012 18:05:31 +0000 (22:05 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 16 Feb 2012 18:05:31 +0000 (22:05 +0400)
* finalize.c (GC_finalizer_nested): Change type from char to int to
force GC symbols proper alignment for some compilers (e.g., Watcom);
add comment.
* finalize.c (GC_check_finalizer_nested): Cast GC_finalizer_nested
properly (since it holds an unsigned char value).
* os_dep.c (GC_get_maps): Remove static "init_buf" variable (of char
size) and initialize "maps_buf" to NULL since it is allocated anyway
(since maps_size is non-zero).
* os_dep.c (GC_register_data_segments): Remove static "dummy" variable
(of char size) and use GC_pages_executable instead.

finalize.c
os_dep.c

index ae87e5259568992e8fe54e161845cbba8441d7d0..742b5abd8b641a2ab4b948139846bb9a4b01842a 100644 (file)
@@ -547,7 +547,10 @@ GC_API void GC_CALL GC_register_finalizer_unreachable(void * obj,
 #ifndef THREADS
   /* Global variables to minimize the level of recursion when a client  */
   /* finalizer allocates memory.                                        */
-  STATIC unsigned char GC_finalizer_nested = 0;
+  STATIC int GC_finalizer_nested = 0;
+                        /* Only the lowest byte is used, the rest is    */
+                        /* padding for proper global data alignment     */
+                        /* required for some compilers (like Watcom).   */
   STATIC unsigned GC_finalizer_skipped = 0;
 
   /* Checks and updates the level of finalizers recursion.              */
@@ -556,7 +559,7 @@ GC_API void GC_CALL GC_register_finalizer_unreachable(void * obj,
   /* otherwise returns a pointer to GC_finalizer_nested.                */
   STATIC unsigned char *GC_check_finalizer_nested(void)
   {
-    unsigned nesting_level = GC_finalizer_nested;
+    unsigned nesting_level = *(unsigned char *)&GC_finalizer_nested;
     if (nesting_level) {
       /* We are inside another GC_invoke_finalizers().          */
       /* Skip some implicitly-called GC_invoke_finalizers()     */
@@ -564,8 +567,8 @@ GC_API void GC_CALL GC_register_finalizer_unreachable(void * obj,
       if (++GC_finalizer_skipped < (1U << nesting_level)) return NULL;
       GC_finalizer_skipped = 0;
     }
-    GC_finalizer_nested = (unsigned char)(nesting_level + 1);
-    return &GC_finalizer_nested;
+    *(char *)&GC_finalizer_nested = (char)(nesting_level + 1);
+    return (unsigned char *)&GC_finalizer_nested;
   }
 #endif /* THREADS */
 
index d27f4657f59be5a4fe38408527ac37b24ebaccb9..344c157b8878d565d122a8528decbe3ab5861d3a 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -199,8 +199,7 @@ GC_INNER char * GC_get_maps(void)
 {
     int f;
     ssize_t result;
-    static char init_buf[1];
-    static char *maps_buf = init_buf;
+    static char *maps_buf = NULL;
     static size_t maps_buf_sz = 1;
     size_t maps_size, old_maps_size = 0;
 
@@ -1852,8 +1851,8 @@ void GC_register_data_segments(void)
   void GC_register_data_segments(void)
   {
 #   ifdef MSWIN32
-      static char dummy;
-      GC_register_root_section((ptr_t)(&dummy));
+      GC_register_root_section((ptr_t)&GC_pages_executable);
+                            /* any other GC global variable would fit too. */
 #   endif
   }