OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2006 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_BASE_CHECKS_H_ | 11 #ifndef WEBRTC_BASE_CHECKS_H_ |
12 #define WEBRTC_BASE_CHECKS_H_ | 12 #define WEBRTC_BASE_CHECKS_H_ |
13 | 13 |
14 #include "webrtc/typedefs.h" | 14 #include "webrtc/typedefs.h" |
15 | 15 |
16 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) | 16 // If you for some reson need to know if DCHECKs are on, test the value of |
| 17 // RTC_DCHECK_IS_ON. (Test its value, not if it's defined; it'll always be |
| 18 // defined, to either a true or a false value.) |
| 19 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
17 #define RTC_DCHECK_IS_ON 1 | 20 #define RTC_DCHECK_IS_ON 1 |
18 #else | 21 #else |
19 #define RTC_DCHECK_IS_ON 0 | 22 #define RTC_DCHECK_IS_ON 0 |
20 #endif | 23 #endif |
21 | 24 |
22 #ifdef __cplusplus | 25 #ifdef __cplusplus |
23 extern "C" { | 26 extern "C" { |
24 #endif | 27 #endif |
25 NO_RETURN void rtc_FatalMessage(const char* file, int line, const char* msg); | 28 NO_RETURN void rtc_FatalMessage(const char* file, int line, const char* msg); |
26 #ifdef __cplusplus | 29 #ifdef __cplusplus |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // The actual stream used isn't important. We reference condition in the code | 86 // The actual stream used isn't important. We reference condition in the code |
84 // but don't evaluate it; this is to avoid "unused variable" warnings (we do so | 87 // but don't evaluate it; this is to avoid "unused variable" warnings (we do so |
85 // in a particularly convoluted way with an extra ?: because that appears to be | 88 // in a particularly convoluted way with an extra ?: because that appears to be |
86 // the simplest construct that keeps Visual Studio from complaining about | 89 // the simplest construct that keeps Visual Studio from complaining about |
87 // condition being unused). | 90 // condition being unused). |
88 #define RTC_EAT_STREAM_PARAMETERS(condition) \ | 91 #define RTC_EAT_STREAM_PARAMETERS(condition) \ |
89 (true ? true : !(condition)) \ | 92 (true ? true : !(condition)) \ |
90 ? static_cast<void>(0) \ | 93 ? static_cast<void>(0) \ |
91 : rtc::FatalMessageVoidify() & rtc::FatalMessage("", 0).stream() | 94 : rtc::FatalMessageVoidify() & rtc::FatalMessage("", 0).stream() |
92 | 95 |
93 // RTC_CHECK dies with a fatal error if condition is not true. It is *not* | 96 // RTC_CHECK dies with a fatal error if condition is not true. It is *not* |
94 // controlled by NDEBUG, so the check will be executed regardless of | 97 // controlled by NDEBUG or anything else, so the check will be executed |
95 // compilation mode. | 98 // regardless of compilation mode. |
96 // | 99 // |
97 // We make sure RTC_CHECK et al. always evaluates their arguments, as | 100 // We make sure RTC_CHECK et al. always evaluates their arguments, as |
98 // doing RTC_CHECK(FunctionWithSideEffect()) is a common idiom. | 101 // doing RTC_CHECK(FunctionWithSideEffect()) is a common idiom. |
99 #define RTC_CHECK(condition) \ | 102 #define RTC_CHECK(condition) \ |
100 RTC_LAZY_STREAM(rtc::FatalMessage(__FILE__, __LINE__).stream(), \ | 103 RTC_LAZY_STREAM(rtc::FatalMessage(__FILE__, __LINE__).stream(), \ |
101 !(condition)) \ | 104 !(condition)) \ |
102 << "Check failed: " #condition << std::endl << "# " | 105 << "Check failed: " #condition << std::endl << "# " |
103 | 106 |
104 // Helper macro for binary operators. | 107 // Helper macro for binary operators. |
105 // Don't use this macro directly in your code, use RTC_CHECK_EQ et al below. | 108 // Don't use this macro directly in your code, use RTC_CHECK_EQ et al below. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 #define RTC_DCHECK_EQ(a, b) RTC_DCHECK((a) == (b)) | 273 #define RTC_DCHECK_EQ(a, b) RTC_DCHECK((a) == (b)) |
271 #define RTC_DCHECK_NE(a, b) RTC_DCHECK((a) != (b)) | 274 #define RTC_DCHECK_NE(a, b) RTC_DCHECK((a) != (b)) |
272 #define RTC_DCHECK_LE(a, b) RTC_DCHECK((a) <= (b)) | 275 #define RTC_DCHECK_LE(a, b) RTC_DCHECK((a) <= (b)) |
273 #define RTC_DCHECK_LT(a, b) RTC_DCHECK((a) < (b)) | 276 #define RTC_DCHECK_LT(a, b) RTC_DCHECK((a) < (b)) |
274 #define RTC_DCHECK_GE(a, b) RTC_DCHECK((a) >= (b)) | 277 #define RTC_DCHECK_GE(a, b) RTC_DCHECK((a) >= (b)) |
275 #define RTC_DCHECK_GT(a, b) RTC_DCHECK((a) > (b)) | 278 #define RTC_DCHECK_GT(a, b) RTC_DCHECK((a) > (b)) |
276 | 279 |
277 #endif // __cplusplus | 280 #endif // __cplusplus |
278 | 281 |
279 #endif // WEBRTC_BASE_CHECKS_H_ | 282 #endif // WEBRTC_BASE_CHECKS_H_ |
OLD | NEW |