From 827f3c4fa495135ce19a0e5ce2f0a0f164805b7c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 25 Nov 2002 21:34:16 +0000 Subject: [PATCH] Remove the (no longer effective) empty if-branch. * glib/gmessages.h (g_assert): (g_return_if_fail): (g_return_val_if_fail): Remove the (no longer effective) empty if-branch. * glib/gmacros.h: Change the definition of G_LIKELY, so that g_return_if_fail() and friends still trigger a gcc warning if the expr is an assignment. --- ChangeLog | 11 +++++++++++ ChangeLog.pre-2-10 | 11 +++++++++++ ChangeLog.pre-2-12 | 11 +++++++++++ ChangeLog.pre-2-2 | 11 +++++++++++ ChangeLog.pre-2-4 | 11 +++++++++++ ChangeLog.pre-2-6 | 11 +++++++++++ ChangeLog.pre-2-8 | 11 +++++++++++ glib/gmacros.h | 18 +++++++++++++++--- glib/gmessages.h | 10 +++++----- 9 files changed, 97 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ec1c5bb0..fbc240d6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2002-11-25 Matthias Clasen + + * glib/gmessages.h (g_assert): + (g_return_if_fail): + (g_return_val_if_fail): Remove the (no longer effective) empty + if-branch. + + * glib/gmacros.h: Change the definition of G_LIKELY, so that + g_return_if_fail() and friends still trigger a gcc warning if + the expr is an assignment. + 2002-11-23 Matthias Clasen * configure.in: Generate docs/reference/*/version.xml. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 7ec1c5bb0..fbc240d6c 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,14 @@ +2002-11-25 Matthias Clasen + + * glib/gmessages.h (g_assert): + (g_return_if_fail): + (g_return_val_if_fail): Remove the (no longer effective) empty + if-branch. + + * glib/gmacros.h: Change the definition of G_LIKELY, so that + g_return_if_fail() and friends still trigger a gcc warning if + the expr is an assignment. + 2002-11-23 Matthias Clasen * configure.in: Generate docs/reference/*/version.xml. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 7ec1c5bb0..fbc240d6c 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,14 @@ +2002-11-25 Matthias Clasen + + * glib/gmessages.h (g_assert): + (g_return_if_fail): + (g_return_val_if_fail): Remove the (no longer effective) empty + if-branch. + + * glib/gmacros.h: Change the definition of G_LIKELY, so that + g_return_if_fail() and friends still trigger a gcc warning if + the expr is an assignment. + 2002-11-23 Matthias Clasen * configure.in: Generate docs/reference/*/version.xml. diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 7ec1c5bb0..fbc240d6c 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,14 @@ +2002-11-25 Matthias Clasen + + * glib/gmessages.h (g_assert): + (g_return_if_fail): + (g_return_val_if_fail): Remove the (no longer effective) empty + if-branch. + + * glib/gmacros.h: Change the definition of G_LIKELY, so that + g_return_if_fail() and friends still trigger a gcc warning if + the expr is an assignment. + 2002-11-23 Matthias Clasen * configure.in: Generate docs/reference/*/version.xml. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 7ec1c5bb0..fbc240d6c 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,14 @@ +2002-11-25 Matthias Clasen + + * glib/gmessages.h (g_assert): + (g_return_if_fail): + (g_return_val_if_fail): Remove the (no longer effective) empty + if-branch. + + * glib/gmacros.h: Change the definition of G_LIKELY, so that + g_return_if_fail() and friends still trigger a gcc warning if + the expr is an assignment. + 2002-11-23 Matthias Clasen * configure.in: Generate docs/reference/*/version.xml. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 7ec1c5bb0..fbc240d6c 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,14 @@ +2002-11-25 Matthias Clasen + + * glib/gmessages.h (g_assert): + (g_return_if_fail): + (g_return_val_if_fail): Remove the (no longer effective) empty + if-branch. + + * glib/gmacros.h: Change the definition of G_LIKELY, so that + g_return_if_fail() and friends still trigger a gcc warning if + the expr is an assignment. + 2002-11-23 Matthias Clasen * configure.in: Generate docs/reference/*/version.xml. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 7ec1c5bb0..fbc240d6c 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,14 @@ +2002-11-25 Matthias Clasen + + * glib/gmessages.h (g_assert): + (g_return_if_fail): + (g_return_val_if_fail): Remove the (no longer effective) empty + if-branch. + + * glib/gmacros.h: Change the definition of G_LIKELY, so that + g_return_if_fail() and friends still trigger a gcc warning if + the expr is an assignment. + 2002-11-23 Matthias Clasen * configure.in: Generate docs/reference/*/version.xml. diff --git a/glib/gmacros.h b/glib/gmacros.h index 58e8cb3af..a07214f00 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -208,10 +208,22 @@ * The G_LIKELY and G_UNLIKELY macros let the programmer give hints to * the compiler about the expected result of an expression. Some compilers * can use this information for optimizations. + * + * The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when + * putting assignments in g_return_if_fail (). */ -#if defined(__GNUC__) && (__GNUC__ > 2) -#define G_LIKELY(expr) __builtin_expect (!!(expr), 1) -#define G_UNLIKELY(expr) __builtin_expect (!!(expr), 0) +#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) +#define _G_BOOLEAN_EXPR(expr) \ + __extension__ ({ \ + int _g_boolean_var_; \ + if (expr) \ + _g_boolean_var_ = 1; \ + else \ + _g_boolean_var_ = 0; \ + _g_boolean_var_; \ +}) +#define G_LIKELY(expr) __builtin_expect (_G_BOOLEAN_EXPR(expr), 1) +#define G_UNLIKELY(expr) __builtin_expect (_G_BOOLEAN_EXPR(expr), 0) #else #define G_LIKELY(expr) expr #define G_UNLIKELY(expr) expr diff --git a/glib/gmessages.h b/glib/gmessages.h index ecfcbcab9..3a4a8dd9e 100644 --- a/glib/gmessages.h +++ b/glib/gmessages.h @@ -201,7 +201,7 @@ GPrintFunc g_set_printerr_handler (GPrintFunc func); #ifdef __GNUC__ #define g_assert(expr) G_STMT_START{ \ - if (expr) { } else \ + if (!G_LIKELY (expr)) \ g_log (G_LOG_DOMAIN, \ G_LOG_LEVEL_ERROR, \ "file %s: line %d (%s): assertion failed: (%s)", \ @@ -253,7 +253,7 @@ GPrintFunc g_set_printerr_handler (GPrintFunc func); #ifdef __GNUC__ #define g_return_if_fail(expr) G_STMT_START{ \ - if (G_LIKELY (expr)) { } else \ + if (!G_LIKELY (expr)) \ { \ g_log (G_LOG_DOMAIN, \ G_LOG_LEVEL_CRITICAL, \ @@ -266,7 +266,7 @@ GPrintFunc g_set_printerr_handler (GPrintFunc func); }; }G_STMT_END #define g_return_val_if_fail(expr,val) G_STMT_START{ \ - if (G_LIKELY (expr)) { } else \ + if (!G_LIKELY (expr)) \ { \ g_log (G_LOG_DOMAIN, \ G_LOG_LEVEL_CRITICAL, \ @@ -299,7 +299,7 @@ GPrintFunc g_set_printerr_handler (GPrintFunc func); #else /* !__GNUC__ */ #define g_return_if_fail(expr) G_STMT_START{ \ - if (G_LIKELY (expr)) { } else \ + if (expr) { } else \ { \ g_log (G_LOG_DOMAIN, \ G_LOG_LEVEL_CRITICAL, \ @@ -311,7 +311,7 @@ GPrintFunc g_set_printerr_handler (GPrintFunc func); }; }G_STMT_END #define g_return_val_if_fail(expr, val) G_STMT_START{ \ - if (G_LIKELY (expr)) { } else \ + if (expr) { } else \ { \ g_log (G_LOG_DOMAIN, \ G_LOG_LEVEL_CRITICAL, \