Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: Source/wtf/Assertions.h

Issue 394353002: Replace tests of ASSERT_ENABLED with ENABLE(ASSERT). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 /* Disable ASSERT* macros in release mode. */ 47 /* Disable ASSERT* macros in release mode. */
48 #define ASSERTIONS_DISABLED_DEFAULT 1 48 #define ASSERTIONS_DISABLED_DEFAULT 1
49 #else 49 #else
50 #define ASSERTIONS_DISABLED_DEFAULT 0 50 #define ASSERTIONS_DISABLED_DEFAULT 0
51 #endif 51 #endif
52 52
53 #ifndef BACKTRACE_DISABLED 53 #ifndef BACKTRACE_DISABLED
54 #define BACKTRACE_DISABLED ASSERTIONS_DISABLED_DEFAULT 54 #define BACKTRACE_DISABLED ASSERTIONS_DISABLED_DEFAULT
55 #endif 55 #endif
56 56
57 #ifndef ASSERT_ENABLED 57 // Users must test "#if ENABLE(ASSERT)", which helps ensure that code
Ken Russell (switch to Gerrit) 2014/07/16 22:04:56 The changes in this file were done by hand.
58 // testing this macro has included this header.
59 #ifndef ENABLE_ASSERT
58 // Notice the not below: 60 // Notice the not below:
59 #define ASSERT_ENABLED !ASSERTIONS_DISABLED_DEFAULT 61 #define ENABLE_ASSERT !ASSERTIONS_DISABLED_DEFAULT
60 #endif 62 #endif
61 63
62 #ifndef ASSERT_MSG_DISABLED 64 #ifndef ASSERT_MSG_DISABLED
63 #define ASSERT_MSG_DISABLED ASSERTIONS_DISABLED_DEFAULT 65 #define ASSERT_MSG_DISABLED !ENABLE(ASSERT)
64 #endif 66 #endif
65 67
66 #ifndef ASSERT_ARG_DISABLED 68 #ifndef ASSERT_ARG_DISABLED
67 #define ASSERT_ARG_DISABLED ASSERTIONS_DISABLED_DEFAULT 69 #define ASSERT_ARG_DISABLED !ENABLE(ASSERT)
68 #endif 70 #endif
69 71
70 #ifndef FATAL_DISABLED 72 #ifndef FATAL_DISABLED
71 #define FATAL_DISABLED ASSERTIONS_DISABLED_DEFAULT 73 #define FATAL_DISABLED !ENABLE(ASSERT)
72 #endif 74 #endif
73 75
74 #ifndef ERROR_DISABLED 76 #ifndef ERROR_DISABLED
75 #define ERROR_DISABLED ASSERTIONS_DISABLED_DEFAULT 77 #define ERROR_DISABLED !ENABLE(ASSERT)
76 #endif 78 #endif
77 79
78 #ifndef LOG_DISABLED 80 #ifndef LOG_DISABLED
79 #define LOG_DISABLED ASSERTIONS_DISABLED_DEFAULT 81 #define LOG_DISABLED !ENABLE(ASSERT)
80 #endif 82 #endif
81 83
82 /* WTF logging functions can process %@ in the format string to log a NSObject* but the printf format attribute 84 /* WTF logging functions can process %@ in the format string to log a NSObject* but the printf format attribute
83 emits a warning when %@ is used in the format string. Until <rdar://problem/ 5195437> is resolved we can't include 85 emits a warning when %@ is used in the format string. Until <rdar://problem/ 5195437> is resolved we can't include
84 the attribute when being used from Objective-C code in case it decides to use %@. */ 86 the attribute when being used from Objective-C code in case it decides to use %@. */
85 #if COMPILER(GCC) && !defined(__OBJC__) 87 #if COMPILER(GCC) && !defined(__OBJC__)
86 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) __attribute__ ((__format__(printf, formatStringArgument, extraArguments))) 88 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) __attribute__ ((__format__(printf, formatStringArgument, extraArguments)))
87 #else 89 #else
88 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) 90 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments)
89 #endif 91 #endif
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 /* ASSERT, ASSERT_NOT_REACHED, ASSERT_UNUSED 191 /* ASSERT, ASSERT_NOT_REACHED, ASSERT_UNUSED
190 192
191 These macros are compiled out of release builds. 193 These macros are compiled out of release builds.
192 Expressions inside them are evaluated in debug builds only. 194 Expressions inside them are evaluated in debug builds only.
193 */ 195 */
194 #if OS(WIN) 196 #if OS(WIN)
195 /* FIXME: Change to use something other than ASSERT to avoid this conflict with the underlying platform */ 197 /* FIXME: Change to use something other than ASSERT to avoid this conflict with the underlying platform */
196 #undef ASSERT 198 #undef ASSERT
197 #endif 199 #endif
198 200
199 #if ASSERT_ENABLED 201 #if ENABLE(ASSERT)
200 202
201 #define ASSERT(assertion) \ 203 #define ASSERT(assertion) \
202 (!(assertion) ? \ 204 (!(assertion) ? \
203 (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #ass ertion), \ 205 (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #ass ertion), \
204 CRASH()) : \ 206 CRASH()) : \
205 (void)0) 207 (void)0)
206 208
207 #define ASSERT_AT(assertion, file, line, function) \ 209 #define ASSERT_AT(assertion, file, line, function) \
208 (!(assertion) ? \ 210 (!(assertion) ? \
209 (WTFReportAssertionFailure(file, line, function, #assertion), \ 211 (WTFReportAssertionFailure(file, line, function, #assertion), \
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 250
249 #define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT_WITH_SECURITY _IMPLICATION(assertion) 251 #define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT_WITH_SECURITY _IMPLICATION(assertion)
250 252
251 #else 253 #else
252 254
253 #define ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT(assertion) 255 #define ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT(assertion)
254 #define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) RELEASE_ASSERT(asser tion) 256 #define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) RELEASE_ASSERT(asser tion)
255 257
256 #endif 258 #endif
257 259
258 #if defined(ADDRESS_SANITIZER) || ASSERT_ENABLED 260 // Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure
259 #define SECURITY_ASSERT_ENABLED 1 261 // that code testing this macro has included this header.
262 #if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT)
263 #define ENABLE_SECURITY_ASSERT 1
260 #else 264 #else
261 #define SECURITY_ASSERT_ENABLED 0 265 #define ENABLE_SECURITY_ASSERT 0
262 #endif 266 #endif
263 267
264 /* ASSERT_WITH_MESSAGE */ 268 /* ASSERT_WITH_MESSAGE */
265 269
266 #if ASSERT_MSG_DISABLED 270 #if ASSERT_MSG_DISABLED
267 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0) 271 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0)
268 #else 272 #else
269 #define ASSERT_WITH_MESSAGE(assertion, ...) do \ 273 #define ASSERT_WITH_MESSAGE(assertion, ...) do \
270 if (!(assertion)) { \ 274 if (!(assertion)) { \
271 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC TION, #assertion, __VA_ARGS__); \ 275 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC TION, #assertion, __VA_ARGS__); \
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 #endif 366 #endif
363 367
364 /* RELEASE_ASSERT 368 /* RELEASE_ASSERT
365 369
366 Use in places where failure of an assertion indicates a definite security 370 Use in places where failure of an assertion indicates a definite security
367 vulnerability from which execution must not continue even in a release build. 371 vulnerability from which execution must not continue even in a release build.
368 Please sure to file bugs for these failures using the security template: 372 Please sure to file bugs for these failures using the security template:
369 http://code.google.com/p/chromium/issues/entry?template=Security%20Bug 373 http://code.google.com/p/chromium/issues/entry?template=Security%20Bug
370 */ 374 */
371 375
372 #if ASSERT_ENABLED 376 #if ENABLE(ASSERT)
373 #define RELEASE_ASSERT(assertion) ASSERT(assertion) 377 #define RELEASE_ASSERT(assertion) ASSERT(assertion)
374 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertio n, __VA_ARGS__) 378 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertio n, __VA_ARGS__)
375 #define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED() 379 #define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED()
376 #else 380 #else
377 #define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH()) : (void)0) 381 #define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH()) : (void)0)
378 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion) 382 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion)
379 #define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH() 383 #define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH()
380 #endif 384 #endif
381 385
382 /* DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES */ 386 /* DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES */
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 } \ 422 } \
419 inline const thisType& to##thisType(const argumentType& argumentName) \ 423 inline const thisType& to##thisType(const argumentType& argumentName) \
420 { \ 424 { \
421 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \ 425 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \
422 return static_cast<const thisType&>(argumentName); \ 426 return static_cast<const thisType&>(argumentName); \
423 } \ 427 } \
424 void to##thisType(const thisType*); \ 428 void to##thisType(const thisType*); \
425 void to##thisType(const thisType&) 429 void to##thisType(const thisType&)
426 430
427 #endif /* WTF_Assertions_h */ 431 #endif /* WTF_Assertions_h */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698