Mercurial > nomad > old-fuse
changeset 61:3f383dbb1c15
common: define ASSERT3*, ASSERT0, and ASSERT
Every project needs a set of macros to assert conditions. These are the ones
we have.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Tue, 07 Jul 2015 21:01:06 -0400 |
parents | 858975077f7c |
children | c5f678921e63 |
files | src/common/include/nomad/error.h |
diffstat | 1 files changed, 39 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/common/include/nomad/error.h Tue Jul 07 20:52:33 2015 -0400 +++ b/src/common/include/nomad/error.h Tue Jul 07 21:01:06 2015 -0400 @@ -46,4 +46,43 @@ return (err < 0) && (err >= -MAX_ERRNO); } +extern void assfail(const char *, const char *, int); +extern void assfail3(const char *, uintmax_t, const char *, uintmax_t, + const char *, int); + +#define ASSERT3P(l, op, r) \ + do { \ + uintptr_t lhs = (uintptr_t) (l); \ + uintptr_t rhs = (uintptr_t) (r); \ + if (!((lhs) op (rhs))) \ + assfail3(#l " " #op " " #r, lhs, #op, rhs, \ + __FILE__, __LINE__); \ + } while (0) + +#define ASSERT3U(l, op, r) \ + do { \ + uint64_t lhs = (l); \ + uint64_t rhs = (r); \ + if (!((lhs) op (rhs))) \ + assfail3(#l " " #op " " #r, lhs, #op, rhs, \ + __FILE__, __LINE__); \ + } while (0) + +#define ASSERT3S(l, op, r) \ + do { \ + int64_t lhs = (l); \ + int64_t rhs = (r); \ + if (!((lhs) op (rhs))) \ + assfail3(#l " " #op " " #r, lhs, #op, rhs, \ + __FILE__, __LINE__); \ + } while (0) + +#define ASSERT(c) \ + do { \ + if (!(c)) \ + assfail(#c, __FILE__, __LINE__); \ + } while (0) + +#define ASSERT0(c) ASSERT3U((c), ==, 0) + #endif