From: Rusty Russell Date: Thu, 17 Mar 2011 11:42:22 +0000 (+1030) Subject: build_assert: rename EXPR_BUILD_ASSERT to BUILD_ASSERT_OR_ZERO X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=3f4e83d8ac847d6bf0c20e88cdbca535e842a97b;hp=a1d048552e7c9cbd07092cefb87204563a807608 build_assert: rename EXPR_BUILD_ASSERT to BUILD_ASSERT_OR_ZERO 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. --- diff --git a/ccan/array_size/array_size.h b/ccan/array_size/array_size.h index c561c0ac..0876945c 100644 --- a/ccan/array_size/array_size.h +++ b/ccan/array_size/array_size.h @@ -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 diff --git a/ccan/build_assert/build_assert.h b/ccan/build_assert/build_assert.h index c6ee362f..24e59c44 100644 --- a/ccan/build_assert/build_assert.h +++ b/ccan/build_assert/build_assert.h @@ -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 */ diff --git a/ccan/build_assert/test/compile_fail-expr.c b/ccan/build_assert/test/compile_fail-expr.c index fa60d689..109215b8 100644 --- a/ccan/build_assert/test/compile_fail-expr.c +++ b/ccan/build_assert/test/compile_fail-expr.c @@ -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 index 00000000..41858213 --- /dev/null +++ b/ccan/build_assert/test/run-BUILD_ASSERT_OR_ZERO.c @@ -0,0 +1,9 @@ +#include +#include + +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 index 91bbbbbf..00000000 --- a/ccan/build_assert/test/run-EXPR_BUILD_ASSERT.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -int main(int argc, char *argv[]) -{ - plan_tests(1); - ok1(EXPR_BUILD_ASSERT(1 == 1) == 0); - return exit_status(); -} diff --git a/ccan/cast/cast.h b/ccan/cast/cast.h index f3bb445d..2fa96445 100644 --- a/ccan/cast/cast.h +++ b/ccan/cast/cast.h @@ -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))) /** diff --git a/ccan/check_type/check_type.h b/ccan/check_type/check_type.h index 88405671..0cf52543 100644 --- a/ccan/check_type/check_type.h +++ b/ccan/check_type/check_type.h @@ -54,10 +54,10 @@ #include /* 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 */ diff --git a/ccan/hash/hash.h b/ccan/hash/hash.h index 189c9438..3db75753 100644 --- a/ccan/hash/hash.h +++ b/ccan/hash/hash.h @@ -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))))