]>
git.saurik.com Git - apple/javascriptcore.git/blob - wtf/Assertions.cpp
d629545b46590fb769da1af3c439dd8ceee6a405
2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "Assertions.h"
33 #include <CoreFoundation/CFString.h>
35 #if COMPILER(MSVC) && !PLATFORM(WIN_CE)
40 #define _WIN32_WINNT 0x0500
48 WTF_ATTRIBUTE_PRINTF(1, 0)
49 static void vprintf_stderr_common(const char* format
, va_list args
)
51 if (strstr(format
, "%@")) {
52 CFStringRef cfFormat
= CFStringCreateWithCString(NULL
, format
, kCFStringEncodingUTF8
);
53 CFStringRef str
= CFStringCreateWithFormatAndArguments(NULL
, NULL
, cfFormat
, args
);
55 int length
= CFStringGetMaximumSizeForEncoding(CFStringGetLength(str
), kCFStringEncodingUTF8
);
56 char* buffer
= (char*)malloc(length
+ 1);
58 CFStringGetCString(str
, buffer
, length
, kCFStringEncodingUTF8
);
60 fputs(buffer
, stderr
);
66 vfprintf(stderr
, format
, args
);
69 WTF_ATTRIBUTE_PRINTF(1, 2)
70 static void printf_stderr_common(const char* format
, ...)
73 va_start(args
, format
);
74 vprintf_stderr_common(format
, args
);
78 static void printCallSite(const char* file
, int line
, const char* function
)
80 #if PLATFORM(WIN) && defined _DEBUG
81 _CrtDbgReport(_CRT_WARN
, file
, line
, NULL
, "%s\n", function
);
83 printf_stderr_common("(%s:%d %s)\n", file
, line
, function
);
87 void WTFReportAssertionFailure(const char* file
, int line
, const char* function
, const char* assertion
)
90 printf_stderr_common("ASSERTION FAILED: %s\n", assertion
);
92 printf_stderr_common("SHOULD NEVER BE REACHED\n");
93 printCallSite(file
, line
, function
);
96 void WTFReportAssertionFailureWithMessage(const char* file
, int line
, const char* function
, const char* assertion
, const char* format
, ...)
98 printf_stderr_common("ASSERTION FAILED: ");
100 va_start(args
, format
);
101 vprintf_stderr_common(format
, args
);
103 printf_stderr_common("\n%s\n", assertion
);
104 printCallSite(file
, line
, function
);
107 void WTFReportArgumentAssertionFailure(const char* file
, int line
, const char* function
, const char* argName
, const char* assertion
)
109 printf_stderr_common("ARGUMENT BAD: %s, %s\n", argName
, assertion
);
110 printCallSite(file
, line
, function
);
113 void WTFReportFatalError(const char* file
, int line
, const char* function
, const char* format
, ...)
115 printf_stderr_common("FATAL ERROR: ");
117 va_start(args
, format
);
118 vprintf_stderr_common(format
, args
);
120 printf_stderr_common("\n");
121 printCallSite(file
, line
, function
);
124 void WTFReportError(const char* file
, int line
, const char* function
, const char* format
, ...)
126 printf_stderr_common("ERROR: ");
128 va_start(args
, format
);
129 vprintf_stderr_common(format
, args
);
131 printf_stderr_common("\n");
132 printCallSite(file
, line
, function
);
135 void WTFLog(WTFLogChannel
* channel
, const char* format
, ...)
137 if (channel
->state
!= WTFLogChannelOn
)
141 va_start(args
, format
);
142 vprintf_stderr_common(format
, args
);
144 if (format
[strlen(format
) - 1] != '\n')
145 printf_stderr_common("\n");
148 void WTFLogVerbose(const char* file
, int line
, const char* function
, WTFLogChannel
* channel
, const char* format
, ...)
150 if (channel
->state
!= WTFLogChannelOn
)
154 va_start(args
, format
);
155 vprintf_stderr_common(format
, args
);
157 if (format
[strlen(format
) - 1] != '\n')
158 printf_stderr_common("\n");
159 printCallSite(file
, line
, function
);