1 /* -*- mode: c++; c-basic-offset: 4 -*- */
3 * Copyright (C) 2003, 2006 Apple Computer, 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 KXMLCORE_ASSERTIONS_H
28 #define KXMLCORE_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.
43 #define ASSERTIONS_DISABLED_DEFAULT 1
45 #define ASSERTIONS_DISABLED_DEFAULT 0
48 #ifndef ASSERT_DISABLED
49 #define ASSERT_DISABLED ASSERTIONS_DISABLED_DEFAULT
52 #ifndef ASSERT_ARG_DISABLED
53 #define ASSERT_ARG_DISABLED ASSERTIONS_DISABLED_DEFAULT
56 #ifndef FATAL_DISABLED
57 #define FATAL_DISABLED ASSERTIONS_DISABLED_DEFAULT
60 #ifndef ERROR_DISABLED
61 #define ERROR_DISABLED ASSERTIONS_DISABLED_DEFAULT
65 #define LOG_DISABLED ASSERTIONS_DISABLED_DEFAULT
69 #define KXMLCORE_PRETTY_FUNCTION __PRETTY_FUNCTION__
71 #define KXMLCORE_PRETTY_FUNCTION __FUNCTION__
74 /* These helper functions are always declared, but not necessarily always defined if the corresponding function is disabled. */
80 typedef enum { WTFLogChannelOff, WTFLogChannelOn } WTFLogChannelState;
84 const char *defaultName;
85 WTFLogChannelState state;
88 void WTFReportAssertionFailure(const char *file, int line, const char *function, const char *assertion);
89 void WTFReportAssertionFailureWithMessage(const char *file, int line, const char *function, const char *assertion, const char *format, ...);
90 void WTFReportArgumentAssertionFailure(const char *file, int line, const char *function, const char *argName, const char *assertion);
91 void WTFReportFatalError(const char *file, int line, const char *function, const char *format, ...) ;
92 void WTFReportError(const char *file, int line, const char *function, const char *format, ...);
93 void WTFLog(const char *file, int line, const char *function, WTFLogChannel *channel, const char *format, ...);
99 /* CRASH -- gets us into the debugger or the crash reporter -- signals are ignored by the crash reporter so we must do better */
101 #define CRASH() *(int *)(uintptr_t)0xbbadbeef = 0
103 /* ASSERT, ASSERT_WITH_MESSAGE, ASSERT_NOT_REACHED */
106 /* FIXME: Change to use something other than ASSERT to avoid this conflict with win32. */
112 #define ASSERT(assertion) ((void)0)
113 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0)
114 #define ASSERT_NOT_REACHED() ((void)0)
118 #define ASSERT(assertion) do \
119 if (!(assertion)) { \
120 WTFReportAssertionFailure(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, #assertion); \
124 #define ASSERT_WITH_MESSAGE(assertion, ...) do \
125 if (!(assertion)) { \
126 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, #assertion, __VA_ARGS__); \
130 #define ASSERT_NOT_REACHED() do { \
131 WTFReportAssertionFailure(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, 0); \
139 #if ASSERT_ARG_DISABLED
141 #define ASSERT_ARG(argName, assertion) ((void)0)
145 #define ASSERT_ARG(argName, assertion) do \
146 if (!(assertion)) { \
147 WTFReportArgumentAssertionFailure(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, #argName, #assertion); \
157 #define FATAL(...) ((void)0)
159 #define FATAL(...) do { \
160 WTFReportFatalError(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, __VA_ARGS__); \
168 #define LOG_ERROR(...) ((void)0)
170 #define LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, __VA_ARGS__)
176 #define LOG(channel, ...) ((void)0)
178 #define LOG(channel, ...) WTFLog(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, &JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), __VA_ARGS__)
179 #define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel)
180 #define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel
183 #endif // KXMLCORE_ASSERTIONS_H