build_assert: rename EXPR_BUILD_ASSERT to BUILD_ASSERT_OR_ZERO
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)
Same thing (a BUILD_ASSERT which evaluates to zero), but there's a
strong preference for all modules to stick with their own names as
prefixes.

ccan/array_size/array_size.h
ccan/build_assert/build_assert.h
ccan/build_assert/test/compile_fail-expr.c
ccan/build_assert/test/run-BUILD_ASSERT_OR_ZERO.c [new file with mode: 0644]
ccan/build_assert/test/run-EXPR_BUILD_ASSERT.c [deleted file]
ccan/cast/cast.h
ccan/check_type/check_type.h
ccan/hash/hash.h

index c561c0ac9c674ca393405ab888b941c0136ca63a..0876945c5e52a7c19e034fb8fdd1ff5e75d1305f 100644 (file)
@@ -17,7 +17,7 @@
 /* Two gcc extensions.
  * &a[0] degrades to a pointer: a different type from an array */
 #define _array_size_chk(arr)                                           \
-       EXPR_BUILD_ASSERT(!__builtin_types_compatible_p(typeof(arr),    \
+       BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \
                                                        typeof(&(arr)[0])))
 #else
 #define _array_size_chk(arr) 0
index c6ee362f2299933160a552484434f911c713a290..24e59c44cd930173178ac9b6e101b0af64a879e9 100644 (file)
@@ -22,7 +22,7 @@
        do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
 
 /**
- * EXPR_BUILD_ASSERT - assert a build-time dependency, as an expression.
+ * BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression.
  * @cond: the compile-time condition which must be true.
  *
  * Your compile will fail if the condition isn't true, or can't be evaluated
@@ -31,9 +31,9 @@
  * Example:
  *     #define foo_to_char(foo)                                        \
  *              ((char *)(foo)                                         \
- *               + EXPR_BUILD_ASSERT(offsetof(struct foo, string) == 0))
+ *               + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0))
  */
-#define EXPR_BUILD_ASSERT(cond) \
+#define BUILD_ASSERT_OR_ZERO(cond) \
        (sizeof(char [1 - 2*!(cond)]) - 1)
 
 #endif /* CCAN_BUILD_ASSERT_H */
index fa60d6899a7e5b162134af8fd7a0ef1a4e08c7c3..109215b8aa7eab11de86a00b2c174ba9a5cfb721 100644 (file)
@@ -3,7 +3,7 @@
 int main(int argc, char *argv[])
 {
 #ifdef FAIL
-       return EXPR_BUILD_ASSERT(1 == 0);
+       return BUILD_ASSERT_OR_ZERO(1 == 0);
 #else
        return 0;
 #endif
diff --git a/ccan/build_assert/test/run-BUILD_ASSERT_OR_ZERO.c b/ccan/build_assert/test/run-BUILD_ASSERT_OR_ZERO.c
new file mode 100644 (file)
index 0000000..4185821
--- /dev/null
@@ -0,0 +1,9 @@
+#include <ccan/build_assert/build_assert.h>
+#include <ccan/tap/tap.h>
+
+int main(int argc, char *argv[])
+{
+       plan_tests(1);
+       ok1(BUILD_ASSERT_OR_ZERO(1 == 1) == 0);
+       return exit_status();
+}
diff --git a/ccan/build_assert/test/run-EXPR_BUILD_ASSERT.c b/ccan/build_assert/test/run-EXPR_BUILD_ASSERT.c
deleted file mode 100644 (file)
index 91bbbbb..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <ccan/build_assert/build_assert.h>
-#include <ccan/tap/tap.h>
-
-int main(int argc, char *argv[])
-{
-       plan_tests(1);
-       ok1(EXPR_BUILD_ASSERT(1 == 1) == 0);
-       return exit_status();
-}
index f3bb445d0f7c145158c2c67bed05cdbb8059d61b..2fa96445b338f6b6b341b3f2aad122963e91054e 100644 (file)
@@ -14,7 +14,7 @@
  */
 #define cast_signed(type, expr)                                                \
        ((type)(expr)                                                   \
-        + EXPR_BUILD_ASSERT(cast_sign_compatible(type, (expr))))
+        + BUILD_ASSERT_OR_ZERO(cast_sign_compatible(type, (expr))))
 
 /**
  * cast_const - remove a const qualifier from a pointer.
@@ -39,7 +39,7 @@
  */
 #define cast_const(type, expr)                                 \
        ((type)(expr)                                           \
-        + EXPR_BUILD_ASSERT(cast_const_compat1((expr), type)))
+        + BUILD_ASSERT_OR_ZERO(cast_const_compat1((expr), type)))
 
 /**
  * cast_const2 - remove a const qualifier from a pointer to a pointer.
@@ -51,7 +51,7 @@
  */
 #define cast_const2(type, expr)                                        \
        ((type)(expr)                                           \
-        + EXPR_BUILD_ASSERT(cast_const_compat2((expr), type)))
+        + BUILD_ASSERT_OR_ZERO(cast_const_compat2((expr), type)))
 
 /**
  * cast_const3 - remove a const from a pointer to a pointer to a pointer..
@@ -63,7 +63,7 @@
  */
 #define cast_const3(type, expr)                                        \
        ((type)(expr)                                           \
-        + EXPR_BUILD_ASSERT(cast_const_compat3((expr), type)))
+        + BUILD_ASSERT_OR_ZERO(cast_const_compat3((expr), type)))
 
 
 /**
index 884056719cc718eb075acd1a8848c8aef8640265..0cf52543e38e6e2d6ef208873fe975839041ce44 100644 (file)
 #include <ccan/build_assert/build_assert.h>
 /* Without typeof, we can only test the sizes. */
 #define check_type(expr, type)                                 \
