10 # define __STRING(x) #x
13 #elif defined(__FreeBSD__)
14 #include <sys/cdefs.h>
15 #define __GNUC_PREREQ(minor, major) __GNUC_PREREQ__(minor, major)
16 #elif defined(__sun) || defined(_AIX)
17 #include "include/compat.h"
22 # include "acconfig.h"
34 * For GNU, test specific version features. Otherwise (e.g. LLVM) we'll use
35 * the defaults selected below.
40 * Version 2.4 and later of GCC define a magical variable
41 * `__PRETTY_FUNCTION__' which contains the name of the function currently
42 * being defined. This is broken in G++ before version 2.6. C9x has a
43 * similar variable called __func__, but prefer the GCC one since it demangles
44 * C++ function names. We define __CEPH_NO_PRETTY_FUNC if we want to avoid
45 * broken versions of G++.
47 # if defined __cplusplus ? !__GNUC_PREREQ (2, 6) : !__GNUC_PREREQ (2, 4)
48 # define __CEPH_NO_PRETTY_FUNC
54 * Select a function-name variable based on compiler tests, and any compiler
57 #if defined(HAVE_PRETTY_FUNC) && !defined(__CEPH_NO_PRETTY_FUNC)
58 # define __CEPH_ASSERT_FUNCTION __PRETTY_FUNCTION__
59 #elif defined(HAVE_FUNC)
60 # define __CEPH_ASSERT_FUNCTION __func__
62 # define __CEPH_ASSERT_FUNCTION ((__const char *) 0)
66 extern void register_assert_context(CephContext *cct);
69 extern void __ceph_assert_fail(const char *assertion, const char *file, int line, const char *function)
70 __attribute__ ((__noreturn__));
71 extern void __ceph_assertf_fail(const char *assertion, const char *file, int line, const char *function, const char* msg, ...)
72 __attribute__ ((__noreturn__));
73 extern void __ceph_assert_warn(const char *assertion, const char *file, int line, const char *function);
76 # define _CEPH_ASSERT_VOID_CAST static_cast<void>
78 # define _CEPH_ASSERT_VOID_CAST (void)
81 #define assert_warn(expr) \
83 ? _CEPH_ASSERT_VOID_CAST (0) \
84 : __ceph_assert_warn (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION))
94 * ceph_abort aborts the program with a nice backtrace.
96 * Currently, it's the same as assert(0), but we may one day make assert a
97 * debug-only thing, like it is in many projects.
99 #define ceph_abort() abort()
101 #define ceph_abort_msg(cct, msg) { \
102 lgeneric_derr(cct) << "abort: " << msg << dendl; \
108 // wipe any prior assert definition
113 // make _ASSERT_H something that *must* have a value other than what
114 // /usr/include/assert.h gives it (nothing!), so that we detect when
115 // our assert is clobbered.
117 #define _ASSERT_H _dout_cct
119 // make __ASSERT_FUNCTION empty (/usr/include/assert.h makes it a function)
120 // and make our encoding macros break if it non-empty.
121 #undef __ASSERT_FUNCTION
122 #define __ASSERT_FUNCTION
124 #define assert(expr) \
126 ? _CEPH_ASSERT_VOID_CAST (0) \
127 : __ceph_assert_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION))
128 #define ceph_assert(expr) \
130 ? _CEPH_ASSERT_VOID_CAST (0) \
131 : __ceph_assert_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION))
133 // this variant will *never* get compiled out to NDEBUG in the future.
134 // (ceph_assert currently doesn't either, but in the future it might.)
135 #define ceph_assert_always(expr) \
137 ? _CEPH_ASSERT_VOID_CAST (0) \
138 : __ceph_assert_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION))
140 // Named by analogy with printf. Along with an expression, takes a format
141 // string and parameters which are printed if the assertion fails.
142 #define assertf(expr, ...) \
144 ? _CEPH_ASSERT_VOID_CAST (0) \
145 : __ceph_assertf_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION, __VA_ARGS__))
146 #define ceph_assertf(expr, ...) \
148 ? _CEPH_ASSERT_VOID_CAST (0) \
149 : __ceph_assertf_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION, __VA_ARGS__))
151 // this variant will *never* get compiled out to NDEBUG in the future.
152 // (ceph_assertf currently doesn't either, but in the future it might.)
153 #define ceph_assertf_always(expr, ...) \
155 ? _CEPH_ASSERT_VOID_CAST (0) \
156 : __ceph_assertf_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION, __VA_ARGS__))