aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-06-17 18:22:39 +0000
committerNick Mathewson <nickm@torproject.org>2007-06-17 18:22:39 +0000
commit5adfa09fce2c61239f9a7fa5fb154282f802af0a (patch)
treeffd522053a544617737cc38128c2e315dce464b1 /src/or
parent93f32db438cff63662761374f4a69b710f3d71d9 (diff)
downloadtor-5adfa09fce2c61239f9a7fa5fb154282f802af0a.tar
tor-5adfa09fce2c61239f9a7fa5fb154282f802af0a.tar.gz
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/or')
-rw-r--r--src/or/buffers.c11
-rw-r--r--src/or/config.c8
-rw-r--r--src/or/dns.c2
-rw-r--r--src/or/main.c4
-rw-r--r--src/or/or.h6
-rw-r--r--src/or/policies.c2
-rw-r--r--src/or/routerparse.c10
-rw-r--r--src/or/test.c8
8 files changed, 28 insertions, 23 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c
index eca603c26..9ddd01452 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -40,18 +40,21 @@ const char buffers_c_id[] =
/** Initialize the sentinel values on <b>m</b> (a value of buf-&gt;mem), which
* has <b>ln</b> useful bytes. */
#define SET_GUARDS(m, ln) \
- do { set_uint32((m)-4,START_MAGIC); set_uint32((m)+ln,END_MAGIC); } while (0)
+ STMT_BEGIN \
+ set_uint32((m)-4,START_MAGIC); \
+ set_uint32((m)+ln,END_MAGIC); \
+ STMT_END
#else
#define RAW_MEM(m) (m)
#define GUARDED_MEM(m) (m)
#define ALLOC_LEN(ln) (ln)
-#define SET_GUARDS(m,ln) do {} while (0)
+#define SET_GUARDS(m,ln) STMT_NIL
#endif
#ifdef PARANOIA
-#define check() do { assert_buf_ok(buf); } while (0)
+#define check() STMT_BEGIN assert_buf_ok(buf); STMT_END
#else
-#define check() do { } while (0)
+#define check() STMT_NIL
#endif
#ifdef NOINLINE
diff --git a/src/or/config.c b/src/or/config.c
index 844e802b9..05c682cc4 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -552,11 +552,11 @@ typedef struct {
/** Macro: assert that <b>cfg</b> has the right magic field for format
* <b>fmt</b>. */
-#define CHECK(fmt, cfg) do { \
+#define CHECK(fmt, cfg) STMT_BEGIN \
tor_assert(fmt && cfg); \
tor_assert((fmt)->magic == \
*(uint32_t*)STRUCT_VAR_P(cfg,fmt->magic_offset)); \
- } while (0)
+ STMT_END
static void config_line_append(config_line_t **lst,
const char *key, const char *val);
@@ -2419,8 +2419,8 @@ options_validate(or_options_t *old_options, or_options_t *options,
const char *uname = get_uname();
char buf[1024];
#define REJECT(arg) \
- do { *msg = tor_strdup(arg); return -1; } while (0)
-#define COMPLAIN(arg) do { log(LOG_WARN, LD_CONFIG, arg); } while (0)
+ STMT_BEGIN *msg = tor_strdup(arg); return -1; STMT_END
+#define COMPLAIN(arg) STMT_BEGIN log(LOG_WARN, LD_CONFIG, arg); STMT_END
tor_assert(msg);
*msg = NULL;
diff --git a/src/or/dns.c b/src/or/dns.c
index 764ce843b..26daf39fb 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -103,7 +103,7 @@ static int dns_resolve_impl(edge_connection_t *exitconn, int is_resolve,
static void _assert_cache_ok(void);
#define assert_cache_ok() _assert_cache_ok()
#else
-#define assert_cache_ok() do {} while (0)
+#define assert_cache_ok() STMT_NIL
#endif
static void assert_resolve_ok(cached_resolve_t *resolve);
diff --git a/src/or/main.c b/src/or/main.c
index 9d75f9138..913f299fc 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1965,7 +1965,7 @@ nt_service_loadlibrary(void)
goto err;
}
-#define LOAD(f) do { \
+#define LOAD(f) STMT_BEGIN \
if (!(fn = GetProcAddress(library, #f))) { \
log_err(LD_BUG, \
"Couldn't find %s in advapi32.dll! We probably got the " \
@@ -1974,7 +1974,7 @@ nt_service_loadlibrary(void)
} else { \
service_fns.f ## _fn = fn; \
} \
- } while (0)
+ STMT_END
LOAD(ChangeServiceConfig2A);
LOAD(CloseServiceHandle);
diff --git a/src/or/or.h b/src/or/or.h
index d92493a8e..5d5352d76 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2576,14 +2576,14 @@ void control_adjust_event_log_severity(void);
* Stmt must not contain any return or goto statements.
*/
#define CONN_LOG_PROTECT(conn, stmt) \
- do { \
+ STMT_BEGIN \
int _log_conn_is_control = (conn && conn->type == CONN_TYPE_CONTROL); \
if (_log_conn_is_control) \
disable_control_logging(); \
- do {stmt;} while (0); \
+ STMT_BEGIN stmt; STMT_END; \
if (_log_conn_is_control) \
enable_control_logging(); \
- } while (0)
+ STMT_END
/** Log information about the connection <b>conn</b>, protecting it as with
* CONN_LOG_PROTECT. Example:
diff --git a/src/or/policies.c b/src/or/policies.c
index dfe337059..5c1004025 100644
--- a/src/or/policies.c
+++ b/src/or/policies.c
@@ -220,7 +220,7 @@ authdir_policy_badexit_address(uint32_t addr, uint16_t port)
}
#define REJECT(arg) \
- do { *msg = tor_strdup(arg); goto err; } while (0)
+ STMT_BEGIN *msg = tor_strdup(arg); goto err; STMT_END
/** Config helper: If there's any problem with the policy configuration
* options in <b>options</b>, return -1 and set <b>msg</b> to a newly
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 7604cb6f6..83487d437 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -2282,12 +2282,13 @@ token_free(directory_token_t *tok)
}
#define RET_ERR(msg) \
- do { \
+ STMT_BEGIN \
if (tok) token_free(tok); \
tok = tor_malloc_zero(sizeof(directory_token_t)); \
tok->tp = _ERR; \
tok->error = tor_strdup(msg); \
- goto done_tokenizing; } while (0)
+ goto done_tokenizing; \
+ STMT_END
static INLINE directory_token_t *
token_check_object(const char *kwd,
@@ -2346,12 +2347,13 @@ get_next_token(const char **s, token_rule_t *table)
const char *kwd = "";
#define RET_ERR(msg) \
- do { \
+ STMT_BEGIN \
if (tok) token_free(tok); \
tok = tor_malloc_zero(sizeof(directory_token_t)); \
tok->tp = _ERR; \
tok->error = tor_strdup(msg); \
- goto done_tokenizing; } while (0)
+ goto done_tokenizing; \
+ STMT_END
tok = tor_malloc_zero(sizeof(directory_token_t));
tok->tp = _ERR;
diff --git a/src/or/test.c b/src/or/test.c
index 776cc2aff..985ff18aa 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -1007,25 +1007,25 @@ _test_eq_ip6(struct in6_addr *a, struct in6_addr *b, const char *e1,
}
#define test_eq_ip6(a,b) _test_eq_ip6((a),(b),#a,#b,__LINE__)
-#define test_pton6_same(a,b) do { \
+#define test_pton6_same(a,b) STMT_BEGIN \
r = tor_inet_pton(AF_INET6, a, &a1); \
test_assert(r==1); \
r = tor_inet_pton(AF_INET6, b, &a2); \
test_assert(r==1); \
test_eq_ip6(&a1,&a2); \
- } while (0)
+ STMT_END
#define test_pton6_bad(a) \
test_eq(0, tor_inet_pton(AF_INET6, a, &a1))
-#define test_ntop6_reduces(a,b) do { \
+#define test_ntop6_reduces(a,b) STMT_BEGIN \
r = tor_inet_pton(AF_INET6, a, &a1); \
test_assert(r==1); \
test_streq(tor_inet_ntop(AF_INET6, &a1, buf, sizeof(buf)), b); \
r = tor_inet_pton(AF_INET6, b, &a2); \
test_assert(r==1); \
test_eq_ip6(&a1, &a2); \
- } while (0)
+ STMT_END
static void
test_ip6_helpers(void)