Changeset View
Standalone View
lib/Support/raw_ostream.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
# define STDOUT_FILENO 1 | # define STDOUT_FILENO 1 | ||||
#endif | #endif | ||||
#ifndef STDERR_FILENO | #ifndef STDERR_FILENO | ||||
# define STDERR_FILENO 2 | # define STDERR_FILENO 2 | ||||
#endif | #endif | ||||
#endif | #endif | ||||
using namespace llvm; | using namespace llvm; | ||||
aaron.ballman: I think this should be moved into WindowsSupport.h, truth be told. I don't think *anyone* wants… | |||||
Will do. ygao: Will do.
lib/Driver/MSVCToolChain.cpp lives in cfe so I'll look into cleaning that up in a… | |||||
Sounds great, thank you! aaron.ballman: Sounds great, thank you! | |||||
raw_ostream::~raw_ostream() { | raw_ostream::~raw_ostream() { | ||||
Please include WindowsSupport.h instead of doing this. aaron.ballman: Please include WindowsSupport.h instead of doing this. | |||||
// raw_ostream's subclasses should take care to flush the buffer | // raw_ostream's subclasses should take care to flush the buffer | ||||
// in their destructors. | // in their destructors. | ||||
assert(OutBufCur == OutBufStart && | assert(OutBufCur == OutBufStart && | ||||
"raw_ostream destructor called with non-empty buffer!"); | "raw_ostream destructor called with non-empty buffer!"); | ||||
Would it make sense to add the VersionHelpers.h include and IsWindows8OrGreater() to WindowsSupport.h as these seem like much more generally useful than just for raw_ostream? I don't feel strongly about this, but am curious what others think. aaron.ballman: Would it make sense to add the VersionHelpers.h include and IsWindows8OrGreater() to… | |||||
It sounds like a good idea. ygao: It sounds like a good idea.
It may be a bit odd that for cygwin I only add a checker for… | |||||
I think that makes the most sense -- as we need them, we can add them in. Eventually cygwin will catch up with the Win32 APIs and we won't need the functionality anyway. aaron.ballman: I think that makes the most sense -- as we need them, we can add them in. Eventually cygwin… | |||||
if (BufferMode == InternalBuffer) | if (BufferMode == InternalBuffer) | ||||
delete [] OutBufStart; | delete [] OutBufStart; | ||||
} | } | ||||
// An out of line virtual method to provide a home for the class vtable. | // An out of line virtual method to provide a home for the class vtable. | ||||
void raw_ostream::handle() {} | void raw_ostream::handle() {} | ||||
size_t raw_ostream::preferred_buffer_size() const { | size_t raw_ostream::preferred_buffer_size() const { | ||||
▲ Show 20 Lines • Show All 483 Lines • ▼ Show 20 Lines | #endif | ||||
// has_error() and clear the error flag with clear_error() before | // has_error() and clear the error flag with clear_error() before | ||||
// destructing raw_ostream objects which may have errors. | // destructing raw_ostream objects which may have errors. | ||||
if (has_error()) | if (has_error()) | ||||
report_fatal_error("IO failure on output stream.", /*GenCrashDiag=*/false); | report_fatal_error("IO failure on output stream.", /*GenCrashDiag=*/false); | ||||
} | } | ||||
void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { | void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { | ||||
assert(FD >= 0 && "File already closed."); | assert(FD >= 0 && "File already closed."); | ||||
GetVersion() is deprecated, you should be using IsWindows8OrGreater() instead (https://msdn.microsoft.com/en-us/library/windows/desktop/dn424961(v=vs.85).aspx). aaron.ballman: GetVersion() is deprecated, you should be using IsWindows8OrGreater() instead (https://msdn. | |||||
pos += Size; | pos += Size; | ||||
#ifndef LLVM_ON_WIN32 | |||||
aaron.ballmanUnsubmitted Is there a noticeable regression in performance due to this chunking? If so, I would prefer if this were dynamically set based on the Windows version. Microsoft is pretty aggressively upgrading people to Windows 10, so it would be good not to punish all Windows users if the performance hit is measurable. aaron.ballman: Is there a noticeable regression in performance due to this chunking? If so, I would prefer if… | |||||
bool ShouldWriteInChunks = false; | |||||
#else | |||||
// PR25717: writing a large size of output to Windows console returns ENOMEM. | |||||
probinsonUnsubmitted I think we don't normally cite PR numbers in source. Instead you can cite it in the commit message, and then a 'blame' will lead someone to the PR if they are that interested. probinson: I think we don't normally cite PR numbers in source. Instead you can cite it in the commit… | |||||
// 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 { | do { | ||||
ssize_t ret; | ssize_t ret; | ||||
size_t ChunkSize = Size; | |||||
if (ChunkSize > 32767 && ShouldWriteInChunks) | |||||
ChunkSize = 32767; | |||||
// Check whether we should attempt to use atomic writes. | // Check whether we should attempt to use atomic writes. | ||||
if (LLVM_LIKELY(!UseAtomicWrites)) { | if (LLVM_LIKELY(!UseAtomicWrites)) { | ||||
ret = ::write(FD, Ptr, Size); | ret = ::write(FD, Ptr, ChunkSize); | ||||
} else { | } else { | ||||
// Use ::writev() where available. | // Use ::writev() where available. | ||||
#if defined(HAVE_WRITEV) | #if defined(HAVE_WRITEV) | ||||
const void *Addr = static_cast<const void *>(Ptr); | 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); | ret = ::writev(FD, &IOV, 1); | ||||
#else | #else | ||||
ret = ::write(FD, Ptr, Size); | ret = ::write(FD, Ptr, ChunkSize); | ||||
#endif | #endif | ||||
} | } | ||||
if (ret < 0) { | if (ret < 0) { | ||||
// If it's a recoverable error, swallow it and retry the write. | // If it's a recoverable error, swallow it and retry the write. | ||||
// | // | ||||
// Ideally we wouldn't ever see EAGAIN or EWOULDBLOCK here, since | // Ideally we wouldn't ever see EAGAIN or EWOULDBLOCK here, since | ||||
// raw_ostream isn't designed to do non-blocking I/O. However, some | // raw_ostream isn't designed to do non-blocking I/O. However, some | ||||
▲ Show 20 Lines • Show All 199 Lines • Show Last 20 Lines |
I think this should be moved into WindowsSupport.h, truth be told. I don't think *anyone* wants min or max to be macros in this project.