Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include/assert: clean up ceph assertion macros #9969

Merged
merged 5 commits into from Jul 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with how our current asserts work with debug that lets them be disabled or not. Can we do something to make sure the tooling is set up properly right now, which guarantees ceph_assert_always really does get compiled in?

Copy link
Member Author

@liewegas liewegas Jun 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ours aren't conditional (yet)... It's the lack of an #ifdef NDEBUG where this comment goes that prevents it from compiling out. And/or the lack of a similar comment says "do not ever compile this out" next to the ceph_assert definition a few lines up.

#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__))