-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert.h
More file actions
148 lines (121 loc) · 4.13 KB
/
Copy pathassert.h
File metadata and controls
148 lines (121 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifndef CEPH_ASSERT_H
#define CEPH_ASSERT_H
#if defined(__linux__)
#include <features.h>
#elif defined(__FreeBSD__)
#include <sys/cdefs.h>
#define __GNUC_PREREQ(minor, major) __GNUC_PREREQ__(minor, major)
#endif
#ifdef __CEPH__
# include "acconfig.h"
#endif
class CephContext;
#ifdef __cplusplus
namespace ceph {
struct BackTrace;
struct FailedAssertion {
BackTrace *backtrace;
FailedAssertion(BackTrace *bt) : backtrace(bt) {}
};
#endif
#ifdef HAVE_STATIC_CAST
# define __CEPH_ASSERT_VOID_CAST static_cast<void>
#else
# define __CEPH_ASSERT_VOID_CAST (void)
#endif
/*
* For GNU, test specific version features. Otherwise (e.g. LLVM) we'll use
* the defaults selected below.
*/
#ifdef __GNUC_PREREQ
/*
* Version 2.4 and later of GCC define a magical variable
* `__PRETTY_FUNCTION__' which contains the name of the function currently
* being defined. This is broken in G++ before version 2.6. C9x has a
* similar variable called __func__, but prefer the GCC one since it demangles
* C++ function names. We define __CEPH_NO_PRETTY_FUNC if we want to avoid
* broken versions of G++.
*/
# if defined __cplusplus ? !__GNUC_PREREQ (2, 6) : !__GNUC_PREREQ (2, 4)
# define __CEPH_NO_PRETTY_FUNC
# endif
#endif
/*
* Select a function-name variable based on compiler tests, and any compiler
* specific overrides.
*/
#if defined(HAVE_PRETTY_FUNC) && !defined(__CEPH_NO_PRETTY_FUNC)
# define __CEPH_ASSERT_FUNCTION __PRETTY_FUNCTION__
#elif defined(HAVE_FUNC)
# define __CEPH_ASSERT_FUNCTION __func__
#else
# define __CEPH_ASSERT_FUNCTION ((__const char *) 0)
#endif
extern void register_assert_context(CephContext *cct);
extern void __ceph_assert_fail(const char *assertion, const char *file, int line, const char *function)
__attribute__ ((__noreturn__));
extern void __ceph_assertf_fail(const char *assertion, const char *file, int line, const char *function, const char* msg, ...)
__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
}
using namespace ceph;
#endif
/*
* ceph_abort aborts the program with a nice backtrace.
*
* 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)
#endif
// wipe any prior assert definition
#ifdef assert
# undef assert
#endif
// make _ASSERT_H something that *must* have a value other than what
// /usr/include/assert.h gives it (nothing!), so that we detect when
// our assert is clobbered.
#undef _ASSERT_H
#define _ASSERT_H _dout_cct
// make __ASSERT_FUNCTION empty (/usr/include/assert.h makes it a function)
// and make our encoding macros break if it non-empty.
#undef __ASSERT_FUNCTION
#define __ASSERT_FUNCTION
#define assert(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__))