diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-06-17 18:22:39 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-06-17 18:22:39 +0000 |
commit | 5adfa09fce2c61239f9a7fa5fb154282f802af0a (patch) | |
tree | ffd522053a544617737cc38128c2e315dce464b1 /src/common/compat.h | |
parent | 93f32db438cff63662761374f4a69b710f3d71d9 (diff) | |
download | tor-5adfa09fce2c61239f9a7fa5fb154282f802af0a.tar.gz tor-5adfa09fce2c61239f9a7fa5fb154282f802af0a.zip |
r13477@catbus: nickm | 2007-06-17 14:22:03 -0400
Sun CC likes to give warnings for the do { } while(0) construction for making statement-like macros. Define STMT_BEGIN/STMT_END macros that do the right thing, and use them everywhere.
svn:r10645
Diffstat (limited to 'src/common/compat.h')
-rw-r--r-- | src/common/compat.h | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/common/compat.h b/src/common/compat.h index 62612b72c6..fe07d3254b 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -120,6 +120,21 @@ extern INLINE double U64_TO_DBL(uint64_t x) { #define PREDICT_UNLIKELY(exp) (exp) #endif +/* Ways to declare macros. */ +#define STMT_NIL (void)0 +#ifdef __GNUC__ +#define STMT_BEGIN (void) ({ +#define STMT_END }) +#else +#if defined(sun) || defined(__sun__) +#define STMT_BEGIN if (1) { +#define STMT_END } else STMT_NIL +#else +#define STMT_BEGIN do { +#define STMT_END } while(0) +#endif +#endif + /* ===== String compatibility */ #ifdef MS_WINDOWS /* Windows names string functions differently from most other platforms. */ @@ -339,9 +354,9 @@ void tor_mutex_free(tor_mutex_t *m); unsigned long tor_get_thread_id(void); #else #define tor_mutex_new() ((tor_mutex_t*)tor_malloc(sizeof(int))) -#define tor_mutex_acquire(m) do { } while (0) -#define tor_mutex_release(m) do { } while (0) -#define tor_mutex_free(m) do { tor_free(m); } while (0) +#define tor_mutex_acquire(m) STMT_NIL +#define tor_mutex_release(m) STMT_NIL +#define tor_mutex_free(m) STMT_BEGIN tor_free(m); STMT_END #define tor_get_thread_id() (1UL) #endif |