From: Ivan Maidanski Date: Thu, 16 Feb 2012 18:05:31 +0000 (+0400) Subject: Fix GC_finalizer_nested size to workaround alignment problem in Watcom X-Git-Tag: gc7_2~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ec7f03cbfc351e5fd7a5c24d5f5fbb59063671a;p=gc Fix GC_finalizer_nested size to workaround alignment problem in Watcom * 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. --- diff --git a/finalize.c b/finalize.c index 40c725a9..0674f376 100644 --- a/finalize.c +++ b/finalize.c @@ -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 */ diff --git a/os_dep.c b/os_dep.c index 15fa2c99..26ab8926 100644 --- 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 }