source: webkit/trunk/JavaScriptCore/wtf/Assertions.cpp@ 27808

Last change on this file since 27808 was 26589, checked in by bdash, 18 years ago

2007-10-14 Kevin Ollivier <[email protected]>

Reviewed by Adam.

Add support for MSVC7, and fix cases where PLATFORM(WIN) should
be PLATFORM(WIN_OS) for other ports building on Windows.

  • dom/XMLTokenizer.cpp:
  • page/FrameTree.cpp:
  • platform/StaticConstructors.h:
  • platform/String.cpp:

2007-10-5 Kevin Ollivier <[email protected]>

Reviewed by Adam.


Add support for MSVC7, and fix cases where PLATFORM(WIN) should
be PLATFORM(WIN_OS) for other ports building on Windows.


  • kjs/DateMath.cpp: (KJS::getDSTOffsetSimple):
  • kjs/JSImmediate.h:
  • wtf/Assertions.cpp:
  • wtf/Assertions.h:
  • wtf/Platform.h:
  • wtf/StringExtras.h: (snprintf): (vsnprintf):
  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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.
25 */
26
27#include "config.h"
28#include "Assertions.h"
29
30#include <stdio.h>
31#include <stdarg.h>
32#include <string.h>
33
34#if PLATFORM(MAC)
35#include <CoreFoundation/CFString.h>
36#endif
37
38#if COMPILER(MSVC)
39#ifndef WINVER
40#define WINVER 0x0500
41#endif
42#ifndef _WIN32_WINNT
43#define _WIN32_WINNT 0x0500
44#endif
45#include <windows.h>
46#include <crtdbg.h>
47#endif
48
49extern "C" {
50
51// This is to work around the "you should use a printf format attribute" warning on GCC
52// We can't use _attribute__ ((format (printf, 2, 3))) since we allow %@
53static int (* vfprintf_no_warning)(FILE *, const char*, va_list) = vfprintf;
54
55static void vprintf_stderr_common(const char* format, va_list args)
56{
57#if PLATFORM(MAC)
58 if (strstr(format, "%@")) {
59 CFStringRef cfFormat = CFStringCreateWithCString(NULL, format, kCFStringEncodingUTF8);
60 CFStringRef str = CFStringCreateWithFormatAndArguments(NULL, NULL, cfFormat, args);
61
62 int length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8);
63 char* buffer = (char*)malloc(length + 1);
64
65 CFStringGetCString(str, buffer, length, kCFStringEncodingUTF8);
66
67 fputs(buffer, stderr);
68
69 free(buffer);
70 CFRelease(str);
71 CFRelease(cfFormat);
72 } else
73#elif COMPILER(MSVC)
74 if (IsDebuggerPresent()) {
75 size_t size = 1024;
76
77 do {
78 char* buffer = (char*)malloc(size);
79
80 if (buffer == NULL)
81 break;
82
83 if (_vsnprintf(buffer, size, format, args) != -1) {
84 OutputDebugStringA(buffer);
85 free(buffer);
86 break;
87 }
88
89 free(buffer);
90 size *= 2;
91 } while (size > 1024);
92 }
93#endif
94 vfprintf_no_warning(stderr, format, args);
95}
96
97static void printf_stderr_common(const char* format, ...)
98{
99 va_list args;
100 va_start(args, format);
101 vprintf_stderr_common(format, args);
102 va_end(args);
103}
104
105static void printCallSite(const char* file, int line, const char* function)
106{
107#if PLATFORM(WIN) && defined _DEBUG
108 _CrtDbgReport(_CRT_WARN, file, line, NULL, "%s\n", function);
109#else
110 printf_stderr_common("(%s:%d %s)\n", file, line, function);
111#endif
112}
113
114void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion)
115{
116 if (assertion)
117 printf_stderr_common("ASSERTION FAILED: %s\n", assertion);
118 else
119 printf_stderr_common("SHOULD NEVER BE REACHED\n");
120 printCallSite(file, line, function);
121}
122
123void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...)
124{
125 printf_stderr_common("ASSERTION FAILED: ");
126 va_list args;
127 va_start(args, format);
128 vprintf_stderr_common(format, args);
129 va_end(args);
130 printf_stderr_common("\n%s\n", assertion);
131 printCallSite(file, line, function);
132}
133
134void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion)
135{
136 printf_stderr_common("ARGUMENT BAD: %s, %s\n", argName, assertion);
137 printCallSite(file, line, function);
138}
139
140void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...)
141{
142 printf_stderr_common("FATAL ERROR: ");
143 va_list args;
144 va_start(args, format);
145 vprintf_stderr_common(format, args);
146 va_end(args);
147 printf_stderr_common("\n");
148 printCallSite(file, line, function);
149}
150
151void WTFReportError(const char* file, int line, const char* function, const char* format, ...)
152{
153 printf_stderr_common("ERROR: ");
154 va_list args;
155 va_start(args, format);
156 vprintf_stderr_common(format, args);
157 va_end(args);
158 printf_stderr_common("\n");
159 printCallSite(file, line, function);
160}
161
162void WTFLog(WTFLogChannel* channel, const char* format, ...)
163{
164 if (channel->state != WTFLogChannelOn)
165 return;
166
167 va_list args;
168 va_start(args, format);
169 vprintf_stderr_common(format, args);
170 va_end(args);
171 if (format[strlen(format) - 1] != '\n')
172 printf_stderr_common("\n");
173}
174
175void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel* channel, const char* format, ...)
176{
177 if (channel->state != WTFLogChannelOn)
178 return;
179
180 va_list args;
181 va_start(args, format);
182 vprintf_stderr_common(format, args);
183 va_end(args);
184 if (format[strlen(format) - 1] != '\n')
185 printf_stderr_common("\n");
186 printCallSite(file, line, function);
187}
188
189} // extern "C"
Note: See TracBrowser for help on using the repository browser.