[PATCH] D15553: PR25717: fatal IO error writing large outputs to console on Windows

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 13:50:55 PST 2015


There are a few places that have duplicated code for calling write
multiple times. I was going to suggest that we refactor this into a
helper function, but realized it is probably better to change the
other locations to use a raw_fd_ostrem.

So this is fine with me if the other concerns are addressed.

Cheers,
Rafael



On 15 December 2015 at 21:09, Yunzhong Gao via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> ygao created this revision.
> ygao added reviewers: silvas, aaron.ballman, Bigcheese.
> ygao added a subscriber: llvm-commits.
>
> The fix to this bug is similar to the Python issue#11395. We need to cap the output size to
> 32767 on Windows to work around the size limit of WriteConsole().
> Reference: https://bugs.python.org/issue11395
>
> At least on Visual Studio 2013, the _isatty() check should be fast because it is implemented
> by reading a field from the preloaded ioinfo struct.
>
> http://reviews.llvm.org/D15553
>
> Files:
>   lib/Support/raw_ostream.cpp
>
> Index: lib/Support/raw_ostream.cpp
> ===================================================================
> --- lib/Support/raw_ostream.cpp
> +++ lib/Support/raw_ostream.cpp
> @@ -567,20 +567,34 @@
>    assert(FD >= 0 && "File already closed.");
>    pos += Size;
>
> +#ifndef LLVM_ON_WIN32
> +  bool ShouldWriteInChunks = false;
> +#else
> +  // PR25717: writing a large size of output to Windows console returns ENOMEM.
> +  // Seems that WriteFile() is redirecting to WriteConsole() prior to Windows 8,
> +  // and WriteConsole() has a size limit (66000 bytes or less, depending on
> +  // heap usage).
> +  bool ShouldWriteInChunks = !!::_isatty(FD);
> +#endif
> +
>    do {
>      ssize_t ret;
>
> +    size_t ChunkSize = Size;
> +    if (ChunkSize > 32767 && ShouldWriteInChunks)
> +        ChunkSize = 32767;
> +
>      // Check whether we should attempt to use atomic writes.
>      if (LLVM_LIKELY(!UseAtomicWrites)) {
> -      ret = ::write(FD, Ptr, Size);
> +      ret = ::write(FD, Ptr, ChunkSize);
>      } else {
>        // Use ::writev() where available.
>  #if defined(HAVE_WRITEV)
>        const void *Addr = static_cast<const void *>(Ptr);
> -      struct iovec IOV = {const_cast<void *>(Addr), Size };
> +      struct iovec IOV = {const_cast<void *>(Addr), ChunkSize };
>        ret = ::writev(FD, &IOV, 1);
>  #else
> -      ret = ::write(FD, Ptr, Size);
> +      ret = ::write(FD, Ptr, ChunkSize);
>  #endif
>      }
>
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>


More information about the llvm-commits mailing list