about summary refs log tree commit homepage
path: root/ext
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-04-21 11:14:50 -0700
committerEric Wong <normalperson@yhbt.net>2009-04-21 11:16:34 -0700
commitb57718fb7ed6f813f41b655ecbab1f6edd64ded0 (patch)
tree1caa7f067057ccc43ac6c4ac5c85305c395acd1a /ext
parentba916e542a46686185cb701e87a98a617c0f4078 (diff)
downloadunicorn-b57718fb7ed6f813f41b655ecbab1f6edd64ded0.tar.gz
Use the "do {} while (0)" idiom to wrap the macros we can
wrap to avoid having to worry about semi-colons when using
them.

Unfortunately DEF_MAX_LENGTH can't be wrapped with "do {} while
(0)".  But we do now correctly constify the strings
DEF_MAX_LENGTH creates and also make them static to reduce
visibility.
Diffstat (limited to 'ext')
-rw-r--r--ext/unicorn/http11/http11.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/ext/unicorn/http11/http11.c b/ext/unicorn/http11/http11.c
index 36e0e54..d37b557 100644
--- a/ext/unicorn/http11/http11.c
+++ b/ext/unicorn/http11/http11.c
@@ -54,14 +54,25 @@ static VALUE global_localhost;
 static VALUE global_http;
 
 /** Defines common length and error messages for input length validation. */
-#define DEF_MAX_LENGTH(N,length) const size_t MAX_##N##_LENGTH = length; const char *MAX_##N##_LENGTH_ERR = "HTTP element " # N  " is longer than the " # length " allowed length."
+#define DEF_MAX_LENGTH(N, length) \
+  static const size_t MAX_##N##_LENGTH = length; \
+  static const char * const MAX_##N##_LENGTH_ERR = \
+    "HTTP element " # N  " is longer than the " # length " allowed length."
 
-/** Validates the max length of given input and throws an HttpParserError exception if over. */
-#define VALIDATE_MAX_LENGTH(len, N) if(len > MAX_##N##_LENGTH) { rb_raise(eHttpParserError, MAX_##N##_LENGTH_ERR); }
+/**
+ * Validates the max length of given input and throws an HttpParserError
+ * exception if over.
+ */
+#define VALIDATE_MAX_LENGTH(len, N) do { \
+  if (len > MAX_##N##_LENGTH) \
+    rb_raise(eHttpParserError, MAX_##N##_LENGTH_ERR); \
+} while (0)
 
 /** Defines global strings in the init method. */
-#define DEF_GLOBAL(N, val)   global_##N = rb_obj_freeze(rb_str_new2(val)); rb_global_variable(&global_##N)
-
+#define DEF_GLOBAL(N, val) do { \
+  global_##N = rb_obj_freeze(rb_str_new(val, sizeof(val) - 1)); \
+  rb_global_variable(&global_##N); \
+} while (0)
 
 /* Defines the maximum allowed lengths for various input elements.*/
 DEF_MAX_LENGTH(FIELD_NAME, 256);