| OLD | NEW |
| 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 25 matching lines...) Expand all Loading... |
| 36 For non-debug builds, everything is disabled by default, except for the | 36 For non-debug builds, everything is disabled by default, except for the |
| 37 RELEASE_ASSERT family of macros. | 37 RELEASE_ASSERT family of macros. |
| 38 | 38 |
| 39 Defining any of the symbols explicitly prevents this from having any effect. | 39 Defining any of the symbols explicitly prevents this from having any effect. |
| 40 | 40 |
| 41 */ | 41 */ |
| 42 | 42 |
| 43 #include "wtf/Compiler.h" | 43 #include "wtf/Compiler.h" |
| 44 #include "wtf/WTFExport.h" | 44 #include "wtf/WTFExport.h" |
| 45 | 45 |
| 46 // Users must test "#if ENABLE(ASSERT)", which helps ensure that code |
| 47 // testing this macro has included this header. |
| 48 #ifndef ENABLE_ASSERT |
| 46 #ifdef NDEBUG | 49 #ifdef NDEBUG |
| 47 /* Disable ASSERT* macros in release mode. */ | 50 /* Disable ASSERT* macros in release mode by default. */ |
| 48 #define ASSERTIONS_DISABLED_DEFAULT 1 | 51 #define ENABLE_ASSERT 0 |
| 49 #else | 52 #else |
| 50 #define ASSERTIONS_DISABLED_DEFAULT 0 | 53 #define ENABLE_ASSERT 1 |
| 54 #endif /* NDEBUG */ |
| 51 #endif | 55 #endif |
| 52 | 56 |
| 53 #ifndef BACKTRACE_DISABLED | 57 #ifndef BACKTRACE_DISABLED |
| 54 #define BACKTRACE_DISABLED ASSERTIONS_DISABLED_DEFAULT | 58 #define BACKTRACE_DISABLED !ENABLE(ASSERT) |
| 55 #endif | |
| 56 | |
| 57 #ifndef ASSERT_ENABLED | |
| 58 // Notice the not below: | |
| 59 #define ASSERT_ENABLED !ASSERTIONS_DISABLED_DEFAULT | |
| 60 #endif | 59 #endif |
| 61 | 60 |
| 62 #ifndef ASSERT_MSG_DISABLED | 61 #ifndef ASSERT_MSG_DISABLED |
| 63 #define ASSERT_MSG_DISABLED ASSERTIONS_DISABLED_DEFAULT | 62 #define ASSERT_MSG_DISABLED !ENABLE(ASSERT) |
| 64 #endif | 63 #endif |
| 65 | 64 |
| 66 #ifndef ASSERT_ARG_DISABLED | 65 #ifndef ASSERT_ARG_DISABLED |
| 67 #define ASSERT_ARG_DISABLED ASSERTIONS_DISABLED_DEFAULT | 66 #define ASSERT_ARG_DISABLED !ENABLE(ASSERT) |
| 68 #endif | 67 #endif |
| 69 | 68 |
| 70 #ifndef FATAL_DISABLED | 69 #ifndef FATAL_DISABLED |
| 71 #define FATAL_DISABLED ASSERTIONS_DISABLED_DEFAULT | 70 #define FATAL_DISABLED !ENABLE(ASSERT) |
| 72 #endif | 71 #endif |
| 73 | 72 |
| 74 #ifndef ERROR_DISABLED | 73 #ifndef ERROR_DISABLED |
| 75 #define ERROR_DISABLED ASSERTIONS_DISABLED_DEFAULT | 74 #define ERROR_DISABLED !ENABLE(ASSERT) |
| 76 #endif | 75 #endif |
| 77 | 76 |
| 78 #ifndef LOG_DISABLED | 77 #ifndef LOG_DISABLED |
| 79 #define LOG_DISABLED ASSERTIONS_DISABLED_DEFAULT | 78 #define LOG_DISABLED !ENABLE(ASSERT) |
| 80 #endif | 79 #endif |
| 81 | 80 |
| 82 /* WTF logging functions can process %@ in the format string to log a NSObject*
but the printf format attribute | 81 /* 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 | 82 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
%@. */ | 83 the attribute when being used from Objective-C code in case it decides to use
%@. */ |
| 85 #if COMPILER(GCC) && !defined(__OBJC__) | 84 #if COMPILER(GCC) && !defined(__OBJC__) |
| 86 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) __attribute__
((__format__(printf, formatStringArgument, extraArguments))) | 85 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) __attribute__
((__format__(printf, formatStringArgument, extraArguments))) |
| 87 #else | 86 #else |
| 88 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) | 87 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) |
| 89 #endif | 88 #endif |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 /* ASSERT, ASSERT_NOT_REACHED, ASSERT_UNUSED | 188 /* ASSERT, ASSERT_NOT_REACHED, ASSERT_UNUSED |
| 190 | 189 |
| 191 These macros are compiled out of release builds. | 190 These macros are compiled out of release builds. |
| 192 Expressions inside them are evaluated in debug builds only. | 191 Expressions inside them are evaluated in debug builds only. |
| 193 */ | 192 */ |
| 194 #if OS(WIN) | 193 #if OS(WIN) |
| 195 /* FIXME: Change to use something other than ASSERT to avoid this conflict with
the underlying platform */ | 194 /* FIXME: Change to use something other than ASSERT to avoid this conflict with
the underlying platform */ |
| 196 #undef ASSERT | 195 #undef ASSERT |
| 197 #endif | 196 #endif |
| 198 | 197 |
| 199 #if ASSERT_ENABLED | 198 #if ENABLE(ASSERT) |
| 200 | 199 |
| 201 #define ASSERT(assertion) \ | 200 #define ASSERT(assertion) \ |
| 202 (!(assertion) ? \ | 201 (!(assertion) ? \ |
| 203 (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #ass
ertion), \ | 202 (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #ass
ertion), \ |
| 204 CRASH()) : \ | 203 CRASH()) : \ |
| 205 (void)0) | 204 (void)0) |
| 206 | 205 |
| 207 #define ASSERT_AT(assertion, file, line, function) \ | 206 #define ASSERT_AT(assertion, file, line, function) \ |
| 208 (!(assertion) ? \ | 207 (!(assertion) ? \ |
| 209 (WTFReportAssertionFailure(file, line, function, #assertion), \ | 208 (WTFReportAssertionFailure(file, line, function, #assertion), \ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 247 |
| 249 #define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT_WITH_SECURITY
_IMPLICATION(assertion) | 248 #define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT_WITH_SECURITY
_IMPLICATION(assertion) |
| 250 | 249 |
| 251 #else | 250 #else |
| 252 | 251 |
| 253 #define ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT(assertion) | 252 #define ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT(assertion) |
| 254 #define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) RELEASE_ASSERT(asser
tion) | 253 #define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) RELEASE_ASSERT(asser
tion) |
| 255 | 254 |
| 256 #endif | 255 #endif |
| 257 | 256 |
| 258 #if defined(ADDRESS_SANITIZER) || ASSERT_ENABLED | 257 /* Users must test "#if ENABLE(SECURITY_ASSERT)", which helps ensure |
| 259 #define SECURITY_ASSERT_ENABLED 1 | 258 * that code testing this macro has included this header. */ |
| 259 #if defined(ADDRESS_SANITIZER) || ENABLE(ASSERT) |
| 260 #define ENABLE_SECURITY_ASSERT 1 |
| 260 #else | 261 #else |
| 261 #define SECURITY_ASSERT_ENABLED 0 | 262 #define ENABLE_SECURITY_ASSERT 0 |
| 262 #endif | 263 #endif |
| 263 | 264 |
| 264 /* ASSERT_WITH_MESSAGE */ | 265 /* ASSERT_WITH_MESSAGE */ |
| 265 | 266 |
| 266 #if ASSERT_MSG_DISABLED | 267 #if ASSERT_MSG_DISABLED |
| 267 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0) | 268 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0) |
| 268 #else | 269 #else |
| 269 #define ASSERT_WITH_MESSAGE(assertion, ...) do \ | 270 #define ASSERT_WITH_MESSAGE(assertion, ...) do \ |
| 270 if (!(assertion)) { \ | 271 if (!(assertion)) { \ |
| 271 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC
TION, #assertion, __VA_ARGS__); \ | 272 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNC
TION, #assertion, __VA_ARGS__); \ |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 #endif | 363 #endif |
| 363 | 364 |
| 364 /* RELEASE_ASSERT | 365 /* RELEASE_ASSERT |
| 365 | 366 |
| 366 Use in places where failure of an assertion indicates a definite security | 367 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. | 368 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: | 369 Please sure to file bugs for these failures using the security template: |
| 369 http://code.google.com/p/chromium/issues/entry?template=Security%20Bug | 370 http://code.google.com/p/chromium/issues/entry?template=Security%20Bug |
| 370 */ | 371 */ |
| 371 | 372 |
| 372 #if ASSERT_ENABLED | 373 #if ENABLE(ASSERT) |
| 373 #define RELEASE_ASSERT(assertion) ASSERT(assertion) | 374 #define RELEASE_ASSERT(assertion) ASSERT(assertion) |
| 374 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertio
n, __VA_ARGS__) | 375 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertio
n, __VA_ARGS__) |
| 375 #define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED() | 376 #define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED() |
| 376 #else | 377 #else |
| 377 #define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH())
: (void)0) | 378 #define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH())
: (void)0) |
| 378 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion) | 379 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion) |
| 379 #define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH() | 380 #define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH() |
| 380 #endif | 381 #endif |
| 381 | 382 |
| 382 /* DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES */ | 383 /* DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES */ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } \ | 419 } \ |
| 419 inline const thisType& to##thisType(const argumentType& argumentName) \ | 420 inline const thisType& to##thisType(const argumentType& argumentName) \ |
| 420 { \ | 421 { \ |
| 421 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \ | 422 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \ |
| 422 return static_cast<const thisType&>(argumentName); \ | 423 return static_cast<const thisType&>(argumentName); \ |
| 423 } \ | 424 } \ |
| 424 void to##thisType(const thisType*); \ | 425 void to##thisType(const thisType*); \ |
| 425 void to##thisType(const thisType&) | 426 void to##thisType(const thisType&) |
| 426 | 427 |
| 427 #endif /* WTF_Assertions_h */ | 428 #endif /* WTF_Assertions_h */ |
| OLD | NEW |