From 9458f991eb90b4cfef3836dd37ae6d1fe96409fd Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 8 Aug 2008 13:44:30 +0000 Subject: [PATCH] lassert: 0. add LINVRNT() macro for more expensive checks that are disabled by default; 1. replace ((void)0) with ((void)!!sizeof(exp)) so that expression is used (though not evaluated) even when assertions are disabled. !! is for things --like bitfields-- that do not have sizeof. --- libcfs/include/libcfs/libcfs_private.h | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/libcfs/include/libcfs/libcfs_private.h b/libcfs/include/libcfs/libcfs_private.h index e0a27a9..3620355 100644 --- a/libcfs/include/libcfs/libcfs_private.h +++ b/libcfs/include/libcfs/libcfs_private.h @@ -116,13 +116,23 @@ #endif /* !LASSERT_CHECKED */ - - #else /* !LIBCFS_DEBUG */ -#define LASSERT(e) ((void)(0)) -#define LASSERTF(cond, fmt...) ((void)(0)) +/* sizeof is to use expression without evaluating it. */ +# define LASSERT(e) ((void)sizeof!!(e)) +# define LASSERTF(cond, fmt...) ((void)sizeof!!(cond)) #endif /* !LIBCFS_DEBUG */ +#ifdef INVARIANT_CHECK +/** + * This is for more expensive checks that one doesn't want to be enabled all + * the time. LINVRNT() has to be explicitly enabled by --enable-invariants + * configure option. + */ +# define LINVRNT(exp) LASSERT(exp) +#else +# define LINVRNT(exp) ((void)sizeof!!(exp)) +#endif + #define KLASSERT(e) LASSERT(e) void lbug_with_loc(char *file, const char *func, const int line) @@ -234,12 +244,18 @@ do { \ assert(cond); \ } while (0) # define LBUG() assert(0) +# ifdef INVARIANT_CHECK +# define LINVRNT(exp) LASSERT(exp) +# else +# define LINVRNT(exp) ((void)sizeof!!(exp)) +# endif # else -# define LASSERT(e) ((void)(0)) -# define LASSERTF(cond, args...) do { } while (0) +# define LASSERT(e) ((void)sizeof!!(e)) +# define LASSERTF(cond, args...) ((void)sizeof!!(cond)) # define LBUG() ((void)(0)) +# define LINVRNT(exp) ((void)sizeof!!(exp)) # endif /* LIBCFS_DEBUG */ -# define KLASSERT(e) do { } while (0) +# define KLASSERT(e) ((void)0) # define printk(format, args...) printf (format, ## args) # ifdef CRAY_XT3 /* buggy calloc! */ # define LIBCFS_ALLOC(ptr, size) \ -- 1.8.3.1