Skip to content

Commit

Permalink
use original
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com>
  • Loading branch information
BrainSlayer committed Aug 23, 2024
1 parent c98dc67 commit 27052a0
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 33 deletions.
1 change: 1 addition & 0 deletions include/os/linux/spl/sys/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)

#ifdef NDEBUG
#define VERIFY(cond) (void) ((!(cond)))
#define VERIFYF(cond) do { } while(0)

Check failure on line 108 in include/os/linux/spl/sys/debug.h

View workflow job for this annotation

GitHub Actions / checkstyle

missing space between keyword and paren

#define VERIFY3B(LEFT, OP, RIGHT) \
do { \
Expand Down
162 changes: 129 additions & 33 deletions lib/libspl/include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,77 +63,173 @@ libspl_assert(const char *buf, const char *file, const char *func, int line)
#ifdef verify
#undef verify
#endif

#ifdef NDEBUG
#define VERIFY(cond) (void) ((!(cond)))
#define VERIFYF(cond, STR, ...) do { } while(0)

Check failure on line 69 in lib/libspl/include/assert.h

View workflow job for this annotation

GitHub Actions / checkstyle

missing space between keyword and paren
#define verify(cond) (void) ((!(cond)))

#define PANIC(fmt, a...) \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, fmt, ## a)
libspl_assertf("unknown", __FUNCTION__, __LINE__, fmt, ## a)

#define VERIFY3B(LEFT, OP, RIGHT) \
do { \
const boolean_t __left __attribute__((unused)) = \
(boolean_t)(LEFT); \
const boolean_t __right __attribute__((unused)) = \
(boolean_t)(RIGHT); \
const boolean_t __left = (boolean_t)(LEFT); \
const boolean_t __right = (boolean_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
"%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
} while (0)

#define VERIFY3S(LEFT, OP, RIGHT) \
do { \
const int64_t __left __attribute__((unused)) = \
(int64_t)(LEFT); \
const int64_t __right __attribute__((unused)) = \
(int64_t)(RIGHT); \
const int64_t __left = (int64_t)(LEFT); \
const int64_t __right = (int64_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
"%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
} while (0)

#define VERIFY3U(LEFT, OP, RIGHT) \
do { \
const uint64_t __left __attribute__((unused)) = \
(uint64_t)(LEFT); \
const uint64_t __right __attribute__((unused)) = \
(uint64_t)(RIGHT); \
const uint64_t __left = (uint64_t)(LEFT); \
const uint64_t __right = (uint64_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
"%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
} while (0)

#define VERIFY3P(LEFT, OP, RIGHT) \
do { \
const uintptr_t __left __attribute__((unused)) = \
(uintptr_t)(LEFT); \
const uintptr_t __right __attribute__((unused)) = \
(uintptr_t)(RIGHT); \
const uintptr_t __left = (uintptr_t)(LEFT); \
const uintptr_t __right = (uintptr_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
"%s %s %s (%p %s %p)", #LEFT, #OP, #RIGHT, \
(void *)__left, #OP, (void *)__right); \
} while (0)

#define VERIFY0(LEFT) \
do { \
const uint64_t __left __attribute__((unused)) = \
(uint64_t)(LEFT); \
const uint64_t __left = (uint64_t)(LEFT); \
if (!(__left == 0)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
"%s == 0 (0x%llx == 0)", #LEFT, \
(u_longlong_t)__left); \
} while (0)

#define VERIFY0P(LEFT) \
do { \
const uintptr_t __left = (uintptr_t)(LEFT); \
if (!(__left == 0)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
"%s == 0 (%p == 0)", #LEFT, \
(void *)__left); \
} while (0)

/*
* This is just here because cstyle gets upset about #LEFT
* on a newline.
*/

/* BEGIN CSTYLED */
#define VERIFY3BF(LEFT, OP, RIGHT, STR, ...) \
do { \
const boolean_t __left = (boolean_t)(LEFT); \
const boolean_t __right = (boolean_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
"%s %s %s (0x%llx %s 0x%llx) " STR, \
#LEFT, #OP, #RIGHT, \
(u_longlong_t)__left, #OP, (u_longlong_t)__right, \
__VA_ARGS__); \
} while (0)

#define VERIFY3SF(LEFT, OP, RIGHT, STR, ...) \
do { \
const int64_t __left = (int64_t)(LEFT); \
const int64_t __right = (int64_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
"%s %s %s (0x%llx %s 0x%llx) " STR, \
#LEFT, #OP, #RIGHT, \
(u_longlong_t)__left, #OP, (u_longlong_t)__right, \
__VA_ARGS__); \
} while (0)

#define VERIFY3UF(LEFT, OP, RIGHT, STR, ...) \
do { \
const uint64_t __left = (uint64_t)(LEFT); \
const uint64_t __right = (uint64_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
"%s %s %s (0x%llx %s 0x%llx) " STR, \
#LEFT, #OP, #RIGHT, \
(u_longlong_t)__left, #OP, (u_longlong_t)__right, \
__VA_ARGS__); \
} while (0)

#define VERIFY3PF(LEFT, OP, RIGHT, STR, ...) \
do { \
const uintptr_t __left = (uintptr_t)(LEFT); \
const uintptr_t __right = (uintptr_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
"%s %s %s (0x%llx %s 0x%llx) " STR, \
#LEFT, #OP, #RIGHT, \
(u_longlong_t)__left, #OP, (u_longlong_t)__right, \
__VA_ARGS__); \
} while (0)
/* END CSTYLED */

#define VERIFY0F(LEFT, STR, ...) \
do { \
const uint64_t __left = (uint64_t)(LEFT); \
if (!(__left == 0)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
"%s == 0 (0x%llx == 0) " STR, #LEFT, \
(u_longlong_t)__left, __VA_ARGS__); \
} while (0)

#define VERIFY0PF(LEFT, STR, ...) \
do { \
const uintptr_t __left = (uintptr_t)(LEFT); \
if (!(__left == 0)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
"%s == 0 (%p == 0) " STR, #LEFT, \
(u_longlong_t)__left, __VA_ARGS__); \
} while (0)

#else

#define PANIC(fmt, a...) \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, fmt, ## a)

#define VERIFY(cond) \
(void) ((!(cond)) && \
libspl_assert(#cond, "unknown", __FUNCTION__, __LINE__))
libspl_assert(#cond, __FILE__, __FUNCTION__, __LINE__))

#define VERIFYF(cond, STR, ...) \
do { \
if (!(cond)) \
libspl_assertf( "unknown", __FUNCTION__, __LINE__, \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
"%s " STR, #cond, \
__VA_ARGS__); \
} while (0)

#define verify(cond) \
(void) ((!(cond)) && \
libspl_assert(#cond, "unknown", __FUNCTION__, __LINE__))

#define PANIC(fmt, a...) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, fmt, ## a)
libspl_assert(#cond, __FILE__, __FUNCTION__, __LINE__))

#define VERIFY3B(LEFT, OP, RIGHT) \
do { \
const boolean_t __left = (boolean_t)(LEFT); \
const boolean_t __right = (boolean_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
"%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
} while (0)
Expand All @@ -143,7 +239,7 @@ do { \
const int64_t __left = (int64_t)(LEFT); \
const int64_t __right = (int64_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
"%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
} while (0)
Expand All @@ -153,7 +249,7 @@ do { \
const uint64_t __left = (uint64_t)(LEFT); \
const uint64_t __right = (uint64_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
"%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
} while (0)
Expand All @@ -163,7 +259,7 @@ do { \
const uintptr_t __left = (uintptr_t)(LEFT); \
const uintptr_t __right = (uintptr_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
"%s %s %s (%p %s %p)", #LEFT, #OP, #RIGHT, \
(void *)__left, #OP, (void *)__right); \
} while (0)
Expand All @@ -172,7 +268,7 @@ do { \
do { \
const uint64_t __left = (uint64_t)(LEFT); \
if (!(__left == 0)) \
libspl_assertf("unknown", __FUNCTION__, __LINE__, \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
"%s == 0 (0x%llx == 0)", #LEFT, \
(u_longlong_t)__left); \
} while (0)
Expand Down Expand Up @@ -258,8 +354,8 @@ do { \
"%s == 0 (%p == 0) " STR, #LEFT, \
(u_longlong_t)__left, __VA_ARGS__); \
} while (0)
#endif

#endif
#ifdef assert
#undef assert
#endif
Expand Down Expand Up @@ -308,11 +404,11 @@ do { \
#define IMPLY(A, B) \
((void)(((!(A)) || (B)) || \
libspl_assert("(" #A ") implies (" #B ")", \
"unknown", __FUNCTION__, __LINE__)))
__FILE__, __FUNCTION__, __LINE__)))
#define EQUIV(A, B) \
((void)((!!(A) == !!(B)) || \
libspl_assert("(" #A ") is equivalent to (" #B ")", \
"unknown", __FUNCTION__, __LINE__)))
__FILE__, __FUNCTION__, __LINE__)))

#endif /* NDEBUG */

Expand Down

0 comments on commit 27052a0

Please sign in to comment.