-       EXPR_BUILD_ASSERT(sizeof(expr) == sizeof(type))
+       BUILD_ASSERT_OR_ZERO(sizeof(expr) == sizeof(type))
 
 #define check_types_match(expr1, expr2)                                \
-       EXPR_BUILD_ASSERT(sizeof(expr1) == sizeof(expr2))
+       BUILD_ASSERT_OR_ZERO(sizeof(expr1) == sizeof(expr2))
 #endif /* HAVE_TYPEOF */
 
 #endif /* CCAN_CHECK_TYPE_H */
index 189c9438c8dfdccd4ba12480b4afa808f2d7f248..3db75753fb503d5fd9b5284a2e6e0698bdf63b26 100644 (file)
@@ -91,8 +91,8 @@
  *     }
  */
 #define hash_stable(p, num, base)                                      \
-       (EXPR_BUILD_ASSERT(sizeof(*(p)) == 8 || sizeof(*(p)) == 4       \
-                          || sizeof(*(p)) == 2 || sizeof(*(p)) == 1) + \
+       (BUILD_ASSERT_OR_ZERO(sizeof(*(p)) == 8 || sizeof(*(p)) == 4    \
+                             || sizeof(*(p)) == 2 || sizeof(*(p)) == 1) + \
         sizeof(*(p)) == 8 ? hash_stable_64((p), (num), (base))         \
         : sizeof(*(p)) == 4 ? hash_stable_32((p), (num), (base))       \
         : sizeof(*(p)) == 2 ? hash_stable_16((p), (num), (base))       \
@@ -220,8 +220,8 @@ static inline uint32_t hash_string(const char *string)
  *     }
  */
 #define hash64_stable(p, num, base)                                    \
-       (EXPR_BUILD_ASSERT(sizeof(*(p)) == 8 || sizeof(*(p)) == 4       \
-                          || sizeof(*(p)) == 2 || sizeof(*(p)) == 1) + \
+       (BUILD_ASSERT_OR_ZERO(sizeof(*(p)) == 8 || sizeof(*(p)) == 4    \
+                             || sizeof(*(p)) == 2 || sizeof(*(p)) == 1) + \
         sizeof(*(p)) == 8 ? hash64_stable_64((p), (num), (base))       \
         : sizeof(*(p)) == 4 ? hash64_stable_32((p), (num), (base))     \
         : sizeof(*(p)) == 2 ? hash64_stable_16((p), (num), (base))     \
@@ -237,8 +237,8 @@ static inline uint32_t hash_string(const char *string)
  * This is either hash() or hash64(), on 32/64 bit long machines.
  */
 #define hashl(p, num, base)                                            \
-       (EXPR_BUILD_ASSERT(sizeof(long) == sizeof(uint32_t)             \
-                          || sizeof(long) == sizeof(uint64_t)) +       \
+       (BUILD_ASSERT_OR_ZERO(sizeof(long) == sizeof(uint32_t)          \
+                             || sizeof(long) == sizeof(uint64_t)) +    \
        (sizeof(long) == sizeof(uint64_t)                               \
         ? hash64((p), (num), (base)) : hash((p), (num), (base))))