diff --git a/ChangeLog b/ChangeLog index 45dec3325..ddd46ce19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-11-28 Matthias Clasen + + Fix G_STMT_START / G_STMT_END on Solaris. (#321972, + Andrew Paprocki) + + * configure.in: Check whether do { } while (0) works. + + * glib/gmacros.h: Use do { } while (0) for G_STMT_START / + G_STMT_END if it works. + 2005-11-28 Matthias Clasen * glib/gthread.c (g_static_rw_lock_wait, g_static_rw_lock_signal): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 45dec3325..ddd46ce19 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,13 @@ +2005-11-28 Matthias Clasen + + Fix G_STMT_START / G_STMT_END on Solaris. (#321972, + Andrew Paprocki) + + * configure.in: Check whether do { } while (0) works. + + * glib/gmacros.h: Use do { } while (0) for G_STMT_START / + G_STMT_END if it works. + 2005-11-28 Matthias Clasen * glib/gthread.c (g_static_rw_lock_wait, g_static_rw_lock_signal): diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 45dec3325..ddd46ce19 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,13 @@ +2005-11-28 Matthias Clasen + + Fix G_STMT_START / G_STMT_END on Solaris. (#321972, + Andrew Paprocki) + + * configure.in: Check whether do { } while (0) works. + + * glib/gmacros.h: Use do { } while (0) for G_STMT_START / + G_STMT_END if it works. + 2005-11-28 Matthias Clasen * glib/gthread.c (g_static_rw_lock_wait, g_static_rw_lock_signal): diff --git a/configure.in b/configure.in index 1fc4ea516..eb4497adc 100644 --- a/configure.in +++ b/configure.in @@ -700,6 +700,21 @@ main (void) { }],[g_can_inline=yes],[g_can_inline=no]) AC_MSG_RESULT($g_can_inline) +dnl *** check for working do while(0) macros *** +AC_CACHE_CHECK([for working do while(0) macros], g_support_dowhile_macros, [ + AC_TRY_COMPILE([],[ + #define STMT_START do + #define STMT_END while(0) + #define STMT_TEST STMT_START { i = 0; } STMT_END + int main(void) { int i = 1; STMT_TEST; return i; }], + [g_support_dowhile_macros=yes], + [g_support_dowhile_macros=no], + [g_support_dowhile_macros=yes]) +]) +if test x$g_support_dowhile_macros = xyes; then + AC_DEFINE(HAVE_DOWHILE_MACROS, 1, [define for working do while(0) macros]) +fi + # check for flavours of varargs macros AC_MSG_CHECKING(for ISO C99 varargs macros in C) AC_TRY_COMPILE([],[ diff --git a/glib/gmacros.h b/glib/gmacros.h index 84e8e10e3..21aa46d76 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -194,23 +194,26 @@ * can be used as a single statement, as in * if (x) G_STMT_START { ... } G_STMT_END; else ... * - * For gcc we will wrap the statements within `({' and `})' braces. - * For SunOS they will be wrapped within `if (1)' and `else (void) 0', - * and otherwise within `do' and `while (0)'. + * When GCC is compiling C code in non-ANSI mode, it will use the + * compiler __extension__ to wrap the statements wihin `({' and '})' braces. + * When compiling on platforms where configure has defined + * HAVE_DOWHILE_MACROS, statements will be wrapped with `do' and `while (0)'. + * For any other platforms (SunOS4 is known to have this issue), wrap the + * statements with `if (1)' and `else (void) 0'. */ #if !(defined (G_STMT_START) && defined (G_STMT_END)) -# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) -# define G_STMT_START (void) __extension__ ( -# define G_STMT_END ) -# else -# if (defined (sun) || defined (__sun__)) -# define G_STMT_START if (1) -# define G_STMT_END else (void)0 -# else -# define G_STMT_START do -# define G_STMT_END while (0) -# endif -# endif +# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) +# define G_STMT_START (void) __extension__ ( +# define G_STMT_END ) +# else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */ +# if defined (HAVE_DOWHILE_MACROS) +# define G_STMT_START do +# define G_STMT_END while (0) +# else /* !HAVE_DOWHILE_MACROS */ +# define G_STMT_START if (1) +# define G_STMT_END else (void) 0 +# endif /* !HAVE_DOWHILE_MACROS */ +# endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */ #endif /* Allow the app programmer to select whether or not return values