source: webkit/trunk/JavaScriptCore/wtf/Assertions.h@ 27885

Last change on this file since 27885 was 26589, checked in by bdash, 18 years ago

2007-10-14 Kevin Ollivier <[email protected]>

Reviewed by Adam.

Add support for MSVC7, and fix cases where PLATFORM(WIN) should
be PLATFORM(WIN_OS) for other ports building on Windows.

  • dom/XMLTokenizer.cpp:
  • page/FrameTree.cpp:
  • platform/StaticConstructors.h:
  • platform/String.cpp:

2007-10-5 Kevin Ollivier <[email protected]>

Reviewed by Adam.


Add support for MSVC7, and fix cases where PLATFORM(WIN) should
be PLATFORM(WIN_OS) for other ports building on Windows.


  • kjs/DateMath.cpp: (KJS::getDSTOffsetSimple):
  • kjs/JSImmediate.h:
  • wtf/Assertions.cpp:
  • wtf/Assertions.h:
  • wtf/Platform.h:
  • wtf/StringExtras.h: (snprintf): (vsnprintf):
  • Property svn:eol-style set to native
File size: 6.7 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4 -*- */
2/*
3 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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.
25 */
26
27#ifndef WTF_Assertions_h
28#define WTF_Assertions_h
29
30/*
31 no namespaces because this file has to be includable from C and Objective-C
32
33 Note, this file uses many GCC extensions, but it should be compatible with
34 C, Objective C, C++, and Objective C++.
35
36 For non-debug builds, everything is disabled by default.
37 Defining any of the symbols explicitly prevents this from having any effect.
38
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
41 macros here:
42
43 http://msdn2.microsoft.com/en-us/library/ms177415(VS.80).aspx
44*/
45
46#include "Platform.h"
47
48#if COMPILER(MSVC)
49#include <stddef.h>
50#else
51#include <inttypes.h>
52#endif
53
54#ifdef NDEBUG
55#define ASSERTIONS_DISABLED_DEFAULT 1
56#else
57#define ASSERTIONS_DISABLED_DEFAULT 0
58#endif
59
60#ifndef ASSERT_DISABLED
61#define ASSERT_DISABLED ASSERTIONS_DISABLED_DEFAULT
62#endif
63
64#ifndef ASSERT_ARG_DISABLED
65#define ASSERT_ARG_DISABLED ASSERTIONS_DISABLED_DEFAULT
66#endif
67
68#ifndef FATAL_DISABLED
69#define FATAL_DISABLED ASSERTIONS_DISABLED_DEFAULT
70#endif
71
72#ifndef ERROR_DISABLED
73#define ERROR_DISABLED ASSERTIONS_DISABLED_DEFAULT
74#endif
75
76#ifndef LOG_DISABLED
77#define LOG_DISABLED ASSERTIONS_DISABLED_DEFAULT
78#endif
79
80#if COMPILER(GCC)
81#define WTF_PRETTY_FUNCTION __PRETTY_FUNCTION__
82#else
83#define WTF_PRETTY_FUNCTION __FUNCTION__
84#endif
85
86/* These helper functions are always declared, but not necessarily always defined if the corresponding function is disabled. */
87
88#ifdef __cplusplus
89extern "C" {
90#endif
91
92typedef enum { WTFLogChannelOff, WTFLogChannelOn } WTFLogChannelState;
93
94typedef struct {
95 unsigned mask;
96 const char *defaultName;
97 WTFLogChannelState state;
98} WTFLogChannel;
99
100void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion);
101void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...);
102void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion);
103void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...) ;
104void WTFReportError(const char* file, int line, const char* function, const char* format, ...);
105void WTFLog(WTFLogChannel* channel, const char* format, ...);
106void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel* channel, const char* format, ...);
107
108#ifdef __cplusplus
109}
110#endif
111
112/* CRASH -- gets us into the debugger or the crash reporter -- signals are ignored by the crash reporter so we must do better */
113
114#ifndef CRASH
115#define CRASH() *(int *)(uintptr_t)0xbbadbeef = 0
116#endif
117
118/* ASSERT, ASSERT_WITH_MESSAGE, ASSERT_NOT_REACHED */
119
120#if PLATFORM(WIN_OS)
121/* FIXME: Change to use something other than ASSERT to avoid this conflict with win32. */
122#undef ASSERT
123#endif
124
125#if ASSERT_DISABLED
126
127#define ASSERT(assertion) ((void)0)
128#define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0)
129#define ASSERT_NOT_REACHED() ((void)0)
130
131#else
132
133#define ASSERT(assertion) do \
134 if (!(assertion)) { \
135 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion); \
136 CRASH(); \
137 } \
138while (0)
139#if COMPILER(MSVC7)
140#define ASSERT_WITH_MESSAGE(assertion) ((void)0)
141#else
142#define ASSERT_WITH_MESSAGE(assertion, ...) do \
143 if (!(assertion)) { \
144 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion, __VA_ARGS__); \
145 CRASH(); \
146 } \
147while (0)
148#endif // COMPILER(MSVC7)
149#define ASSERT_NOT_REACHED() do { \
150 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \
151 CRASH(); \
152} while (0)
153
154#endif
155
156/* ASSERT_ARG */
157
158#if ASSERT_ARG_DISABLED
159
160#define ASSERT_ARG(argName, assertion) ((void)0)
161
162#else
163
164#define ASSERT_ARG(argName, assertion) do \
165 if (!(assertion)) { \
166 WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #argName, #assertion); \
167 CRASH(); \
168 } \
169while (0)
170
171#endif
172
173/* COMPILE_ASSERT */
174#ifndef COMPILE_ASSERT
175#define COMPILE_ASSERT(exp, name) typedef int dummy##name [(exp) ? 1 : -1];
176#endif
177
178/* FATAL */
179
180#if FATAL_DISABLED
181#define FATAL(...) ((void)0)
182#elif COMPILER(MSVC7)
183#define FATAL() ((void)0)
184#else
185#define FATAL(...) do { \
186 WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__); \
187 CRASH(); \
188} while (0)
189#endif
190
191/* LOG_ERROR */
192
193#if ERROR_DISABLED
194#define LOG_ERROR(...) ((void)0)
195#elif COMPILER(MSVC7)
196#define LOG_ERROR() ((void)0)
197#else
198#define LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__)
199#endif
200
201/* LOG */
202
203#if LOG_DISABLED
204#define LOG(channel, ...) ((void)0)
205#elif COMPILER(MSVC7)
206#define LOG() ((void)0)
207#else
208#define LOG(channel, ...) WTFLog(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), __VA_ARGS__)
209#define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel)
210#define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel
211#endif
212
213/* LOG_VERBOSE */
214
215#if LOG_DISABLED
216#define LOG_VERBOSE(channel, ...) ((void)0)
217#elif COMPILER(MSVC7)
218#define LOG_VERBOSE(channel) ((void)0)
219#else
220#define LOG_VERBOSE(channel, ...) WTFLogVerbose(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, &JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), __VA_ARGS__)
221#endif
222
223#endif // WTF_Assertions_h
Note: See TracBrowser for help on using the repository browser.