]>
git.saurik.com Git - apple/javascriptcore.git/blob - wtf/Assertions.cpp
1 // -*- mode: c++; c-basic-offset: 4 -*-
3 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
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>
41 #define _WIN32_WINNT 0x0500
49 WTF_ATTRIBUTE_PRINTF(1, 0)
50 static void vprintf_stderr_common(const char* format
, va_list args
)
52 if (strstr(format
, "%@")) {
53 CFStringRef cfFormat
= CFStringCreateWithCString(NULL
, format
, kCFStringEncodingUTF8
);
54 CFStringRef str
= CFStringCreateWithFormatAndArguments(NULL
, NULL
, cfFormat
, args
);
56 int length
= CFStringGetMaximumSizeForEncoding(CFStringGetLength(str
), kCFStringEncodingUTF8
);
57 char* buffer
= (char*)malloc(length
+ 1);
59 CFStringGetCString(str
, buffer
, length
, kCFStringEncodingUTF8
);
61 fputs(buffer
, stderr
);
67 vfprintf(stderr
, format
, args
);
70 WTF_ATTRIBUTE_PRINTF(1, 2)
71 static void printf_stderr_common(const char* format
, ...)
74 va_start(args
, format
);
75 vprintf_stderr_common(format
, args
);
79 static void printCallSite(const char* file
, int line
, const char* function
)
81 #if PLATFORM(WIN) && defined _DEBUG
82 _CrtDbgReport(_CRT_WARN
, file
, line
, NULL
, "%s\n", function
);
84 printf_stderr_common("(%s:%d %s)\n", file
, line
, function
);
88 void WTFReportAssertionFailure(const char* file
, int line
, const char* function
, const char* assertion
)
91 printf_stderr_common("ASSERTION FAILED: %s\n", assertion
);
93 printf_stderr_common("SHOULD NEVER BE REACHED\n");
94 printCallSite(file
, line
, function
);
97 void WTFReportAssertionFailureWithMessage(const char* file
, int line
, const char* function
, const char* assertion
, const char* format
, ...)
99 printf_stderr_common("ASSERTION FAILED: ");
101 va_start(args
, format
);
102 vprintf_stderr_common(format
, args
);
104 printf_stderr_common("\n%s\n", assertion
);
105 printCallSite(file
, line
, function
);
108 void WTFReportArgumentAssertionFailure(const char* file
, int line
, const char* function
, const char* argName
, const char* assertion
)
110 printf_stderr_common("ARGUMENT BAD: %s, %s\n", argName
, assertion
);
111 printCallSite(file
, line
, function
);
114 void WTFReportFatalError(const char* file
, int line
, const char* function
, const char* format
, ...)
116 printf_stderr_common("FATAL ERROR: ");
118 va_start(args
, format
);
119 vprintf_stderr_common(format
, args
);
121 printf_stderr_common("\n");
122 printCallSite(file
, line
, function
);
125 void WTFReportError(const char* file
, int line
, const char* function
, const char* format
, ...)
127 printf_stderr_common("ERROR: ");
129 va_start(args
, format
);
130 vprintf_stderr_common(format
, args
);
132 printf_stderr_common("\n");
133 printCallSite(file
, line
, function
);
136 void WTFLog(WTFLogChannel
* channel
, const char* format
, ...)
138 if (channel
->state
!= WTFLogChannelOn
)
142 va_start(args
, format
);
143 vprintf_stderr_common(format
, args
);
145 if (format
[strlen(format
) - 1] != '\n')
146 printf_stderr_common("\n");
149 void WTFLogVerbose(const char* file
, int line
, const char* function
, WTFLogChannel
* channel
, const char* format
, ...)
151 if (channel
->state
!= WTFLogChannelOn
)
155 va_start(args
, format
);
156 vprintf_stderr_common(format
, args
);
158 if (format
[strlen(format
) - 1] != '\n')
159 printf_stderr_common("\n");
160 printCallSite(file
, line
, function
);