Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2258)

Unified Diff: third_party/WebKit/Source/wtf/Assertions.cpp

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/Assertions.h ('k') | third_party/WebKit/Source/wtf/AssertionsTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/Assertions.cpp
diff --git a/third_party/WebKit/Source/wtf/Assertions.cpp b/third_party/WebKit/Source/wtf/Assertions.cpp
index d72aa692d7c058944dec6928f07e7474c6395b7b..7cad6ea81d9869e28921a3dee891ccd50c531af1 100644
--- a/third_party/WebKit/Source/wtf/Assertions.cpp
+++ b/third_party/WebKit/Source/wtf/Assertions.cpp
@@ -50,7 +50,7 @@
#define WTF_USE_APPLE_SYSTEM_LOG 1
#include <asl.h>
#endif
-#endif // OS(MACOSX)
+#endif // OS(MACOSX)
#if COMPILER(MSVC)
#include <crtdbg.h>
@@ -71,68 +71,70 @@
#endif
WTF_ATTRIBUTE_PRINTF(1, 0)
-static void vprintf_stderr_common(const char* format, va_list args)
-{
+static void vprintf_stderr_common(const char* format, va_list args) {
#if OS(MACOSX)
- if (strstr(format, "%@")) {
- CFStringRef cfFormat = CFStringCreateWithCString(nullptr, format, kCFStringEncodingUTF8);
+ if (strstr(format, "%@")) {
+ CFStringRef cfFormat =
+ CFStringCreateWithCString(nullptr, format, kCFStringEncodingUTF8);
#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
- CFStringRef str = CFStringCreateWithFormatAndArguments(nullptr, nullptr, cfFormat, args);
+ CFStringRef str =
+ CFStringCreateWithFormatAndArguments(nullptr, nullptr, cfFormat, args);
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
- CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8);
- char* buffer = (char*)malloc(length + 1);
+ CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str),
+ kCFStringEncodingUTF8);
+ char* buffer = (char*)malloc(length + 1);
- CFStringGetCString(str, buffer, length, kCFStringEncodingUTF8);
+ CFStringGetCString(str, buffer, length, kCFStringEncodingUTF8);
#if USE(APPLE_SYSTEM_LOG)
- asl_log(0, 0, ASL_LEVEL_NOTICE, "%s", buffer);
+ asl_log(0, 0, ASL_LEVEL_NOTICE, "%s", buffer);
#endif
- fputs(buffer, stderr);
+ fputs(buffer, stderr);
- free(buffer);
- CFRelease(str);
- CFRelease(cfFormat);
- return;
- }
+ free(buffer);
+ CFRelease(str);
+ CFRelease(cfFormat);
+ return;
+ }
#if USE(APPLE_SYSTEM_LOG)
- va_list copyOfArgs;
- va_copy(copyOfArgs, args);
- asl_vlog(0, 0, ASL_LEVEL_NOTICE, format, copyOfArgs);
- va_end(copyOfArgs);
+ va_list copyOfArgs;
+ va_copy(copyOfArgs, args);
+ asl_vlog(0, 0, ASL_LEVEL_NOTICE, format, copyOfArgs);
+ va_end(copyOfArgs);
#endif
- // Fall through to write to stderr in the same manner as other platforms.
+// Fall through to write to stderr in the same manner as other platforms.
#elif OS(ANDROID)
- __android_log_vprint(ANDROID_LOG_WARN, "WebKit", format, args);
+ __android_log_vprint(ANDROID_LOG_WARN, "WebKit", format, args);
#elif OS(WIN)
- if (IsDebuggerPresent()) {
- size_t size = 1024;
-
- do {
- char* buffer = (char*)malloc(size);
- if (!buffer)
- break;
-
- if (_vsnprintf(buffer, size, format, args) != -1) {
- OutputDebugStringA(buffer);
- free(buffer);
- break;
- }
-
- free(buffer);
- size *= 2;
- } while (size > 1024);
- }
+ if (IsDebuggerPresent()) {
+ size_t size = 1024;
+
+ do {
+ char* buffer = (char*)malloc(size);
+ if (!buffer)
+ break;
+
+ if (_vsnprintf(buffer, size, format, args) != -1) {
+ OutputDebugStringA(buffer);
+ free(buffer);
+ break;
+ }
+
+ free(buffer);
+ size *= 2;
+ } while (size > 1024);
+ }
#endif
- vfprintf(stderr, format, args);
+ vfprintf(stderr, format, args);
}
#if COMPILER(CLANG) || (COMPILER(GCC) && GCC_VERSION_AT_LEAST(4, 6, 0))
@@ -140,32 +142,34 @@ static void vprintf_stderr_common(const char* format, va_list args)
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
-static void vprintf_stderr_with_prefix(const char* prefix, const char* format, va_list args)
-{
- size_t prefixLength = strlen(prefix);
- size_t formatLength = strlen(format);
- OwnPtr<char[]> formatWithPrefix = adoptArrayPtr(new char[prefixLength + formatLength + 1]);
- memcpy(formatWithPrefix.get(), prefix, prefixLength);
- memcpy(formatWithPrefix.get() + prefixLength, format, formatLength);
- formatWithPrefix[prefixLength + formatLength] = 0;
-
- vprintf_stderr_common(formatWithPrefix.get(), args);
+static void vprintf_stderr_with_prefix(const char* prefix,
+ const char* format,
+ va_list args) {
+ size_t prefixLength = strlen(prefix);
+ size_t formatLength = strlen(format);
+ OwnPtr<char[]> formatWithPrefix =
+ adoptArrayPtr(new char[prefixLength + formatLength + 1]);
+ memcpy(formatWithPrefix.get(), prefix, prefixLength);
+ memcpy(formatWithPrefix.get() + prefixLength, format, formatLength);
+ formatWithPrefix[prefixLength + formatLength] = 0;
+
+ vprintf_stderr_common(formatWithPrefix.get(), args);
}
-static void vprintf_stderr_with_trailing_newline(const char* format, va_list args)
-{
- size_t formatLength = strlen(format);
- if (formatLength && format[formatLength - 1] == '\n') {
- vprintf_stderr_common(format, args);
- return;
- }
+static void vprintf_stderr_with_trailing_newline(const char* format,
+ va_list args) {
+ size_t formatLength = strlen(format);
+ if (formatLength && format[formatLength - 1] == '\n') {
+ vprintf_stderr_common(format, args);
+ return;
+ }
- OwnPtr<char[]> formatWithNewline = adoptArrayPtr(new char[formatLength + 2]);
- memcpy(formatWithNewline.get(), format, formatLength);
- formatWithNewline[formatLength] = '\n';
- formatWithNewline[formatLength + 1] = 0;
+ OwnPtr<char[]> formatWithNewline = adoptArrayPtr(new char[formatLength + 2]);
+ memcpy(formatWithNewline.get(), format, formatLength);
+ formatWithNewline[formatLength] = '\n';
+ formatWithNewline[formatLength + 1] = 0;
- vprintf_stderr_common(formatWithNewline.get(), args);
+ vprintf_stderr_common(formatWithNewline.get(), args);
}
#if COMPILER(CLANG) || (COMPILER(GCC) && GCC_VERSION_AT_LEAST(4, 6, 0))
@@ -173,256 +177,261 @@ static void vprintf_stderr_with_trailing_newline(const char* format, va_list arg
#endif
WTF_ATTRIBUTE_PRINTF(1, 2)
-static void printf_stderr_common(const char* format, ...)
-{
- va_list args;
- va_start(args, format);
- vprintf_stderr_common(format, args);
- va_end(args);
+static void printf_stderr_common(const char* format, ...) {
+ va_list args;
+ va_start(args, format);
+ vprintf_stderr_common(format, args);
+ va_end(args);
}
-static void printCallSite(const char* file, int line, const char* function)
-{
+static void printCallSite(const char* file, int line, const char* function) {
#if OS(WIN) && defined(_DEBUG)
- _CrtDbgReport(_CRT_WARN, file, line, nullptr, "%s\n", function);
+ _CrtDbgReport(_CRT_WARN, file, line, nullptr, "%s\n", function);
#else
- // By using this format, which matches the format used by MSVC for compiler errors, developers
- // using Visual Studio can double-click the file/line number in the Output Window to have the
- // editor navigate to that line of code. It seems fine for other developers, too.
- printf_stderr_common("%s(%d) : %s\n", file, line, function);
+ // By using this format, which matches the format used by MSVC for compiler errors, developers
+ // using Visual Studio can double-click the file/line number in the Output Window to have the
+ // editor navigate to that line of code. It seems fine for other developers, too.
+ 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("ASSERTION FAILED: %s\n", assertion);
- else
- printf_stderr_common("SHOULD NEVER BE REACHED\n");
- printCallSite(file, line, function);
+void WTFReportAssertionFailure(const char* file,
+ int line,
+ const char* function,
+ const char* assertion) {
+ if (assertion)
+ printf_stderr_common("ASSERTION FAILED: %s\n", assertion);
+ else
+ 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, ...)
-{
- va_list args;
- va_start(args, format);
- vprintf_stderr_with_prefix("ASSERTION FAILED: ", format, args);
- va_end(args);
- printf_stderr_common("\n%s\n", assertion);
- printCallSite(file, line, function);
+void WTFReportAssertionFailureWithMessage(const char* file,
+ int line,
+ const char* function,
+ const char* assertion,
+ const char* format,
+ ...) {
+ va_list args;
+ va_start(args, format);
+ vprintf_stderr_with_prefix("ASSERTION FAILED: ", format, args);
+ va_end(args);
+ 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)
-{
- printf_stderr_common("ARGUMENT BAD: %s, %s\n", argName, assertion);
- printCallSite(file, line, function);
+void WTFReportArgumentAssertionFailure(const char* file,
+ int line,
+ const char* function,
+ const char* argName,
+ const char* assertion) {
+ printf_stderr_common("ARGUMENT BAD: %s, %s\n", argName, assertion);
+ printCallSite(file, line, function);
}
-void WTFGetBacktrace(void** stack, int* size)
-{
+void WTFGetBacktrace(void** stack, int* size) {
#if OS(MACOSX) || (OS(LINUX) && !defined(__UCLIBC__))
- *size = backtrace(stack, *size);
+ *size = backtrace(stack, *size);
#elif OS(WIN)
- // The CaptureStackBackTrace function is available in XP, but it is not defined
- // in the Windows Server 2003 R2 Platform SDK. So, we'll grab the function
- // through GetProcAddress.
- typedef WORD (NTAPI* RtlCaptureStackBackTraceFunc)(DWORD, DWORD, PVOID*, PDWORD);
- HMODULE kernel32 = ::GetModuleHandleW(L"Kernel32.dll");
- if (!kernel32) {
- *size = 0;
- return;
- }
- RtlCaptureStackBackTraceFunc captureStackBackTraceFunc = reinterpret_cast<RtlCaptureStackBackTraceFunc>(
- ::GetProcAddress(kernel32, "RtlCaptureStackBackTrace"));
- if (captureStackBackTraceFunc)
- *size = captureStackBackTraceFunc(0, *size, stack, 0);
- else
- *size = 0;
-#else
+ // The CaptureStackBackTrace function is available in XP, but it is not defined
+ // in the Windows Server 2003 R2 Platform SDK. So, we'll grab the function
+ // through GetProcAddress.
+ typedef WORD(NTAPI * RtlCaptureStackBackTraceFunc)(DWORD, DWORD, PVOID*,
+ PDWORD);
+ HMODULE kernel32 = ::GetModuleHandleW(L"Kernel32.dll");
+ if (!kernel32) {
+ *size = 0;
+ return;
+ }
+ RtlCaptureStackBackTraceFunc captureStackBackTraceFunc =
+ reinterpret_cast<RtlCaptureStackBackTraceFunc>(
+ ::GetProcAddress(kernel32, "RtlCaptureStackBackTrace"));
+ if (captureStackBackTraceFunc)
+ *size = captureStackBackTraceFunc(0, *size, stack, 0);
+ else
*size = 0;
+#else
+ *size = 0;
#endif
}
-void WTFReportBacktrace(int framesToShow)
-{
- static const int framesToSkip = 2;
- // Use alloca to allocate on the stack since this function is used in OOM situations.
- void** samples = static_cast<void**>(alloca((framesToShow + framesToSkip) * sizeof(void *)));
- int frames = framesToShow + framesToSkip;
+void WTFReportBacktrace(int framesToShow) {
+ static const int framesToSkip = 2;
+ // Use alloca to allocate on the stack since this function is used in OOM situations.
+ void** samples = static_cast<void**>(
+ alloca((framesToShow + framesToSkip) * sizeof(void*)));
+ int frames = framesToShow + framesToSkip;
- WTFGetBacktrace(samples, &frames);
- WTFPrintBacktrace(samples + framesToSkip, frames - framesToSkip);
+ WTFGetBacktrace(samples, &frames);
+ WTFPrintBacktrace(samples + framesToSkip, frames - framesToSkip);
}
-FrameToNameScope::FrameToNameScope(void* addr)
- : m_name(0)
- , m_cxaDemangled(0)
-{
+FrameToNameScope::FrameToNameScope(void* addr) : m_name(0), m_cxaDemangled(0) {
#if OS(MACOSX) || (OS(LINUX) && !defined(__UCLIBC__))
- Dl_info info;
- if (!dladdr(addr, &info) || !info.dli_sname)
- return;
- const char* mangledName = info.dli_sname;
- if ((m_cxaDemangled = abi::__cxa_demangle(mangledName, 0, 0, 0)))
- m_name = m_cxaDemangled;
- else
- m_name = mangledName;
+ Dl_info info;
+ if (!dladdr(addr, &info) || !info.dli_sname)
+ return;
+ const char* mangledName = info.dli_sname;
+ if ((m_cxaDemangled = abi::__cxa_demangle(mangledName, 0, 0, 0)))
+ m_name = m_cxaDemangled;
+ else
+ m_name = mangledName;
#else
- (void)addr;
+ (void)addr;
#endif
}
-FrameToNameScope::~FrameToNameScope()
-{
- free(m_cxaDemangled);
+FrameToNameScope::~FrameToNameScope() {
+ free(m_cxaDemangled);
}
static const char kScopedLoggerIndent[] = " ";
ScopedLogger::ScopedLogger(bool condition, const char* format, ...)
- : m_parent(condition ? current() : 0)
- , m_multiline(false)
-{
- if (!condition)
- return;
-
- va_list args;
- va_start(args, format);
- init(format, args);
- va_end(args);
+ : m_parent(condition ? current() : 0), m_multiline(false) {
+ if (!condition)
+ return;
+
+ va_list args;
+ va_start(args, format);
+ init(format, args);
+ va_end(args);
}
-ScopedLogger::~ScopedLogger()
-{
- if (current() == this) {
- if (m_multiline)
- indent();
- else
- print(" ");
- print(")\n");
- current() = m_parent;
- }
+ScopedLogger::~ScopedLogger() {
+ if (current() == this) {
+ if (m_multiline)
+ indent();
+ else
+ print(" ");
+ print(")\n");
+ current() = m_parent;
+ }
}
-void ScopedLogger::init(const char* format, va_list args)
-{
- current() = this;
- if (m_parent)
- m_parent->writeNewlineIfNeeded();
- indent();
- print("( ");
- m_printFunc(format, args);
+void ScopedLogger::init(const char* format, va_list args) {
+ current() = this;
+ if (m_parent)
+ m_parent->writeNewlineIfNeeded();
+ indent();
+ print("( ");
+ m_printFunc(format, args);
}
-void ScopedLogger::writeNewlineIfNeeded()
-{
- if (!m_multiline) {
- print("\n");
- m_multiline = true;
- }
+void ScopedLogger::writeNewlineIfNeeded() {
+ if (!m_multiline) {
+ print("\n");
+ m_multiline = true;
+ }
}
-void ScopedLogger::indent()
-{
- if (m_parent) {
- m_parent->indent();
- print(kScopedLoggerIndent);
- }
+void ScopedLogger::indent() {
+ if (m_parent) {
+ m_parent->indent();
+ print(kScopedLoggerIndent);
+ }
}
-void ScopedLogger::log(const char* format, ...)
-{
- if (current() != this)
- return;
+void ScopedLogger::log(const char* format, ...) {
+ if (current() != this)
+ return;
- va_list args;
- va_start(args, format);
+ va_list args;
+ va_start(args, format);
- writeNewlineIfNeeded();
- indent();
- print(kScopedLoggerIndent);
- m_printFunc(format, args);
- print("\n");
+ writeNewlineIfNeeded();
+ indent();
+ print(kScopedLoggerIndent);
+ m_printFunc(format, args);
+ print("\n");
- va_end(args);
+ va_end(args);
}
-void ScopedLogger::print(const char* format, ...)
-{
- va_list args;
- va_start(args, format);
- m_printFunc(format, args);
- va_end(args);
+void ScopedLogger::print(const char* format, ...) {
+ va_list args;
+ va_start(args, format);
+ m_printFunc(format, args);
+ va_end(args);
}
-ScopedLogger*& ScopedLogger::current()
-{
- DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<ScopedLogger*>, ref, new ThreadSpecific<ScopedLogger*>);
- return *ref;
+ScopedLogger*& ScopedLogger::current() {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<ScopedLogger*>, ref,
+ new ThreadSpecific<ScopedLogger*>);
+ return *ref;
}
-ScopedLogger::PrintFunctionPtr ScopedLogger::m_printFunc = vprintf_stderr_common;
-
-void WTFPrintBacktrace(void** stack, int size)
-{
- for (int i = 0; i < size; ++i) {
- FrameToNameScope frameToName(stack[i]);
- const int frameNumber = i + 1;
- if (frameToName.nullableName())
- printf_stderr_common("%-3d %p %s\n", frameNumber, stack[i], frameToName.nullableName());
- else
- printf_stderr_common("%-3d %p\n", frameNumber, stack[i]);
- }
-}
+ScopedLogger::PrintFunctionPtr ScopedLogger::m_printFunc =
+ vprintf_stderr_common;
-void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...)
-{
- va_list args;
- va_start(args, format);
- vprintf_stderr_with_prefix("FATAL ERROR: ", format, args);
- va_end(args);
- printf_stderr_common("\n");
- printCallSite(file, line, function);
+void WTFPrintBacktrace(void** stack, int size) {
+ for (int i = 0; i < size; ++i) {
+ FrameToNameScope frameToName(stack[i]);
+ const int frameNumber = i + 1;
+ if (frameToName.nullableName())
+ printf_stderr_common("%-3d %p %s\n", frameNumber, stack[i],
+ frameToName.nullableName());
+ else
+ printf_stderr_common("%-3d %p\n", frameNumber, stack[i]);
+ }
}
-void WTFReportError(const char* file, int line, const char* function, const char* format, ...)
-{
- va_list args;
- va_start(args, format);
- vprintf_stderr_with_prefix("ERROR: ", format, args);
- va_end(args);
- printf_stderr_common("\n");
- printCallSite(file, line, function);
+void WTFReportFatalError(const char* file,
+ int line,
+ const char* function,
+ const char* format,
+ ...) {
+ va_list args;
+ va_start(args, format);
+ vprintf_stderr_with_prefix("FATAL ERROR: ", format, args);
+ va_end(args);
+ printf_stderr_common("\n");
+ printCallSite(file, line, function);
}
-void WTFLog(WTFLogChannel* channel, const char* format, ...)
-{
- if (channel->state != WTFLogChannelOn)
- return;
-
- va_list args;
- va_start(args, format);
- vprintf_stderr_with_trailing_newline(format, args);
- va_end(args);
+void WTFReportError(const char* file,
+ int line,
+ const char* function,
+ const char* format,
+ ...) {
+ va_list args;
+ va_start(args, format);
+ vprintf_stderr_with_prefix("ERROR: ", format, args);
+ va_end(args);
+ printf_stderr_common("\n");
+ printCallSite(file, line, function);
}
-void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel* channel, const char* format, ...)
-{
- if (channel->state != WTFLogChannelOn)
- return;
+void WTFLog(WTFLogChannel* channel, const char* format, ...) {
+ if (channel->state != WTFLogChannelOn)
+ return;
- va_list args;
- va_start(args, format);
- vprintf_stderr_with_trailing_newline(format, args);
- va_end(args);
+ va_list args;
+ va_start(args, format);
+ vprintf_stderr_with_trailing_newline(format, args);
+ va_end(args);
+}
- printCallSite(file, line, function);
+void WTFLogVerbose(const char* file,
+ int line,
+ const char* function,
+ WTFLogChannel* channel,
+ const char* format,
+ ...) {
+ if (channel->state != WTFLogChannelOn)
+ return;
+
+ va_list args;
+ va_start(args, format);
+ vprintf_stderr_with_trailing_newline(format, args);
+ va_end(args);
+
+ printCallSite(file, line, function);
}
-void WTFLogAlways(const char* format, ...)
-{
- va_list args;
- va_start(args, format);
- vprintf_stderr_with_trailing_newline(format, args);
- va_end(args);
+void WTFLogAlways(const char* format, ...) {
+ va_list args;
+ va_start(args, format);
+ vprintf_stderr_with_trailing_newline(format, args);
+ va_end(args);
}
« no previous file with comments | « third_party/WebKit/Source/wtf/Assertions.h ('k') | third_party/WebKit/Source/wtf/AssertionsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698