Fix VPrintHelper used on Windows.
authorvegorov@chromium.org <vegorov@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 6 Mar 2014 11:55:47 +0000 (11:55 +0000)
committervegorov@chromium.org <vegorov@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 6 Mar 2014 11:55:47 +0000 (11:55 +0000)
VPrintHelper would silently ignore the stream given to it if application is in GUI mode (no console is attached) and redirect output to the debugger via OutputDebugString.

Such redirection makes sense only if passed stream is either stderr or stdout. Don't redirect any other stream to the debugger.

Reorder clauses in VPrintHelper to make condition more readable.

BUG=
R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/177413006

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19688 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/platform-win32.cc

index 446caee..52c3050 100644 (file)
@@ -662,15 +662,15 @@ static bool HasConsole() {
 
 
 static void VPrintHelper(FILE* stream, const char* format, va_list args) {
-  if (HasConsole()) {
-    vfprintf(stream, format, args);
-  } else {
+  if ((stream == stdout || stream == stderr) && !HasConsole()) {
     // It is important to use safe print here in order to avoid
     // overflowing the buffer. We might truncate the output, but this
     // does not crash.
     EmbeddedVector<char, 4096> buffer;
     OS::VSNPrintF(buffer, format, args);
     OutputDebugStringA(buffer.start());
+  } else {
+    vfprintf(stream, format, args);
   }
 }