]>
git.saurik.com Git - apple/javascriptcore.git/blob - wtf/Assertions.cpp
2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007-2009 Torch Mobile, Inc.
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.
28 #include "Assertions.h"
34 #include <CoreFoundation/CFString.h>
36 #if COMPILER(MSVC) && !OS(WINCE)
41 #define _WIN32_WINNT 0x0500
53 WTF_ATTRIBUTE_PRINTF(1, 0)
54 static void vprintf_stderr_common(const char* format
, va_list args
)
56 if (strstr(format
, "%@")) {
57 CFStringRef cfFormat
= CFStringCreateWithCString(NULL
, format
, kCFStringEncodingUTF8
);
58 CFStringRef str
= CFStringCreateWithFormatAndArguments(NULL
, NULL
, cfFormat
, args
);
60 int length
= CFStringGetMaximumSizeForEncoding(CFStringGetLength(str
), kCFStringEncodingUTF8
);
61 char* buffer
= (char*)malloc(length
+ 1);
63 CFStringGetCString(str
, buffer
, length
, kCFStringEncodingUTF8
);
65 fputs(buffer
, stderr
);
72 vfprintf(stdout
, format
, args
);
74 vfprintf(stderr
, format
, args
);
78 WTF_ATTRIBUTE_PRINTF(1, 2)
79 static void printf_stderr_common(const char* format
, ...)
82 va_start(args
, format
);
83 vprintf_stderr_common(format
, args
);
87 static void printCallSite(const char* file
, int line
, const char* function
)
89 #if OS(WIN) && !OS(WINCE) && defined _DEBUG
90 _CrtDbgReport(_CRT_WARN
, file
, line
, NULL
, "%s\n", function
);
92 printf_stderr_common("(%s:%d %s)\n", file
, line
, function
);
96 void WTFReportAssertionFailure(const char* file
, int line
, const char* function
, const char* assertion
)
99 printf_stderr_common("ASSERTION FAILED: %s\n", assertion
);
101 printf_stderr_common("SHOULD NEVER BE REACHED\n");
102 printCallSite(file
, line
, function
);
105 void WTFReportAssertionFailureWithMessage(const char* file
, int line
, const char* function
, const char* assertion
, const char* format
, ...)
107 printf_stderr_common("ASSERTION FAILED: ");
109 va_start(args
, format
);
110 vprintf_stderr_common(format
, args
);
112 printf_stderr_common("\n%s\n", assertion
);
113 printCallSite(file
, line
, function
);
116 void WTFReportArgumentAssertionFailure(const char* file
, int line
, const char* function
, const char* argName
, const char* assertion
)
118 printf_stderr_common("ARGUMENT BAD: %s, %s\n", argName
, assertion
);
119 printCallSite(file
, line
, function
);
122 void WTFReportFatalError(const char* file
, int line
, const char* function
, const char* format
, ...)
124 printf_stderr_common("FATAL ERROR: ");
126 va_start(args
, format
);
127 vprintf_stderr_common(format
, args
);
129 printf_stderr_common("\n");
130 printCallSite(file
, line
, function
);
133 void WTFReportError(const char* file
, int line
, const char* function
, const char* format
, ...)
135 printf_stderr_common("ERROR: ");
137 va_start(args
, format
);
138 vprintf_stderr_common(format
, args
);
140 printf_stderr_common("\n");
141 printCallSite(file
, line
, function
);
144 void WTFLog(WTFLogChannel
* channel
, const char* format
, ...)
146 if (channel
->state
!= WTFLogChannelOn
)
150 va_start(args
, format
);
151 vprintf_stderr_common(format
, args
);
153 if (format
[strlen(format
) - 1] != '\n')
154 printf_stderr_common("\n");
157 void WTFLogVerbose(const char* file
, int line
, const char* function
, WTFLogChannel
* channel
, const char* format
, ...)
159 if (channel
->state
!= WTFLogChannelOn
)
163 va_start(args
, format
);
164 vprintf_stderr_common(format
, args
);
166 if (format
[strlen(format
) - 1] != '\n')
167 printf_stderr_common("\n");
168 printCallSite(file
, line
, function
);