Commit 3f4e83d8 authored by Rusty Russell's avatar Rusty Russell

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.
parent a1d04855
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
/* Two gcc extensions. /* Two gcc extensions.
* &a[0] degrades to a pointer: a different type from an array */ * &a[0] degrades to a pointer: a different type from an array */
#define _array_size_chk(arr) \ #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]))) typeof(&(arr)[0])))
#else #else
#define _array_size_chk(arr) 0 #define _array_size_chk(arr) 0
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
do { (void) sizeof(char [1 - 2*!(cond)]); } while(0) 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. * @cond: the compile-time condition which must be true.
* *
* Your compile will fail if the condition isn't true, or can't be evaluated * Your compile will fail if the condition isn't true, or can't be evaluated
...@@ -31,9 +31,9 @@ ...@@ -31,9 +31,9 @@
* Example: * Example:
* #define foo_to_char(foo) \ * #define foo_to_char(foo) \
* ((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) (sizeof(char [1 - 2*!(cond)]) - 1)
#endif /* CCAN_BUILD_ASSERT_H */ #endif /* CCAN_BUILD_ASSERT_H */
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#ifdef FAIL #ifdef FAIL
return EXPR_BUILD_ASSERT(1 == 0); return BUILD_ASSERT_OR_ZERO(1 == 0);
#else #else
return 0; return 0;
#endif #endif
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
plan_tests(1); plan_tests(1);
ok1(EXPR_BUILD_ASSERT(1 == 1) == 0); ok1(BUILD_ASSERT_OR_ZERO(1 == 1) == 0);
return exit_status(); return exit_status();
} }
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
*/ */
#define cast_signed(type, expr) \ #define cast_signed(type, expr) \
((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. * cast_const - remove a const qualifier from a pointer.
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
*/ */
#define cast_const(type, expr) \ #define cast_const(type, expr) \
((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. * cast_const2 - remove a const qualifier from a pointer to a pointer.
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
*/ */
#define cast_const2(type, expr) \ #define cast_const2(type, expr) \
((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.. * cast_const3 - remove a const from a pointer to a pointer to a pointer..
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
*/ */
#define cast_const3(type, expr) \ #define cast_const3(type, expr) \
((type)(expr) \ ((type)(expr) \
+ EXPR_BUILD_ASSERT(cast_const_compat3((expr), type))) + BUILD_ASSERT_OR_ZERO(cast_const_compat3((expr), type)))
/** /**
......
...@@ -54,10 +54,10 @@ ...@@ -54,10 +54,10 @@
#include <ccan/build_assert/build_assert.h> #include <ccan/build_assert/build_assert.h>
/* Without typeof, we can only test the sizes. */ /* Without typeof, we can only test the sizes. */
#define check_type(expr, type) \ #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) \ #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 /* HAVE_TYPEOF */
#endif /* CCAN_CHECK_TYPE_H */ #endif /* CCAN_CHECK_TYPE_H */
...@@ -91,8 +91,8 @@ ...@@ -91,8 +91,8 @@
* } * }
*/ */
#define hash_stable(p, num, base) \ #define hash_stable(p, num, base) \
(EXPR_BUILD_ASSERT(sizeof(*(p)) == 8 || sizeof(*(p)) == 4 \ (BUILD_ASSERT_OR_ZERO(sizeof(*(p)) == 8 || sizeof(*(p)) == 4 \
|| sizeof(*(p)) == 2 || sizeof(*(p)) == 1) + \ || sizeof(*(p)) == 2 || sizeof(*(p)) == 1) + \
sizeof(*(p)) == 8 ? hash_stable_64((p), (num), (base)) \ sizeof(*(p)) == 8 ? hash_stable_64((p), (num), (base)) \
: sizeof(*(p)) == 4 ? hash_stable_32((p), (num), (base)) \ : sizeof(*(p)) == 4 ? hash_stable_32((p), (num), (base)) \
: sizeof(*(p)) == 2 ? hash_stable_16((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) ...@@ -220,8 +220,8 @@ static inline uint32_t hash_string(const char *string)
* } * }
*/ */
#define hash64_stable(p, num, base) \ #define hash64_stable(p, num, base) \
(EXPR_BUILD_ASSERT(sizeof(*(p)) == 8 || sizeof(*(p)) == 4 \ (BUILD_ASSERT_OR_ZERO(sizeof(*(p)) == 8 || sizeof(*(p)) == 4 \
|| sizeof(*(p)) == 2 || sizeof(*(p)) == 1) + \ || sizeof(*(p)) == 2 || sizeof(*(p)) == 1) + \
sizeof(*(p)) == 8 ? hash64_stable_64((p), (num), (base)) \ sizeof(*(p)) == 8 ? hash64_stable_64((p), (num), (base)) \
: sizeof(*(p)) == 4 ? hash64_stable_32((p), (num), (base)) \ : sizeof(*(p)) == 4 ? hash64_stable_32((p), (num), (base)) \
: sizeof(*(p)) == 2 ? hash64_stable_16((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) ...@@ -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. * This is either hash() or hash64(), on 32/64 bit long machines.
*/ */
#define hashl(p, num, base) \ #define hashl(p, num, base) \
(EXPR_BUILD_ASSERT(sizeof(long) == sizeof(uint32_t) \ (BUILD_ASSERT_OR_ZERO(sizeof(long) == sizeof(uint32_t) \
|| sizeof(long) == sizeof(uint64_t)) + \ || sizeof(long) == sizeof(uint64_t)) + \
(sizeof(long) == sizeof(uint64_t) \ (sizeof(long) == sizeof(uint64_t) \
? hash64((p), (num), (base)) : hash((p), (num), (base)))) ? hash64((p), (num), (base)) : hash((p), (num), (base))))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment