~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003, 2006, 2007 Apple Inc.  All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
7
 * 1. Redistributions of source code must retain the above copyright
 
8
 *    notice, this list of conditions and the following disclaimer.
 
9
 * 2. Redistributions in binary form must reproduce the above copyright
 
10
 *    notice, this list of conditions and the following disclaimer in the
 
11
 *    documentation and/or other materials provided with the distribution.
 
12
 *
 
13
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
24
 */
 
25
 
 
26
#ifndef WTF_Assertions_h
 
27
#define WTF_Assertions_h
 
28
 
 
29
/*
 
30
   no namespaces because this file has to be includable from C and Objective-C
 
31
 
 
32
   Note, this file uses many GCC extensions, but it should be compatible with
 
33
   C, Objective C, C++, and Objective C++.
 
34
 
 
35
   For non-debug builds, everything is disabled by default.
 
36
   Defining any of the symbols explicitly prevents this from having any effect.
 
37
   
 
38
   MSVC7 note: variadic macro support was added in MSVC8, so for now we disable
 
39
   those macros in MSVC7. For more info, see the MSDN document on variadic 
 
40
   macros here:
 
41
   
 
42
   http://msdn2.microsoft.com/en-us/library/ms177415(VS.80).aspx
 
43
*/
 
44
 
 
45
#include "Platform.h"
 
46
 
 
47
#if COMPILER(MSVC)
 
48
#include <stddef.h>
 
49
#else
 
50
#include <inttypes.h>
 
51
#endif
 
52
 
 
53
#if PLATFORM(SYMBIAN)
 
54
#include <e32def.h>
 
55
#include <e32debug.h>
 
56
#endif
 
57
 
 
58
#ifdef NDEBUG
 
59
#define ASSERTIONS_DISABLED_DEFAULT 1
 
60
#else
 
61
#define ASSERTIONS_DISABLED_DEFAULT 0
 
62
#endif
 
63
 
 
64
#ifndef ASSERT_DISABLED
 
65
#define ASSERT_DISABLED ASSERTIONS_DISABLED_DEFAULT
 
66
#endif
 
67
 
 
68
#ifndef ASSERT_ARG_DISABLED
 
69
#define ASSERT_ARG_DISABLED ASSERTIONS_DISABLED_DEFAULT
 
70
#endif
 
71
 
 
72
#ifndef FATAL_DISABLED
 
73
#define FATAL_DISABLED ASSERTIONS_DISABLED_DEFAULT
 
74
#endif
 
75
 
 
76
#ifndef ERROR_DISABLED
 
77
#define ERROR_DISABLED ASSERTIONS_DISABLED_DEFAULT
 
78
#endif
 
79
 
 
80
#ifndef LOG_DISABLED
 
81
#define LOG_DISABLED ASSERTIONS_DISABLED_DEFAULT
 
82
#endif
 
83
 
 
84
#if COMPILER(GCC)
 
85
#define WTF_PRETTY_FUNCTION __PRETTY_FUNCTION__
 
86
#else
 
87
#define WTF_PRETTY_FUNCTION __FUNCTION__
 
88
#endif
 
89
 
 
90
/* WTF logging functions can process %@ in the format string to log a NSObject* but the printf format attribute
 
91
   emits a warning when %@ is used in the format string.  Until <rdar://problem/5195437> is resolved we can't include
 
92
   the attribute when being used from Objective-C code in case it decides to use %@. */
 
93
#if COMPILER(GCC) && !defined(__OBJC__)
 
94
#define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) __attribute__((__format__(printf, formatStringArgument, extraArguments)))
 
95
#else
 
96
#define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) 
 
97
#endif
 
98
 
 
99
/* These helper functions are always declared, but not necessarily always defined if the corresponding function is disabled. */
 
100
 
 
101
#ifdef __cplusplus
 
102
extern "C" {
 
103
#endif
 
104
 
 
105
typedef enum { WTFLogChannelOff, WTFLogChannelOn } WTFLogChannelState;
 
106
 
 
107
typedef struct {
 
108
    unsigned mask;
 
109
    const char *defaultName;
 
110
    WTFLogChannelState state;
 
111
} WTFLogChannel;
 
112
 
 
113
void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion);
 
114
void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
 
115
void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion);
 
116
void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5);
 
117
void WTFReportError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5);
 
118
void WTFLog(WTFLogChannel* channel, const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
 
119
void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel* channel, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
 
120
 
 
121
#ifdef __cplusplus
 
122
}
 
123
#endif
 
124
 
 
125
/* CRASH -- gets us into the debugger or the crash reporter -- signals are ignored by the crash reporter so we must do better */
 
126
 
 
127
#ifndef CRASH
 
128
#if PLATFORM(SYMBIAN)
 
129
#define CRASH() do { \
 
130
    __DEBUGGER(); \
 
131
    User::Panic(_L("Webkit CRASH"),0); \
 
132
    } while(false)
 
133
#else
 
134
#define CRASH() do { \
 
135
    *(int *)(uintptr_t)0xbbadbeef = 0; \
 
