]> 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 21:14:59 +0000 (01:14 +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 40c725a97702be05cb352927d6b65ce41f44c0c2..0674f3761aebfa4e3fc8faf0b452dc6359d4d79a 100644 (file)
@@ -494,7 +494,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.              */
@@ -503,7 +506,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()     */
@@ -511,8 +514,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 15fa2c99289ff648ff8cbf75e521ec5b2dbb5d93..26ab89268233eeb1e27d01aabd6de6e3c27caafe 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -200,8 +200,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;
 
@@ -1833,8 +1832,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
   }