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

Last change on this file since 16089 was 15906, checked in by sfalken, 19 years ago

2006-08-15 Steve Falkenburg <[email protected]>

Reviewed by mjs.


Build fix.

  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • wtf/Assertions.h:
  • Property svn:eol-style set to native
File size: 5.7 KB
Line 
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * Copyright (C) 2003, 2006 Apple Computer, 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 KXMLCORE_ASSERTIONS_H
28#define KXMLCORE_ASSERTIONS_H
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#include "Platform.h"
39
40#ifdef NDEBUG
41#define ASSERTIONS_DISABLED_DEFAULT 1
42#else
43#define ASSERTIONS_DISABLED_DEFAULT 0
44#endif
45
46#ifndef ASSERT_DISABLED
47#define ASSERT_DISABLED ASSERTIONS_DISABLED_DEFAULT
48#endif
49
50#ifndef ASSERT_ARG_DISABLED
51#define ASSERT_ARG_DISABLED ASSERTIONS_DISABLED_DEFAULT
52#endif
53
54#ifndef FATAL_DISABLED
55#define FATAL_DISABLED ASSERTIONS_DISABLED_DEFAULT
56#endif
57
58#ifndef ERROR_DISABLED
59#define ERROR_DISABLED ASSERTIONS_DISABLED_DEFAULT
60#endif
61
62#ifndef LOG_DISABLED
63#define LOG_DISABLED ASSERTIONS_DISABLED_DEFAULT
64#endif
65
66#if COMPILER(GCC)
67#define KXMLCORE_PRETTY_FUNCTION __PRETTY_FUNCTION__
68#else
69#define KXMLCORE_PRETTY_FUNCTION __FUNCTION__
70#endif
71
72// These helper functions are always declared, but not necessarily always defined if the corresponding function is disabled.
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
78typedef enum { WTFLogChannelOff, WTFLogChannelOn } WTFLogChannelState;
79
80typedef struct {
81 unsigned mask;
82 const char *defaultName;
83 WTFLogChannelState state;
84} WTFLogChannel;
85
86void WTFReportAssertionFailure(const char *file, int line, const char *function, const char *assertion);
87void WTFReportAssertionFailureWithMessage(const char *file, int line, const char *function, const char *assertion, const char *format, ...);
88void WTFReportArgumentAssertionFailure(const char *file, int line, const char *function, const char *argName, const char *assertion);
89void WTFReportFatalError(const char *file, int line, const char *function, const char *format, ...) ;
90void WTFReportError(const char *file, int line, const char *function, const char *format, ...);
91void WTFLog(const char *file, int line, const char *function, WTFLogChannel *channel, const char *format, ...);
92
93#ifdef __cplusplus
94}
95#endif
96
97// CRASH -- gets us into the debugger or the crash reporter -- signals are ignored by the crash reporter so we must do better
98
99#define CRASH() *(int *)(uintptr_t)0xbbadbeef = 0
100
101// ASSERT, ASSERT_WITH_MESSAGE, ASSERT_NOT_REACHED
102
103#if PLATFORM(WIN_OS)
104// FIXME: Change to use something other than ASSERT to avoid this conflict with win32.
105#undef ASSERT
106#endif
107
108#if ASSERT_DISABLED
109
110#define ASSERT(assertion) ((void)0)
111#define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0)
112#define ASSERT_NOT_REACHED() ((void)0)
113
114#else
115
116#define ASSERT(assertion) do \
117 if (!(assertion)) { \
118 WTFReportAssertionFailure(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, #assertion); \
119 CRASH(); \
120 } \
121while (0)
122#define ASSERT_WITH_MESSAGE(assertion, ...) do \
123 if (!(assertion)) { \
124 WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, #assertion, __VA_ARGS__); \
125 CRASH(); \
126 } \
127while (0)
128#define ASSERT_NOT_REACHED() do { \
129 WTFReportAssertionFailure(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, 0); \
130 CRASH(); \
131} while (0)
132
133#endif
134
135// ASSERT_ARG
136
137#if ASSERT_ARG_DISABLED
138
139#define ASSERT_ARG(argName, assertion) ((void)0)
140
141#else
142
143#define ASSERT_ARG(argName, assertion) do \
144 if (!(assertion)) { \
145 WTFReportArgumentAssertionFailure(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, #argName, #assertion); \
146 CRASH(); \
147 } \
148while (0)
149
150#endif
151
152// FATAL
153
154#if FATAL_DISABLED
155#define FATAL(...) ((void)0)
156#else
157#define FATAL(...) do { \
158 WTFReportFatalError(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, __VA_ARGS__); \
159 CRASH(); \
160} while (0)
161#endif
162
163// LOG_ERROR
164
165#if ERROR_DISABLED
166#define LOG_ERROR(...) ((void)0)
167#else
168#define LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, __VA_ARGS__)
169#endif
170
171// LOG
172
173#if LOG_DISABLED
174#define LOG(channel, ...) ((void)0)
175#else
176#define LOG(channel, ...) WTFLog(__FILE__, __LINE__, KXMLCORE_PRETTY_FUNCTION, &JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), __VA_ARGS__)
177#define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel)
178#define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel
179#endif
180
181#endif // KXMLCORE_ASSERTIONS_H
Note: See TracBrowser for help on using the repository browser.