Skip to content

Commit

Permalink
Merge pull request #9969 from liewegas/wip-assert
Browse files Browse the repository at this point in the history
include/assert: clean up ceph assertion macros

Reviewed-by: Greg Farnum <gfarnum@redhat.com>
  • Loading branch information
tchaikov committed Jul 4, 2016
2 parents a758a02 + 59ddf4d commit c5d50ca
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions src/include/assert.h
@@ -1,6 +1,8 @@
#ifndef CEPH_ASSERT_H
#define CEPH_ASSERT_H

#include <stdlib.h>

#if defined(__linux__)
#include <features.h>

Expand Down Expand Up @@ -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
}

Expand All @@ -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

Expand All @@ -141,10 +124,32 @@ 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.
#define assertf(expr, ...) \
((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__))

0 comments on commit c5d50ca

Please sign in to comment.