henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef RTC_BASE_CHECKS_H_ |
| 12 | #define RTC_BASE_CHECKS_H_ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 13 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 14 | // If you for some reson need to know if DCHECKs are on, test the value of |
| 15 | // RTC_DCHECK_IS_ON. (Test its value, not if it's defined; it'll always be |
| 16 | // defined, to either a true or a false value.) |
| 17 | #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
| 18 | #define RTC_DCHECK_IS_ON 1 |
| 19 | #else |
| 20 | #define RTC_DCHECK_IS_ON 0 |
| 21 | #endif |
| 22 | |
Fredrik Solenberg | 500e75b | 2018-05-23 11:49:01 +0200 | [diff] [blame] | 23 | // Annotate a function that will not return control flow to the caller. |
| 24 | #if defined(_MSC_VER) |
| 25 | #define RTC_NORETURN __declspec(noreturn) |
| 26 | #elif defined(__GNUC__) |
| 27 | #define RTC_NORETURN __attribute__ ((__noreturn__)) |
| 28 | #else |
| 29 | #define RTC_NORETURN |
| 30 | #endif |
| 31 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
Fredrik Solenberg | 500e75b | 2018-05-23 11:49:01 +0200 | [diff] [blame] | 35 | RTC_NORETURN void rtc_FatalMessage(const char* file, int line, const char* msg); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 36 | #ifdef __cplusplus |
| 37 | } // extern "C" |
| 38 | #endif |
| 39 | |
| 40 | #ifdef __cplusplus |
| 41 | // C++ version. |
| 42 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 43 | #include <string> |
| 44 | |
Karl Wiberg | e40468b | 2017-11-22 10:42:26 +0100 | [diff] [blame] | 45 | #include "rtc_base/numerics/safe_compare.h" |
Jonas Olsson | f8e5c11 | 2018-06-14 13:14:22 +0200 | [diff] [blame] | 46 | #include "rtc_base/system/inline.h" |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 47 | |
| 48 | // The macros here print a message to stderr and abort under various |
| 49 | // conditions. All will accept additional stream messages. For example: |
| 50 | // RTC_DCHECK_EQ(foo, bar) << "I'm printed when foo != bar."; |
| 51 | // |
| 52 | // - RTC_CHECK(x) is an assertion that x is always true, and that if it isn't, |
| 53 | // it's better to terminate the process than to continue. During development, |
| 54 | // the reason that it's better to terminate might simply be that the error |
| 55 | // handling code isn't in place yet; in production, the reason might be that |
| 56 | // the author of the code truly believes that x will always be true, but that |
| 57 | // she recognizes that if she is wrong, abrupt and unpleasant process |
| 58 | // termination is still better than carrying on with the assumption violated. |
| 59 | // |
| 60 | // RTC_CHECK always evaluates its argument, so it's OK for x to have side |
| 61 | // effects. |
| 62 | // |
| 63 | // - RTC_DCHECK(x) is the same as RTC_CHECK(x)---an assertion that x is always |
| 64 | // true---except that x will only be evaluated in debug builds; in production |
| 65 | // builds, x is simply assumed to be true. This is useful if evaluating x is |
| 66 | // expensive and the expected cost of failing to detect the violated |
| 67 | // assumption is acceptable. You should not handle cases where a production |
| 68 | // build fails to spot a violated condition, even those that would result in |
| 69 | // crashes. If the code needs to cope with the error, make it cope, but don't |
| 70 | // call RTC_DCHECK; if the condition really can't occur, but you'd sleep |
| 71 | // better at night knowing that the process will suicide instead of carrying |
| 72 | // on in case you were wrong, use RTC_CHECK instead of RTC_DCHECK. |
| 73 | // |
| 74 | // RTC_DCHECK only evaluates its argument in debug builds, so if x has visible |
| 75 | // side effects, you need to write e.g. |
| 76 | // bool w = x; RTC_DCHECK(w); |
| 77 | // |
| 78 | // - RTC_CHECK_EQ, _NE, _GT, ..., and RTC_DCHECK_EQ, _NE, _GT, ... are |
| 79 | // specialized variants of RTC_CHECK and RTC_DCHECK that print prettier |
| 80 | // messages if the condition doesn't hold. Prefer them to raw RTC_CHECK and |
| 81 | // RTC_DCHECK. |
| 82 | // |
| 83 | // - FATAL() aborts unconditionally. |
| 84 | // |
| 85 | // TODO(ajm): Ideally, checks.h would be combined with logging.h, but |
| 86 | // consolidation with system_wrappers/logging.h should happen first. |
| 87 | |
| 88 | namespace rtc { |
Jonas Olsson | f8e5c11 | 2018-06-14 13:14:22 +0200 | [diff] [blame] | 89 | namespace webrtc_checks_impl { |
| 90 | enum class CheckArgType : int8_t { |
| 91 | kEnd = 0, |
| 92 | kInt, |
| 93 | kLong, |
| 94 | kLongLong, |
| 95 | kUInt, |
| 96 | kULong, |
| 97 | kULongLong, |
| 98 | kDouble, |
| 99 | kLongDouble, |
| 100 | kCharP, |
| 101 | kStdString, |
| 102 | kVoidP, |
Jonas Olsson | d000b0a | 2018-07-03 12:07:53 +0200 | [diff] [blame] | 103 | |
| 104 | // kCheckOp doesn't represent an argument type. Instead, it is sent as the |
| 105 | // first argument from RTC_CHECK_OP to make FatalLog use the next two |
| 106 | // arguments to build the special CHECK_OP error message |
| 107 | // (the "a == b (1 vs. 2)" bit). |
| 108 | kCheckOp, |
Jonas Olsson | f8e5c11 | 2018-06-14 13:14:22 +0200 | [diff] [blame] | 109 | }; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 110 | |
Jonas Olsson | f8e5c11 | 2018-06-14 13:14:22 +0200 | [diff] [blame] | 111 | RTC_NORETURN void FatalLog(const char* file, |
| 112 | int line, |
| 113 | const char* message, |
| 114 | const CheckArgType* fmt, |
| 115 | ...); |
| 116 | |
| 117 | // Wrapper for log arguments. Only ever make values of this type with the |
| 118 | // MakeVal() functions. |
| 119 | template <CheckArgType N, typename T> |
| 120 | struct Val { |
| 121 | static constexpr CheckArgType Type() { return N; } |
| 122 | T GetVal() const { return val; } |
| 123 | T val; |
| 124 | }; |
| 125 | |
| 126 | inline Val<CheckArgType::kInt, int> MakeVal(int x) { |
| 127 | return {x}; |
| 128 | } |
| 129 | inline Val<CheckArgType::kLong, long> MakeVal(long x) { |
| 130 | return {x}; |
| 131 | } |
| 132 | inline Val<CheckArgType::kLongLong, long long> MakeVal(long long x) { |
| 133 | return {x}; |
| 134 | } |
| 135 | inline Val<CheckArgType::kUInt, unsigned int> MakeVal(unsigned int x) { |
| 136 | return {x}; |
| 137 | } |
| 138 | inline Val<CheckArgType::kULong, unsigned long> MakeVal(unsigned long x) { |
| 139 | return {x}; |
| 140 | } |
| 141 | inline Val<CheckArgType::kULongLong, unsigned long long> MakeVal( |
| 142 | unsigned long long x) { |
| 143 | return {x}; |
| 144 | } |
| 145 | |
| 146 | inline Val<CheckArgType::kDouble, double> MakeVal(double x) { |
| 147 | return {x}; |
| 148 | } |
| 149 | inline Val<CheckArgType::kLongDouble, long double> MakeVal(long double x) { |
| 150 | return {x}; |
| 151 | } |
| 152 | |
| 153 | inline Val<CheckArgType::kCharP, const char*> MakeVal(const char* x) { |
| 154 | return {x}; |
| 155 | } |
| 156 | inline Val<CheckArgType::kStdString, const std::string*> MakeVal( |
| 157 | const std::string& x) { |
| 158 | return {&x}; |
| 159 | } |
| 160 | |
| 161 | inline Val<CheckArgType::kVoidP, const void*> MakeVal(const void* x) { |
| 162 | return {x}; |
| 163 | } |
| 164 | |
| 165 | // Ephemeral type that represents the result of the logging << operator. |
| 166 | template <typename... Ts> |
| 167 | class LogStreamer; |
| 168 | |
| 169 | // Base case: Before the first << argument. |
| 170 | template <> |
| 171 | class LogStreamer<> final { |
| 172 | public: |
| 173 | template < |
| 174 | typename U, |
| 175 | typename std::enable_if<std::is_arithmetic<U>::value>::type* = nullptr> |
| 176 | RTC_FORCE_INLINE LogStreamer<decltype(MakeVal(std::declval<U>()))> operator<<( |
| 177 | U arg) const { |
| 178 | return LogStreamer<decltype(MakeVal(std::declval<U>()))>(MakeVal(arg), |
| 179 | this); |
| 180 | } |
| 181 | |
| 182 | template < |
| 183 | typename U, |
| 184 | typename std::enable_if<!std::is_arithmetic<U>::value>::type* = nullptr> |
| 185 | RTC_FORCE_INLINE LogStreamer<decltype(MakeVal(std::declval<U>()))> operator<<( |
| 186 | const U& arg) const { |
| 187 | return LogStreamer<decltype(MakeVal(std::declval<U>()))>(MakeVal(arg), |
| 188 | this); |
| 189 | } |
| 190 | |
| 191 | template <typename... Us> |
| 192 | RTC_NORETURN RTC_FORCE_INLINE static void Call(const char* file, |
| 193 | const int line, |
| 194 | const char* message, |
| 195 | const Us&... args) { |
| 196 | static constexpr CheckArgType t[] = {Us::Type()..., CheckArgType::kEnd}; |
| 197 | FatalLog(file, line, message, t, args.GetVal()...); |
| 198 | } |
Jonas Olsson | d000b0a | 2018-07-03 12:07:53 +0200 | [diff] [blame] | 199 | |
| 200 | template <typename... Us> |
| 201 | RTC_NORETURN RTC_FORCE_INLINE static void CallCheckOp(const char* file, |
| 202 | const int line, |
| 203 | const char* message, |
| 204 | const Us&... args) { |
| 205 | static constexpr CheckArgType t[] = {CheckArgType::kCheckOp, Us::Type()..., |
| 206 | CheckArgType::kEnd}; |
| 207 | FatalLog(file, line, message, t, args.GetVal()...); |
| 208 | } |
Jonas Olsson | f8e5c11 | 2018-06-14 13:14:22 +0200 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | // Inductive case: We've already seen at least one << argument. The most recent |
| 212 | // one had type `T`, and the earlier ones had types `Ts`. |
| 213 | template <typename T, typename... Ts> |
| 214 | class LogStreamer<T, Ts...> final { |
| 215 | public: |
| 216 | RTC_FORCE_INLINE LogStreamer(T arg, const LogStreamer<Ts...>* prior) |
| 217 | : arg_(arg), prior_(prior) {} |
| 218 | |
| 219 | template < |
| 220 | typename U, |
| 221 | typename std::enable_if<std::is_arithmetic<U>::value>::type* = nullptr> |
| 222 | RTC_FORCE_INLINE LogStreamer<decltype(MakeVal(std::declval<U>())), T, Ts...> |
| 223 | operator<<(U arg) const { |
| 224 | return LogStreamer<decltype(MakeVal(std::declval<U>())), T, Ts...>( |
| 225 | MakeVal(arg), this); |
| 226 | } |
| 227 | |
| 228 | template < |
| 229 | typename U, |
| 230 | typename std::enable_if<!std::is_arithmetic<U>::value>::type* = nullptr> |
| 231 | RTC_FORCE_INLINE LogStreamer<decltype(MakeVal(std::declval<U>())), T, Ts...> |
| 232 | operator<<(const U& arg) const { |
| 233 | return LogStreamer<decltype(MakeVal(std::declval<U>())), T, Ts...>( |
| 234 | MakeVal(arg), this); |
| 235 | } |
| 236 | |
| 237 | template <typename... Us> |
| 238 | RTC_NORETURN RTC_FORCE_INLINE void Call(const char* file, |
| 239 | const int line, |
| 240 | const char* message, |
| 241 | const Us&... args) const { |
| 242 | prior_->Call(file, line, message, arg_, args...); |
| 243 | } |
| 244 | |
Jonas Olsson | d000b0a | 2018-07-03 12:07:53 +0200 | [diff] [blame] | 245 | template <typename... Us> |
| 246 | RTC_NORETURN RTC_FORCE_INLINE void CallCheckOp(const char* file, |
| 247 | const int line, |
| 248 | const char* message, |
| 249 | const Us&... args) const { |
| 250 | prior_->CallCheckOp(file, line, message, arg_, args...); |
| 251 | } |
| 252 | |
Jonas Olsson | f8e5c11 | 2018-06-14 13:14:22 +0200 | [diff] [blame] | 253 | private: |
| 254 | // The most recent argument. |
| 255 | T arg_; |
| 256 | |
| 257 | // Earlier arguments. |
| 258 | const LogStreamer<Ts...>* prior_; |
| 259 | }; |
| 260 | |
Jonas Olsson | d000b0a | 2018-07-03 12:07:53 +0200 | [diff] [blame] | 261 | template <bool isCheckOp> |
Jonas Olsson | f8e5c11 | 2018-06-14 13:14:22 +0200 | [diff] [blame] | 262 | class FatalLogCall final { |
| 263 | public: |
| 264 | FatalLogCall(const char* file, int line, const char* message) |
| 265 | : file_(file), line_(line), message_(message) {} |
| 266 | |
| 267 | // This can be any binary operator with precedence lower than <<. |
| 268 | template <typename... Ts> |
| 269 | RTC_NORETURN RTC_FORCE_INLINE void operator&( |
| 270 | const LogStreamer<Ts...>& streamer) { |
Jonas Olsson | d000b0a | 2018-07-03 12:07:53 +0200 | [diff] [blame] | 271 | isCheckOp ? streamer.CallCheckOp(file_, line_, message_) |
| 272 | : streamer.Call(file_, line_, message_); |
Jonas Olsson | f8e5c11 | 2018-06-14 13:14:22 +0200 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | private: |
| 276 | const char* file_; |
| 277 | int line_; |
| 278 | const char* message_; |
| 279 | }; |
| 280 | } // namespace webrtc_checks_impl |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 281 | |
| 282 | // The actual stream used isn't important. We reference |ignored| in the code |
| 283 | // but don't evaluate it; this is to avoid "unused variable" warnings (we do so |
| 284 | // in a particularly convoluted way with an extra ?: because that appears to be |
| 285 | // the simplest construct that keeps Visual Studio from complaining about |
| 286 | // condition being unused). |
Jonas Olsson | d000b0a | 2018-07-03 12:07:53 +0200 | [diff] [blame] | 287 | #define RTC_EAT_STREAM_PARAMETERS(ignored) \ |
| 288 | (true ? true : ((void)(ignored), true)) \ |
| 289 | ? static_cast<void>(0) \ |
| 290 | : rtc::webrtc_checks_impl::FatalLogCall<false>("", 0, "") & \ |
Jonas Olsson | f8e5c11 | 2018-06-14 13:14:22 +0200 | [diff] [blame] | 291 | rtc::webrtc_checks_impl::LogStreamer<>() |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 292 | |
| 293 | // Call RTC_EAT_STREAM_PARAMETERS with an argument that fails to compile if |
| 294 | // values of the same types as |a| and |b| can't be compared with the given |
| 295 | // operation, and that would evaluate |a| and |b| if evaluated. |
| 296 | #define RTC_EAT_STREAM_PARAMETERS_OP(op, a, b) \ |
| 297 | RTC_EAT_STREAM_PARAMETERS(((void)rtc::Safe##op(a, b))) |
| 298 | |
| 299 | // RTC_CHECK dies with a fatal error if condition is not true. It is *not* |
| 300 | // controlled by NDEBUG or anything else, so the check will be executed |
| 301 | // regardless of compilation mode. |
| 302 | // |
Jonas Olsson | f8e5c11 | 2018-06-14 13:14:22 +0200 | [diff] [blame] | 303 | // We make sure RTC_CHECK et al. always evaluates |condition|, as |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 304 | // doing RTC_CHECK(FunctionWithSideEffect()) is a common idiom. |
Jonas Olsson | d000b0a | 2018-07-03 12:07:53 +0200 | [diff] [blame] | 305 | #define RTC_CHECK(condition) \ |
| 306 | while (!(condition)) \ |
| 307 | rtc::webrtc_checks_impl::FatalLogCall<false>(__FILE__, __LINE__, \ |
| 308 | #condition) & \ |
Jonas Olsson | f8e5c11 | 2018-06-14 13:14:22 +0200 | [diff] [blame] | 309 | rtc::webrtc_checks_impl::LogStreamer<>() |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 310 | |
| 311 | // Helper macro for binary operators. |
| 312 | // Don't use this macro directly in your code, use RTC_CHECK_EQ et al below. |
Jonas Olsson | d000b0a | 2018-07-03 12:07:53 +0200 | [diff] [blame] | 313 | #define RTC_CHECK_OP(name, op, val1, val2) \ |
| 314 | while (!rtc::Safe##name((val1), (val2))) \ |
| 315 | rtc::webrtc_checks_impl::FatalLogCall<true>(__FILE__, __LINE__, \ |
| 316 | #val1 " " #op " " #val2) & \ |
| 317 | rtc::webrtc_checks_impl::LogStreamer<>() << (val1) << (val2) |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 318 | |
| 319 | #define RTC_CHECK_EQ(val1, val2) RTC_CHECK_OP(Eq, ==, val1, val2) |
| 320 | #define RTC_CHECK_NE(val1, val2) RTC_CHECK_OP(Ne, !=, val1, val2) |
| 321 | #define RTC_CHECK_LE(val1, val2) RTC_CHECK_OP(Le, <=, val1, val2) |
| 322 | #define RTC_CHECK_LT(val1, val2) RTC_CHECK_OP(Lt, <, val1, val2) |
| 323 | #define RTC_CHECK_GE(val1, val2) RTC_CHECK_OP(Ge, >=, val1, val2) |
| 324 | #define RTC_CHECK_GT(val1, val2) RTC_CHECK_OP(Gt, >, val1, val2) |
| 325 | |
| 326 | // The RTC_DCHECK macro is equivalent to RTC_CHECK except that it only generates |
| 327 | // code in debug builds. It does reference the condition parameter in all cases, |
| 328 | // though, so callers won't risk getting warnings about unused variables. |
| 329 | #if RTC_DCHECK_IS_ON |
| 330 | #define RTC_DCHECK(condition) RTC_CHECK(condition) |
| 331 | #define RTC_DCHECK_EQ(v1, v2) RTC_CHECK_EQ(v1, v2) |
| 332 | #define RTC_DCHECK_NE(v1, v2) RTC_CHECK_NE(v1, v2) |
| 333 | #define RTC_DCHECK_LE(v1, v2) RTC_CHECK_LE(v1, v2) |
| 334 | #define RTC_DCHECK_LT(v1, v2) RTC_CHECK_LT(v1, v2) |
| 335 | #define RTC_DCHECK_GE(v1, v2) RTC_CHECK_GE(v1, v2) |
| 336 | #define RTC_DCHECK_GT(v1, v2) RTC_CHECK_GT(v1, v2) |
| 337 | #else |
| 338 | #define RTC_DCHECK(condition) RTC_EAT_STREAM_PARAMETERS(condition) |
| 339 | #define RTC_DCHECK_EQ(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Eq, v1, v2) |
| 340 | #define RTC_DCHECK_NE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Ne, v1, v2) |
| 341 | #define RTC_DCHECK_LE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Le, v1, v2) |
| 342 | #define RTC_DCHECK_LT(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Lt, v1, v2) |
| 343 | #define RTC_DCHECK_GE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Ge, v1, v2) |
| 344 | #define RTC_DCHECK_GT(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Gt, v1, v2) |
| 345 | #endif |
| 346 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 347 | #define RTC_UNREACHABLE_CODE_HIT false |
| 348 | #define RTC_NOTREACHED() RTC_DCHECK(RTC_UNREACHABLE_CODE_HIT) |
| 349 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 350 | // TODO(bugs.webrtc.org/8454): Add an RTC_ prefix or rename differently. |
Jonas Olsson | d000b0a | 2018-07-03 12:07:53 +0200 | [diff] [blame] | 351 | #define FATAL() \ |
| 352 | rtc::webrtc_checks_impl::FatalLogCall<false>(__FILE__, __LINE__, \ |
| 353 | "FATAL()") & \ |
Jonas Olsson | f8e5c11 | 2018-06-14 13:14:22 +0200 | [diff] [blame] | 354 | rtc::webrtc_checks_impl::LogStreamer<>() |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 355 | |
| 356 | // Performs the integer division a/b and returns the result. CHECKs that the |
| 357 | // remainder is zero. |
| 358 | template <typename T> |
| 359 | inline T CheckedDivExact(T a, T b) { |
| 360 | RTC_CHECK_EQ(a % b, 0) << a << " is not evenly divisible by " << b; |
| 361 | return a / b; |
| 362 | } |
| 363 | |
| 364 | } // namespace rtc |
| 365 | |
| 366 | #else // __cplusplus not defined |
| 367 | // C version. Lacks many features compared to the C++ version, but usage |
| 368 | // guidelines are the same. |
| 369 | |
| 370 | #define RTC_CHECK(condition) \ |
| 371 | do { \ |
| 372 | if (!(condition)) { \ |
| 373 | rtc_FatalMessage(__FILE__, __LINE__, "CHECK failed: " #condition); \ |
| 374 | } \ |
| 375 | } while (0) |
| 376 | |
| 377 | #define RTC_CHECK_EQ(a, b) RTC_CHECK((a) == (b)) |
| 378 | #define RTC_CHECK_NE(a, b) RTC_CHECK((a) != (b)) |
| 379 | #define RTC_CHECK_LE(a, b) RTC_CHECK((a) <= (b)) |
| 380 | #define RTC_CHECK_LT(a, b) RTC_CHECK((a) < (b)) |
| 381 | #define RTC_CHECK_GE(a, b) RTC_CHECK((a) >= (b)) |
| 382 | #define RTC_CHECK_GT(a, b) RTC_CHECK((a) > (b)) |
| 383 | |
| 384 | #define RTC_DCHECK(condition) \ |
| 385 | do { \ |
| 386 | if (RTC_DCHECK_IS_ON && !(condition)) { \ |
| 387 | rtc_FatalMessage(__FILE__, __LINE__, "DCHECK failed: " #condition); \ |
| 388 | } \ |
| 389 | } while (0) |
| 390 | |
| 391 | #define RTC_DCHECK_EQ(a, b) RTC_DCHECK((a) == (b)) |
| 392 | #define RTC_DCHECK_NE(a, b) RTC_DCHECK((a) != (b)) |
| 393 | #define RTC_DCHECK_LE(a, b) RTC_DCHECK((a) <= (b)) |
| 394 | #define RTC_DCHECK_LT(a, b) RTC_DCHECK((a) < (b)) |
| 395 | #define RTC_DCHECK_GE(a, b) RTC_DCHECK((a) >= (b)) |
| 396 | #define RTC_DCHECK_GT(a, b) RTC_DCHECK((a) > (b)) |
| 397 | |
| 398 | #endif // __cplusplus |
kwiberg | 2e48646 | 2016-08-23 05:54:25 -0700 | [diff] [blame] | 399 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 400 | #endif // RTC_BASE_CHECKS_H_ |