michael@0: /* michael@0: * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. michael@0: * Copyright (C) 2007-2009 Torch Mobile, Inc. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * 1. Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * 2. Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY michael@0: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE michael@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR michael@0: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR michael@0: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, michael@0: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR michael@0: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY michael@0: * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: #include "assembler/wtf/Assertions.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #if WTF_COMPILER_MSVC michael@0: #ifndef WINVER michael@0: #define WINVER 0x0500 michael@0: #endif michael@0: #ifndef _WIN32_WINNT michael@0: #define _WIN32_WINNT 0x0500 michael@0: #endif michael@0: #include "jswin.h" michael@0: #include michael@0: #endif michael@0: michael@0: extern "C" { michael@0: michael@0: WTF_ATTRIBUTE_PRINTF(1, 0) michael@0: static void vprintf_stderr_common(const char* format, va_list args) michael@0: { michael@0: vfprintf(stderr, format, args); michael@0: } michael@0: michael@0: WTF_ATTRIBUTE_PRINTF(1, 2) michael@0: static void printf_stderr_common(const char* format, ...) michael@0: { michael@0: va_list args; michael@0: va_start(args, format); michael@0: vprintf_stderr_common(format, args); michael@0: va_end(args); michael@0: } michael@0: michael@0: static void printCallSite(const char* file, int line, const char* function) michael@0: { michael@0: #if WTF_COMPILER_MSVC && defined _DEBUG michael@0: _CrtDbgReport(_CRT_WARN, file, line, NULL, "%s\n", function); michael@0: #else michael@0: printf_stderr_common("(%s:%d %s)\n", file, line, function); michael@0: #endif michael@0: } michael@0: michael@0: void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion) michael@0: { michael@0: if (assertion) michael@0: printf_stderr_common("Assertion failure: %s\n", assertion); michael@0: else michael@0: printf_stderr_common("Should never be reached\n"); michael@0: printCallSite(file, line, function); michael@0: } michael@0: michael@0: void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...) michael@0: { michael@0: printf_stderr_common("Assertion failure: "); michael@0: va_list args; michael@0: va_start(args, format); michael@0: vprintf_stderr_common(format, args); michael@0: va_end(args); michael@0: printf_stderr_common("\n%s\n", assertion); michael@0: printCallSite(file, line, function); michael@0: } michael@0: michael@0: void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion) michael@0: { michael@0: printf_stderr_common("Argument bad: %s, %s\n", argName, assertion); michael@0: printCallSite(file, line, function); michael@0: } michael@0: michael@0: void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...) michael@0: { michael@0: printf_stderr_common("Fatal error: "); michael@0: va_list args; michael@0: va_start(args, format); michael@0: vprintf_stderr_common(format, args); michael@0: va_end(args); michael@0: printf_stderr_common("\n"); michael@0: printCallSite(file, line, function); michael@0: } michael@0: michael@0: void WTFReportError(const char* file, int line, const char* function, const char* format, ...) michael@0: { michael@0: printf_stderr_common("Error: "); michael@0: va_list args; michael@0: va_start(args, format); michael@0: vprintf_stderr_common(format, args); michael@0: va_end(args); michael@0: printf_stderr_common("\n"); michael@0: printCallSite(file, line, function); michael@0: } michael@0: michael@0: void WTFLog(WTFLogChannel* channel, const char* format, ...) michael@0: { michael@0: if (channel->state != WTFLogChannelOn) michael@0: return; michael@0: michael@0: va_list args; michael@0: va_start(args, format); michael@0: vprintf_stderr_common(format, args); michael@0: va_end(args); michael@0: if (format[strlen(format) - 1] != '\n') michael@0: printf_stderr_common("\n"); michael@0: } michael@0: michael@0: void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel* channel, const char* format, ...) michael@0: { michael@0: if (channel->state != WTFLogChannelOn) michael@0: return; michael@0: michael@0: va_list args; michael@0: va_start(args, format); michael@0: vprintf_stderr_common(format, args); michael@0: va_end(args); michael@0: if (format[strlen(format) - 1] != '\n') michael@0: printf_stderr_common("\n"); michael@0: printCallSite(file, line, function); michael@0: } michael@0: michael@0: } // extern "C"