summaryrefslogtreecommitdiffstats
path: root/lib/libspl
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2015-06-24 13:54:06 -0700
committerBrian Behlendorf <[email protected]>2015-06-24 15:11:48 -0700
commitfa720217b9765303aaa882a9ccdf70c185acc53d (patch)
tree7a9804e251d8f703fe92b135aa1cdbb6710b422b /lib/libspl
parent72540ea3148a2bc03860d7d59b2b5fdc9a5cdee7 (diff)
Add IMPLY() and EQUIV() macros
Added for upstream compatibility, they are of the form: * IMPLY(a, b) - if (a) then (b) * EQUIV(a, b) - if (a) then (b) *AND* if (b) then (a) Signed-off-by: Brian Behlendorf <[email protected]>
Diffstat (limited to 'lib/libspl')
-rw-r--r--lib/libspl/include/assert.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/libspl/include/assert.h b/lib/libspl/include/assert.h
index d749d1e9c..52924e8ba 100644
--- a/lib/libspl/include/assert.h
+++ b/lib/libspl/include/assert.h
@@ -63,6 +63,13 @@ __assert_c99(const char *expr, const char *file, int line, const char *func)
extern void __assert(const char *, const char *, int);
+static inline int
+assfail(const char *buf, const char *file, int line)
+{
+ __assert(buf, file, line);
+ return (0);
+}
+
/* BEGIN CSTYLED */
#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
const TYPE __left = (TYPE)(LEFT); \
@@ -72,7 +79,7 @@ extern void __assert(const char *, const char *, int);
(void) snprintf(__buf, 256, "%s %s %s (0x%llx %s 0x%llx)", \
#LEFT, #OP, #RIGHT, \
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
- __assert(__buf, __FILE__, __LINE__); \
+ assfail(__buf, __FILE__, __LINE__); \
} \
} while (0)
/* END CSTYLED */
@@ -88,12 +95,21 @@ extern void __assert(const char *, const char *, int);
#define ASSERT3P(x, y, z) ((void)0)
#define ASSERT0(x) ((void)0)
#define ASSERTV(x)
+#define IMPLY(A, B) ((void)0)
+#define EQUIV(A, B) ((void)0)
#else
#define ASSERT3S(x, y, z) VERIFY3S(x, y, z)
#define ASSERT3U(x, y, z) VERIFY3U(x, y, z)
#define ASSERT3P(x, y, z) VERIFY3P(x, y, z)
#define ASSERT0(x) VERIFY0(x)
#define ASSERTV(x) x
+#define IMPLY(A, B) \
+ ((void)(((!(A)) || (B)) || \
+ assfail("(" #A ") implies (" #B ")", __FILE__, __LINE__)))
+#define EQUIV(A, B) \
+ ((void)((!!(A) == !!(B)) || \
+ assfail("(" #A ") is equivalent to (" #B ")", __FILE__, __LINE__)))
+
#endif /* NDEBUG */
#endif /* _LIBSPL_ASSERT_H */