[PATCH] D15553: PR25717: fatal IO error writing large outputs to console on Windows
Yunzhong Gao via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 5 16:53:41 PST 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL256892: Fixing PR25717: fatal IO error writing large outputs to console on Windows. (authored by ygao).
Changed prior to commit:
http://reviews.llvm.org/D15553?vs=43277&id=44073#toc
Repository:
rL LLVM
http://reviews.llvm.org/D15553
Files:
llvm/trunk/lib/Support/Windows/WindowsSupport.h
llvm/trunk/lib/Support/raw_ostream.cpp
Index: llvm/trunk/lib/Support/raw_ostream.cpp
===================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp
+++ llvm/trunk/lib/Support/raw_ostream.cpp
@@ -57,6 +57,10 @@
#endif
#endif
+#ifdef LLVM_ON_WIN32
+#include "Windows/WindowsSupport.h"
+#endif
+
using namespace llvm;
raw_ostream::~raw_ostream() {
@@ -567,8 +571,21 @@
assert(FD >= 0 && "File already closed.");
pos += Size;
+#ifndef LLVM_ON_WIN32
+ bool ShouldWriteInChunks = false;
+#else
+ // Writing a large size of output to Windows console returns ENOMEM. It seems
+ // that, prior to Windows 8, WriteFile() is redirecting to WriteConsole(), and
+ // the latter has a size limit (66000 bytes or less, depending on heap usage).
+ bool ShouldWriteInChunks = !!::_isatty(FD) && !IsWindows8OrGreater();
+#endif
+
do {
- ssize_t ret = ::write(FD, Ptr, Size);
+ size_t ChunkSize = Size;
+ if (ChunkSize > 32767 && ShouldWriteInChunks)
+ ChunkSize = 32767;
+
+ ssize_t ret = ::write(FD, Ptr, ChunkSize);
if (ret < 0) {
// If it's a recoverable error, swallow it and retry the write.
Index: llvm/trunk/lib/Support/Windows/WindowsSupport.h
===================================================================
--- llvm/trunk/lib/Support/Windows/WindowsSupport.h
+++ llvm/trunk/lib/Support/Windows/WindowsSupport.h
@@ -30,6 +30,8 @@
#define _WIN32_WINNT 0x0601
#define _WIN32_IE 0x0800 // MinGW at it again. FIXME: verify if still needed.
#define WIN32_LEAN_AND_MEAN
+#define NOGDI
+#define NOMINMAX
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
@@ -44,6 +46,20 @@
#include <string>
#include <vector>
+#ifndef __CYGWIN__
+#include <VersionHelpers.h>
+#else
+// Cygwin does not have the IsWindows8OrGreater() API.
+inline bool IsWindows8OrGreater() {
+ OSVERSIONINFO osvi = {};
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ if (!::GetVersionEx(&osvi))
+ return false;
+ return (osvi.dwMajorVersion > 6 ||
+ (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion >= 2));
+}
+#endif // __CYGWIN__
+
inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
if (!ErrMsg)
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15553.44073.patch
Type: text/x-patch
Size: 2216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160106/892f5793/attachment.bin>
More information about the llvm-commits
mailing list