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 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // TODO(ajm): Ideally, checks.h would be combined with logging.h, but | 76 // TODO(ajm): Ideally, checks.h would be combined with logging.h, but |
77 // consolidation with system_wrappers/logging.h should happen first. | 77 // consolidation with system_wrappers/logging.h should happen first. |
78 | 78 |
79 namespace rtc { | 79 namespace rtc { |
80 | 80 |
81 // Helper macro which avoids evaluating the arguments to a stream if | 81 // Helper macro which avoids evaluating the arguments to a stream if |
82 // the condition doesn't hold. | 82 // the condition doesn't hold. |
83 #define RTC_LAZY_STREAM(stream, condition) \ | 83 #define RTC_LAZY_STREAM(stream, condition) \ |
84 !(condition) ? static_cast<void>(0) : rtc::FatalMessageVoidify() & (stream) | 84 !(condition) ? static_cast<void>(0) : rtc::FatalMessageVoidify() & (stream) |
85 | 85 |
86 // The actual stream used isn't important. We reference condition in the code | 86 // The actual stream used isn't important. We reference |ignored| in the code |
87 // 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 |
88 // 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 |
89 // the simplest construct that keeps Visual Studio from complaining about | 89 // the simplest construct that keeps Visual Studio from complaining about |
90 // condition being unused). | 90 // condition being unused). |
91 #define RTC_EAT_STREAM_PARAMETERS(condition) \ | 91 #define RTC_EAT_STREAM_PARAMETERS(ignored) \ |
92 (true ? true : !(condition)) \ | 92 (true ? true : ((void)(ignored), true)) \ |
93 ? static_cast<void>(0) \ | 93 ? static_cast<void>(0) \ |
94 : rtc::FatalMessageVoidify() & rtc::FatalMessage("", 0).stream() | 94 : rtc::FatalMessageVoidify() & rtc::FatalMessage("", 0).stream() |
95 | 95 |
| 96 // Call RTC_EAT_STREAM_PARAMETERS with an argument that fails to compile if |
| 97 // values of the same types as |a| and |b| can't be compared with the given |
| 98 // operation, and that would evaluate |a| and |b| if evaluated. |
| 99 #define RTC_EAT_STREAM_PARAMETERS_OP(op, a, b) \ |
| 100 RTC_EAT_STREAM_PARAMETERS(((void)sizeof(std::declval<decltype(a)>() \ |
| 101 op std::declval<decltype(b)>()), \ |
| 102 (void)(a), (void)(b))) |
| 103 |
96 // RTC_CHECK dies with a fatal error if condition is not true. It is *not* | 104 // RTC_CHECK dies with a fatal error if condition is not true. It is *not* |
97 // controlled by NDEBUG or anything else, so the check will be executed | 105 // controlled by NDEBUG or anything else, so the check will be executed |
98 // regardless of compilation mode. | 106 // regardless of compilation mode. |
99 // | 107 // |
100 // We make sure RTC_CHECK et al. always evaluates their arguments, as | 108 // We make sure RTC_CHECK et al. always evaluates their arguments, as |
101 // doing RTC_CHECK(FunctionWithSideEffect()) is a common idiom. | 109 // doing RTC_CHECK(FunctionWithSideEffect()) is a common idiom. |
102 #define RTC_CHECK(condition) \ | 110 #define RTC_CHECK(condition) \ |
103 RTC_LAZY_STREAM(rtc::FatalMessage(__FILE__, __LINE__).stream(), \ | 111 RTC_LAZY_STREAM(rtc::FatalMessage(__FILE__, __LINE__).stream(), \ |
104 !(condition)) \ | 112 !(condition)) \ |
105 << "Check failed: " #condition << std::endl << "# " | 113 << "Check failed: " #condition << std::endl << "# " |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 #if RTC_DCHECK_IS_ON | 194 #if RTC_DCHECK_IS_ON |
187 #define RTC_DCHECK(condition) RTC_CHECK(condition) | 195 #define RTC_DCHECK(condition) RTC_CHECK(condition) |
188 #define RTC_DCHECK_EQ(v1, v2) RTC_CHECK_EQ(v1, v2) | 196 #define RTC_DCHECK_EQ(v1, v2) RTC_CHECK_EQ(v1, v2) |
189 #define RTC_DCHECK_NE(v1, v2) RTC_CHECK_NE(v1, v2) | 197 #define RTC_DCHECK_NE(v1, v2) RTC_CHECK_NE(v1, v2) |
190 #define RTC_DCHECK_LE(v1, v2) RTC_CHECK_LE(v1, v2) | 198 #define RTC_DCHECK_LE(v1, v2) RTC_CHECK_LE(v1, v2) |
191 #define RTC_DCHECK_LT(v1, v2) RTC_CHECK_LT(v1, v2) | 199 #define RTC_DCHECK_LT(v1, v2) RTC_CHECK_LT(v1, v2) |
192 #define RTC_DCHECK_GE(v1, v2) RTC_CHECK_GE(v1, v2) | 200 #define RTC_DCHECK_GE(v1, v2) RTC_CHECK_GE(v1, v2) |
193 #define RTC_DCHECK_GT(v1, v2) RTC_CHECK_GT(v1, v2) | 201 #define RTC_DCHECK_GT(v1, v2) RTC_CHECK_GT(v1, v2) |
194 #else | 202 #else |
195 #define RTC_DCHECK(condition) RTC_EAT_STREAM_PARAMETERS(condition) | 203 #define RTC_DCHECK(condition) RTC_EAT_STREAM_PARAMETERS(condition) |
196 #define RTC_DCHECK_EQ(v1, v2) RTC_EAT_STREAM_PARAMETERS((v1) == (v2)) | 204 #define RTC_DCHECK_EQ(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(==, v1, v2) |
197 #define RTC_DCHECK_NE(v1, v2) RTC_EAT_STREAM_PARAMETERS((v1) != (v2)) | 205 #define RTC_DCHECK_NE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(!=, v1, v2) |
198 #define RTC_DCHECK_LE(v1, v2) RTC_EAT_STREAM_PARAMETERS((v1) <= (v2)) | 206 #define RTC_DCHECK_LE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(<=, v1, v2) |
199 #define RTC_DCHECK_LT(v1, v2) RTC_EAT_STREAM_PARAMETERS((v1) < (v2)) | 207 #define RTC_DCHECK_LT(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(<, v1, v2) |
200 #define RTC_DCHECK_GE(v1, v2) RTC_EAT_STREAM_PARAMETERS((v1) >= (v2)) | 208 #define RTC_DCHECK_GE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(>=, v1, v2) |
201 #define RTC_DCHECK_GT(v1, v2) RTC_EAT_STREAM_PARAMETERS((v1) > (v2)) | 209 #define RTC_DCHECK_GT(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(>, v1, v2) |
202 #endif | 210 #endif |
203 | 211 |
204 // This is identical to LogMessageVoidify but in name. | 212 // This is identical to LogMessageVoidify but in name. |
205 class FatalMessageVoidify { | 213 class FatalMessageVoidify { |
206 public: | 214 public: |
207 FatalMessageVoidify() { } | 215 FatalMessageVoidify() { } |
208 // This has to be an operator with a precedence lower than << but | 216 // This has to be an operator with a precedence lower than << but |
209 // higher than ?: | 217 // higher than ?: |
210 void operator&(std::ostream&) { } | 218 void operator&(std::ostream&) { } |
211 }; | 219 }; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 #define RTC_DCHECK_EQ(a, b) RTC_DCHECK((a) == (b)) | 281 #define RTC_DCHECK_EQ(a, b) RTC_DCHECK((a) == (b)) |
274 #define RTC_DCHECK_NE(a, b) RTC_DCHECK((a) != (b)) | 282 #define RTC_DCHECK_NE(a, b) RTC_DCHECK((a) != (b)) |
275 #define RTC_DCHECK_LE(a, b) RTC_DCHECK((a) <= (b)) | 283 #define RTC_DCHECK_LE(a, b) RTC_DCHECK((a) <= (b)) |
276 #define RTC_DCHECK_LT(a, b) RTC_DCHECK((a) < (b)) | 284 #define RTC_DCHECK_LT(a, b) RTC_DCHECK((a) < (b)) |
277 #define RTC_DCHECK_GE(a, b) RTC_DCHECK((a) >= (b)) | 285 #define RTC_DCHECK_GE(a, b) RTC_DCHECK((a) >= (b)) |
278 #define RTC_DCHECK_GT(a, b) RTC_DCHECK((a) > (b)) | 286 #define RTC_DCHECK_GT(a, b) RTC_DCHECK((a) > (b)) |
279 | 287 |
280 #endif // __cplusplus | 288 #endif // __cplusplus |
281 | 289 |
282 #endif // WEBRTC_BASE_CHECKS_H_ | 290 #endif // WEBRTC_BASE_CHECKS_H_ |
OLD | NEW |