Reviewed by Adam.
* wtf/Assertions.cpp: Changed assertion formatting to omit the "======"
lines so you can see more assertions in less space. Also improved format
of file/line information so it works with more development environments.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@16782 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/wtf/Assertions.cpp b/JavaScriptCore/wtf/Assertions.cpp
index e916314..74a1af4 100644
--- a/JavaScriptCore/wtf/Assertions.cpp
+++ b/JavaScriptCore/wtf/Assertions.cpp
@@ -38,15 +38,16 @@
#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
#include <windows.h>
+#include <crtdbg.h>
#endif
extern "C" {
// This is to work around the "you should use a printf format attribute" warning on GCC
// We can't use _attribute__ ((format (printf, 2, 3))) since we allow %@
-static int (* vfprintf_no_warning)(FILE *, const char *, va_list) = vfprintf;
+static int (* vfprintf_no_warning)(FILE *, const char*, va_list) = vfprintf;
-static void vprintf_stderr_common(const char *format, va_list args)
+static void vprintf_stderr_common(const char* format, va_list args)
{
#if PLATFORM(MAC)
if (strstr(format, "%@")) {
@@ -54,7 +55,7 @@
CFStringRef str = CFStringCreateWithFormatAndArguments(NULL, NULL, cfFormat, args);
int length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8);
- char *buffer = (char *)malloc(length + 1);
+ char* buffer = (char*)malloc(length + 1);
CFStringGetCString(str, buffer, length, kCFStringEncodingUTF8);
@@ -65,19 +66,16 @@
CFRelease(cfFormat);
} else
#elif PLATFORM(WIN)
- if (IsDebuggerPresent())
- {
+ if (IsDebuggerPresent()) {
size_t size = 1024;
- do
- {
+ do {
char* buffer = (char*)malloc(size);
if (buffer == NULL)
break;
- if (_vsnprintf(buffer, size, format, args) != -1)
- {
+ if (_vsnprintf(buffer, size, format, args) != -1) {
OutputDebugStringA(buffer);
free(buffer);
break;
@@ -91,7 +89,7 @@
vfprintf_no_warning(stderr, format, args);
}
-static void printf_stderr_common(const char * format, ...)
+static void printf_stderr_common(const char* format, ...)
{
va_list args;
va_start(args, format);
@@ -99,50 +97,64 @@
va_end(args);
}
-void WTFReportAssertionFailure(const char *file, int line, const char *function, const char *assertion)
+static void printCallSite(const char* file, int line, const char* function)
+{
+#if PLATFORM(WIN)
+ _CrtDbgReport(_CRT_WARN, file, line, NULL, "%s\n", function);
+#else
+ printf_stderr_common("(%s:%d %s)\n", file, line, function);
+#endif
+}
+
+void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion)
{
if (assertion)
- printf_stderr_common("=================\nASSERTION FAILED: %s (%s:%d %s)\n=================\n", assertion, file, line, function);
+ printf_stderr_common("ASSERTION FAILED: %s\n", assertion);
else
- printf_stderr_common("=================\nSHOULD NEVER BE REACHED (%s:%d %s)\n=================\n", file, line, function);
+ printf_stderr_common("SHOULD NEVER BE REACHED\n");
+ printCallSite(file, line, function);
}
-void WTFReportAssertionFailureWithMessage(const char *file, int line, const char *function, const char *assertion, const char *format, ...)
+void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...)
{
- printf_stderr_common("=================\nASSERTION FAILED: ");
+ printf_stderr_common("ASSERTION FAILED: ");
va_list args;
va_start(args, format);
vprintf_stderr_common(format, args);
va_end(args);
- printf_stderr_common("\n%s (%s:%d %s)\n=================\n", assertion, file, line, function);
+ printf_stderr_common("\n%s\n", assertion);
+ printCallSite(file, line, function);
}
-void WTFReportArgumentAssertionFailure(const char *file, int line, const char *function, const char *argName, const char *assertion)
+void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion)
{
- printf_stderr_common("=================\nARGUMENT BAD: %s, %s (%s:%d %s)\n=================\n", argName, assertion, file, line, function);
+ printf_stderr_common("ARGUMENT BAD: %s, %s\n", argName, assertion);
+ printCallSite(file, line, function);
}
-void WTFReportFatalError(const char *file, int line, const char *function, const char *format, ...)
+void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...)
{
- printf_stderr_common("=================\nFATAL ERROR: ");
+ printf_stderr_common("FATAL ERROR: ");
va_list args;
va_start(args, format);
vprintf_stderr_common(format, args);
va_end(args);
- printf_stderr_common("\n(%s:%d %s)\n=================\n", file, line, function);
+ printf_stderr_common("\n");
+ printCallSite(file, line, function);
}
-void WTFReportError(const char *file, int line, const char *function, const char *format, ...)
+void WTFReportError(const char* file, int line, const char* function, const char* format, ...)
{
- printf_stderr_common("=================\nERROR: ");
+ printf_stderr_common("ERROR: ");
va_list args;
va_start(args, format);
vprintf_stderr_common(format, args);
va_end(args);
- printf_stderr_common("\n(%s:%d %s)\n=================\n", file, line, function);
+ printf_stderr_common("\n");
+ printCallSite(file, line, function);
}
-void WTFLog(const char*, int, const char*, WTFLogChannel *channel, const char *format, ...)
+void WTFLog(const char*, int, const char*, WTFLogChannel *channel, const char* format, ...)
{
if (channel->state != WTFLogChannelOn)
return;