136
    ((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \
 
137
} while(false)
 
138
#endif
 
139
#endif
 
140
 
 
141
/* ASSERT, ASSERT_WITH_MESSAGE, ASSERT_NOT_REACHED */
 
142
 
 
143
#if PLATFORM(WINCE) && !PLATFORM(TORCHMOBILE)
 
144
/* FIXME: We include this here only to avoid a conflict with the ASSERT macro. */
 
145
#include <windows.h>
 
146
#undef min
 
147
#undef max
 
148
#undef ERROR
 
149
#endif
 
150
 
 
151
#if PLATFORM(WIN_OS) || PLATFORM(SYMBIAN)
 
152
/* FIXME: Change to use something other than ASSERT to avoid this conflict with the underlying platform */
 
153
#undef ASSERT
 
154
#endif
 
155
 
 
156
#if ASSERT_DISABLED
 
157
 
 
158
#define ASSERT(assertion) ((void)0)
 
159
#if COMPILER(MSVC7)
 
160
#define ASSERT_WITH_MESSAGE(assertion) ((void)0)
 
161
#elif PLATFORM(SYMBIAN)
 
162
#define ASSERT_WITH_MESSAGE(assertion...) ((void)0)
 
163
#else
 
164
#define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0)
 
165
#endif /* COMPILER(MSVC7) */
 
166
#define ASSERT_NOT_REACHED() ((void)0)
 
167
#define ASSERT_UNUSED(variable, assertion) ((void)variable)
 
168
 
 
169
#else
 
170
 
 
171
#define ASSERT(assertion) do \
 
172
    if (!(assertion)) { \
 
173
        WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion); \
 
174
        CRASH(); \
 
175
    } \
 
176
while (0)
 
177
#if COMPILER(MSVC7)
 
178
#define ASSERT_WITH_MESSAGE(assertion) ((void)0)
 
179
#elif PLATFORM(SYMBIAN)
 
180
#define ASSERT_WITH_MESSAGE(assertion...) ((void)0)
 
181
#else
 
182
#define ASSERT_WITH_MESSAGE(assertion, ...) do \
 
183
    if (!(assertion)) { \
 
184
        WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion, __VA_ARGS__); \
 
185
        CRASH(); \
 
186
    } \
 
187
while (0)
 
188
#endif /* COMPILER(MSVC7) */
 
189
#define ASSERT_NOT_REACHED() do { \
 
190
    WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \
 
191
    CRASH(); \
 
192
} while (0)
 
193
 
 
194
#define ASSERT_UNUSED(variable, assertion) ASSERT(assertion)
 
195
 
 
196
#endif
 
197
 
 
198
/* ASSERT_ARG */
 
199
 
 
200
#if ASSERT_ARG_DISABLED
 
201
 
 
202
#define ASSERT_ARG(argName, assertion) ((void)0)
 
203
 
 
204
#else
 
205
 
 
206
#define ASSERT_ARG(argName, assertion) do \
 
207
    if (!(assertion)) { \
 
208
        WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #argName, #assertion); \
 
209
        CRASH(); \
 
210
    } \
 
211
while (0)
 
212
 
 
213
#endif
 
214
 
 
215
/* COMPILE_ASSERT */
 
216
#ifndef COMPILE_ASSERT
 
217
#define COMPILE_ASSERT(exp, name) typedef int dummy##name [(exp) ? 1 : -1]
 
218
#endif
 
219
 
 
220
/* FATAL */
 
221
 
 
222
#if FATAL_DISABLED && !COMPILER(MSVC7) && !PLATFORM(SYMBIAN)
 
223
#define FATAL(...) ((void)0)
 
224
#elif COMPILER(MSVC7)
 
225
#define FATAL() ((void)0)
 
226
#elif PLATFORM(SYMBIAN)
 
227
#define FATAL(args...) ((void)0)
 
228
#else
 
229
#define FATAL(...) do { \
 
230
    WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__); \
 
231
    CRASH(); \
 
232
} while (0)
 
233
#endif
 
234
 
 
235
/* LOG_ERROR */
 
236
 
 
237
#if ERROR_DISABLED && !COMPILER(MSVC7) && !PLATFORM(SYMBIAN)
 
238
#define LOG_ERROR(...) ((void)0)
 
239
#elif COMPILER(MSVC7)
 
240
#define LOG_ERROR() ((void)0)
 
241
#elif PLATFORM(SYMBIAN)
 
242
#define LOG_ERROR(args...) ((void)0)
 
243
#else
 
244
#define LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__)
 
245
#endif
 
246
 
 
247
/* LOG */
 
248
 
 
249
#if LOG_DISABLED && !COMPILER(MSVC7) && !PLATFORM(SYMBIAN)
 
250
#define LOG(channel, ...) ((void)0)
 
251
#elif COMPILER(MSVC7)
 
252
#define LOG() ((void)0)
 
253
#elif PLATFORM(SYMBIAN)
 
254
#define LOG(channel, args...) ((void)0)
 
255
#else
 
256
#define LOG(channel, ...) WTFLog(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), __VA_ARGS__)
 
257
#define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel)
 
258
#define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel
 
259
#endif
 
260
 
 
261
/* LOG_VERBOSE */
 
262
 
 
263
#if LOG_DISABLED && !COMPILER(MSVC7) && !PLATFORM(SYMBIAN)
 
264
#define LOG_VERBOSE(channel, ...) ((void)0)
 
265
#elif COMPILER(MSVC7)
 
266
#define LOG_VERBOSE(channel) ((void)0)
 
267
#elif PLATFORM(SYMBIAN)
 
268
#define LOG_VERBOSE(channel, args...) ((void)0)
 
269
#else
 
270
#define LOG_VERBOSE(channel, ...) WTFLogVerbose(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, &JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), __VA_ARGS__)
 
271
#endif
 
272
 
 
273
#endif /* WTF_Assertions_h */