]>
git.saurik.com Git - apple/javascriptcore.git/blob - wtf/Assertions.h
1 /* -*- mode: c++; c-basic-offset: 4 -*- */
3 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef WTF_Assertions_h
28 #define WTF_Assertions_h
31 no namespaces because this file has to be includable from C and Objective-C
33 Note, this file uses many GCC extensions, but it should be compatible with
34 C, Objective C, C++, and Objective C++.
36 For non-debug builds, everything is disabled by default.
37 Defining any of the symbols explicitly prevents this from having any effect.
39 MSVC7 note: variadic macro support was added in MSVC8, so for now we disable
40 those macros in MSVC7. For more info, see the MSDN document on variadic
43 http://msdn2.microsoft.com/en-us/library/ms177415(VS.80).aspx
55 #define ASSERTIONS_DISABLED_DEFAULT 1
57 #define ASSERTIONS_DISABLED_DEFAULT 0
60 #ifndef ASSERT_DISABLED
61 #define ASSERT_DISABLED ASSERTIONS_DISABLED_DEFAULT
64 #ifndef ASSERT_ARG_DISABLED
65 #define ASSERT_ARG_DISABLED ASSERTIONS_DISABLED_DEFAULT
68 #ifndef FATAL_DISABLED
69 #define FATAL_DISABLED ASSERTIONS_DISABLED_DEFAULT
72 #ifndef ERROR_DISABLED
73 #define ERROR_DISABLED ASSERTIONS_DISABLED_DEFAULT
77 #define LOG_DISABLED ASSERTIONS_DISABLED_DEFAULT
81 #define WTF_PRETTY_FUNCTION __PRETTY_FUNCTION__
83 #define WTF_PRETTY_FUNCTION __FUNCTION__
86 // WTF logging functions can process %@ in the format string to log a NSObject* but the printf format attribute
87 // emits a warning when %@ is used in the format string. Until <rdar://problem/5195437> is resolved we can't include
88 // the attribute when being used from Objective-C code in case it decides to use %@.
89 #if COMPILER(GCC) && !defined(__OBJC__)
90 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) __attribute__((__format__(printf, formatStringArgument, extraArguments)))
92 #define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments)
95 /* These helper functions are always declared, but not necessarily always defined if the corresponding function is disabled. */
101 typedef enum { WTFLogChannelOff
, WTFLogChannelOn
} WTFLogChannelState
;
105 const char *defaultName
;
106 WTFLogChannelState state
;
109 void WTFReportAssertionFailure(const char* file
, int line
, const char* function
, const char* assertion
);
110 void WTFReportAssertionFailureWithMessage(const char* file
, int line
, const char* function
, const char* assertion
, const char* format
, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
111 void WTFReportArgumentAssertionFailure(const char* file
, int line
, const char* function
, const char* argName
, const char* assertion
);
112 void WTFReportFatalError(const char* file
, int line
, const char* function
, const char* format
, ...) WTF_ATTRIBUTE_PRINTF(4, 5);
113 void WTFReportError(const char* file
, int line
, const char* function
, const char* format
, ...) WTF_ATTRIBUTE_PRINTF(4, 5);
114 void WTFLog(WTFLogChannel
* channel
, const char* format
, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
115 void WTFLogVerbose(const char* file
, int line
, const char* function
, WTFLogChannel
* channel
, const char* format
, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
121 /* CRASH -- gets us into the debugger or the crash reporter -- signals are ignored by the crash reporter so we must do better */
124 #define CRASH() *(int *)(uintptr_t)0xbbadbeef = 0
127 /* ASSERT, ASSERT_WITH_MESSAGE, ASSERT_NOT_REACHED */
130 /* FIXME: Change to use something other than ASSERT to avoid this conflict with win32. */
136 #define ASSERT(assertion) ((void)0)
137 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0)
138 #define ASSERT_NOT_REACHED() ((void)0)
142 #define ASSERT(assertion) do \
143 if (!(assertion)) { \
144 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion); \
149 #define ASSERT_WITH_MESSAGE(assertion) ((void)0)
151 #define ASSERT_WITH_MESSAGE(assertion, ...) do \
152 if (!(assertion)) { \
153 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion, __VA_ARGS__); \
157 #endif // COMPILER(MSVC7)
158 #define ASSERT_NOT_REACHED() do { \
159 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \
167 #if ASSERT_ARG_DISABLED
169 #define ASSERT_ARG(argName, assertion) ((void)0)
173 #define ASSERT_ARG(argName, assertion) do \
174 if (!(assertion)) { \
175 WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #argName, #assertion); \
183 #ifndef COMPILE_ASSERT
184 #define COMPILE_ASSERT(exp, name) typedef int dummy##name [(exp) ? 1 : -1];
190 #define FATAL(...) ((void)0)
191 #elif COMPILER(MSVC7)
192 #define FATAL() ((void)0)
194 #define FATAL(...) do { \
195 WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__); \
203 #define LOG_ERROR(...) ((void)0)
204 #elif COMPILER(MSVC7)
205 #define LOG_ERROR() ((void)0)
207 #define LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__)
213 #define LOG(channel, ...) ((void)0)
214 #elif COMPILER(MSVC7)
215 #define LOG() ((void)0)
217 #define LOG(channel, ...) WTFLog(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), __VA_ARGS__)
218 #define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel)
219 #define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel
225 #define LOG_VERBOSE(channel, ...) ((void)0)
226 #elif COMPILER(MSVC7)
227 #define LOG_VERBOSE(channel) ((void)0)
229 #define LOG_VERBOSE(channel, ...) WTFLogVerbose(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, &JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), __VA_ARGS__)
232 #endif // WTF_Assertions_h