[or-cvs] r17597: {tor} Remove some cargo-cult gcc hacks around tor_assert and predi (tor/trunk/src/common)

nickm at seul.org nickm at seul.org
Thu Dec 11 20:23:46 UTC 2008


Author: nickm
Date: 2008-12-11 15:23:46 -0500 (Thu, 11 Dec 2008)
New Revision: 17597

Modified:
   tor/trunk/src/common/compat.h
   tor/trunk/src/common/util.h
Log:
Remove some cargo-cult gcc hacks around tor_assert and predict_unlikely; instead, use the standard convert-to-boolean hack of "svn st" 

Modified: tor/trunk/src/common/compat.h
===================================================================
--- tor/trunk/src/common/compat.h	2008-12-11 19:41:03 UTC (rev 17596)
+++ tor/trunk/src/common/compat.h	2008-12-11 20:23:46 UTC (rev 17597)
@@ -143,7 +143,7 @@
  * except that it tells the compiler that the branch will be taken most of the
  * time.  This can generate slightly better code with some CPUs.
  */
-#define PREDICT_LIKELY(exp) __builtin_expect((exp), 1)
+#define PREDICT_LIKELY(exp) __builtin_expect(!!(exp), 1)
 /** Macro: Evaluates to <b>exp</b> and hints the compiler that the value
  * of <b>exp</b> will probably be false.
  *
@@ -151,7 +151,7 @@
  * except that it tells the compiler that the branch will usually not be
  * taken.  This can generate slightly better code with some CPUs.
  */
-#define PREDICT_UNLIKELY(exp) __builtin_expect((exp), 0)
+#define PREDICT_UNLIKELY(exp) __builtin_expect(!!(exp), 0)
 #else
 #define ATTR_NORETURN
 #define ATTR_PURE

Modified: tor/trunk/src/common/util.h
===================================================================
--- tor/trunk/src/common/util.h	2008-12-11 19:41:03 UTC (rev 17596)
+++ tor/trunk/src/common/util.h	2008-12-11 20:23:46 UTC (rev 17597)
@@ -41,18 +41,10 @@
 #error "Sorry; we don't support building with NDEBUG."
 #endif
 
-#if defined(__GNUC__)
-/* Give an int-valued version of !x that won't confuse PREDICT_UNLIKELY,
- * which does poorly with pointer types on some versions of glibc. */
-#define IS_FALSE_AS_INT(x) ((x) == ((typeof(x)) 0))
-#else
-#define IS_FALSE_AS_INT(x) !(x)
-#endif
-
 /** Like assert(3), but send assertion failures to the log as well as to
  * stderr. */
 #define tor_assert(expr) STMT_BEGIN                                     \
-    if (PREDICT_UNLIKELY(IS_FALSE_AS_INT(expr))) {                      \
+    if (PREDICT_UNLIKELY(!(expr))) {                                    \
       log(LOG_ERR, LD_BUG, "%s:%d: %s: Assertion %s failed; aborting.", \
           _SHORT_FILE_, __LINE__, __func__, #expr);                     \
       fprintf(stderr,"%s:%d %s: Assertion %s failed; aborting.\n",      \



More information about the tor-commits mailing list