From dff1e5c0b64858887618a7030d7d433476d589a1 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 6 Mar 2014 09:08:12 +0000 Subject: [PATCH] base: fix a debug message queue crash and add Unicode support on Windows. --- src/base/log.cpp | 10 +++++++--- src/base/string.cpp | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/base/log.cpp b/src/base/log.cpp index c35408a7..959b6e39 100644 --- a/src/base/log.cpp +++ b/src/base/log.cpp @@ -82,7 +82,7 @@ void Log::Helper(MessageType type, char const *fmt, va_list ap) ANDROID_LOG_ERROR }; - String buf = String::Printf(fmt, ap); + String buf = String::VPrintf(fmt, ap); __android_log_print(prio[type], "LOL", "[%d] %s", (int)gettid(), &buf[0]); #else @@ -95,8 +95,12 @@ void Log::Helper(MessageType type, char const *fmt, va_list ap) }; # if defined _WIN32 - String buf = String(prefix[type]) + ": " + String::Printf(fmt, ap); - OutputDebugString(&buf[0]); + String buf = String(prefix[type]) + ": " + String::VPrintf(fmt, ap); + + Array widechar; + widechar.Resize(buf.Count() + 1); + MultiByteToWideChar(CP_UTF8, 0, buf.C(), buf.Count() + 1, widechar.Data(), widechar.Count()); + OutputDebugStringW(widechar.Data()); # else fprintf(stderr, "%s: ", prefix[type]); vfprintf(stderr, fmt, ap); diff --git a/src/base/string.cpp b/src/base/string.cpp index e8eeb2df..15b44f3f 100644 --- a/src/base/string.cpp +++ b/src/base/string.cpp @@ -47,7 +47,7 @@ String String::VPrintf(char const *format, va_list ap) String ret; va_list ap2; -#if !defined _MSC_VER +#if defined va_copy || !defined _MSC_VER /* Visual Studio 2010 does not support va_copy. */ va_copy(ap2, ap); #else @@ -57,7 +57,11 @@ String String::VPrintf(char const *format, va_list ap) /* vsnprintf() tells us how many character we need, and we need to * add one for the terminating null byte. */ size_t needed = vsnprintf(nullptr, 0, format, ap2) + 1; + +#if defined va_copy || !defined _MSC_VER + /* do not call va_end() if va_copy() wasn’t called. */ va_end(ap2); +#endif ((Super &)ret).Reserve(needed); ret.m_count = needed;