diff --git a/src/include/assert.h b/src/include/assert.h index 94f9d7407c755..481f8bacfb3ee 100644 --- a/src/include/assert.h +++ b/src/include/assert.h @@ -1,6 +1,8 @@ #ifndef CEPH_ASSERT_H #define CEPH_ASSERT_H +#include + #if defined(__linux__) #include @@ -74,36 +76,12 @@ extern void __ceph_assertf_fail(const char *assertion, const char *file, int lin __attribute__ ((__noreturn__)); extern void __ceph_assert_warn(const char *assertion, const char *file, int line, const char *function); -#define ceph_assert(expr) \ - ((expr) \ - ? __CEPH_ASSERT_VOID_CAST (0) \ - : __ceph_assert_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION)) #define assert_warn(expr) \ ((expr) \ ? __CEPH_ASSERT_VOID_CAST (0) \ : __ceph_assert_warn (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION)) -/* -#define assert(expr) \ - do { \ - static int __assert_flag = 0; \ - struct TlsData *tls = tls_get_val(); \ - if (!__assert_flag && tls && tls->disable_assert) { \ - __assert_flag = 1; \ - __ceph_assert_warn(__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION); \ - } \ - ((expr) \ - ? __CEPH_ASSERT_VOID_CAST (0) \ - : __ceph_assert_fail (__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION)); \ - } while (0) -#endif -*/ -/* -#define assert_protocol(expr) assert(expr) -#define assert_disk(expr) assert(expr) -*/ - #ifdef __cplusplus } @@ -117,7 +95,12 @@ using namespace ceph; * Currently, it's the same as assert(0), but we may one day make assert a * debug-only thing, like it is in many projects. */ -#define ceph_abort() assert(0) +#define ceph_abort() abort() + +#define ceph_abort_msg(cct, msg) { \ + lgeneric_derr(cct) << "abort: " << msg << dendl; \ + abort(); \ + } #endif @@ -141,6 +124,17 @@ using namespace ceph; ((expr) \ ? __CEPH_ASSERT_VOID_CAST (0) \ : __ceph_assert_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION)) +#define ceph_assert(expr) \ + ((expr) \ + ? __CEPH_ASSERT_VOID_CAST (0) \ + : __ceph_assert_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION)) + +// this variant will *never* get compiled out to NDEBUG in the future. +// (ceph_assert currently doesn't either, but in the future it might.) +#define ceph_assert_always(expr) \ + ((expr) \ + ? __CEPH_ASSERT_VOID_CAST (0) \ + : __ceph_assert_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION)) // Named by analogy with printf. Along with an expression, takes a format // string and parameters which are printed if the assertion fails. @@ -148,3 +142,14 @@ using namespace ceph; ((expr) \ ? __CEPH_ASSERT_VOID_CAST (0) \ : __ceph_assertf_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION, __VA_ARGS__)) +#define ceph_assertf(expr, ...) \ + ((expr) \ + ? __CEPH_ASSERT_VOID_CAST (0) \ + : __ceph_assertf_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION, __VA_ARGS__)) + +// this variant will *never* get compiled out to NDEBUG in the future. +// (ceph_assertf currently doesn't either, but in the future it might.) +#define ceph_assertf_always(expr, ...) \ + ((expr) \ + ? __CEPH_ASSERT_VOID_CAST (0) \ + : __ceph_assertf_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION, __VA_ARGS__))