forked from OSchip/llvm-project
Move raw_ostream's Error flag into raw_fd_ostream, as that's the only
class which is using it. llvm-svn: 111639
This commit is contained in:
parent
c53191aba4
commit
38adfdd100
|
@ -58,10 +58,6 @@ private:
|
||||||
ExternalBuffer
|
ExternalBuffer
|
||||||
} BufferMode;
|
} BufferMode;
|
||||||
|
|
||||||
/// Error This flag is true if an error of any kind has been detected.
|
|
||||||
///
|
|
||||||
bool Error;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// color order matches ANSI escape sequence, don't change
|
// color order matches ANSI escape sequence, don't change
|
||||||
enum Colors {
|
enum Colors {
|
||||||
|
@ -77,7 +73,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit raw_ostream(bool unbuffered=false)
|
explicit raw_ostream(bool unbuffered=false)
|
||||||
: BufferMode(unbuffered ? Unbuffered : InternalBuffer), Error(false) {
|
: BufferMode(unbuffered ? Unbuffered : InternalBuffer) {
|
||||||
// Start out ready to flush.
|
// Start out ready to flush.
|
||||||
OutBufStart = OutBufEnd = OutBufCur = 0;
|
OutBufStart = OutBufEnd = OutBufCur = 0;
|
||||||
}
|
}
|
||||||
|
@ -87,21 +83,6 @@ public:
|
||||||
/// tell - Return the current offset with the file.
|
/// tell - Return the current offset with the file.
|
||||||
uint64_t tell() const { return current_pos() + GetNumBytesInBuffer(); }
|
uint64_t tell() const { return current_pos() + GetNumBytesInBuffer(); }
|
||||||
|
|
||||||
/// has_error - Return the value of the flag in this raw_ostream indicating
|
|
||||||
/// whether an output error has been encountered.
|
|
||||||
/// This doesn't implicitly flush any pending output.
|
|
||||||
bool has_error() const {
|
|
||||||
return Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// clear_error - Set the flag read by has_error() to false. If the error
|
|
||||||
/// flag is set at the time when this raw_ostream's destructor is called,
|
|
||||||
/// report_fatal_error is called to report the error. Use clear_error()
|
|
||||||
/// after handling the error to avoid this behavior.
|
|
||||||
void clear_error() {
|
|
||||||
Error = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// Configuration Interface
|
// Configuration Interface
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
|
@ -285,10 +266,6 @@ protected:
|
||||||
/// underlying output mechanism.
|
/// underlying output mechanism.
|
||||||
virtual size_t preferred_buffer_size() const;
|
virtual size_t preferred_buffer_size() const;
|
||||||
|
|
||||||
/// error_detected - Set the flag indicating that an output error has
|
|
||||||
/// been encountered.
|
|
||||||
void error_detected() { Error = true; }
|
|
||||||
|
|
||||||
/// getBufferStart - Return the beginning of the current stream buffer, or 0
|
/// getBufferStart - Return the beginning of the current stream buffer, or 0
|
||||||
/// if the stream is unbuffered.
|
/// if the stream is unbuffered.
|
||||||
const char *getBufferStart() const { return OutBufStart; }
|
const char *getBufferStart() const { return OutBufStart; }
|
||||||
|
@ -319,6 +296,11 @@ private:
|
||||||
class raw_fd_ostream : public raw_ostream {
|
class raw_fd_ostream : public raw_ostream {
|
||||||
int FD;
|
int FD;
|
||||||
bool ShouldClose;
|
bool ShouldClose;
|
||||||
|
|
||||||
|
/// Error This flag is true if an error of any kind has been detected.
|
||||||
|
///
|
||||||
|
bool Error;
|
||||||
|
|
||||||
uint64_t pos;
|
uint64_t pos;
|
||||||
|
|
||||||
/// write_impl - See raw_ostream::write_impl.
|
/// write_impl - See raw_ostream::write_impl.
|
||||||
|
@ -331,6 +313,10 @@ class raw_fd_ostream : public raw_ostream {
|
||||||
/// preferred_buffer_size - Determine an efficient buffer size.
|
/// preferred_buffer_size - Determine an efficient buffer size.
|
||||||
virtual size_t preferred_buffer_size() const;
|
virtual size_t preferred_buffer_size() const;
|
||||||
|
|
||||||
|
/// error_detected - Set the flag indicating that an output error has
|
||||||
|
/// been encountered.
|
||||||
|
void error_detected() { Error = true; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -365,7 +351,8 @@ public:
|
||||||
/// ShouldClose is true, this closes the file when the stream is destroyed.
|
/// ShouldClose is true, this closes the file when the stream is destroyed.
|
||||||
raw_fd_ostream(int fd, bool shouldClose,
|
raw_fd_ostream(int fd, bool shouldClose,
|
||||||
bool unbuffered=false) : raw_ostream(unbuffered), FD(fd),
|
bool unbuffered=false) : raw_ostream(unbuffered), FD(fd),
|
||||||
ShouldClose(shouldClose) {}
|
ShouldClose(shouldClose),
|
||||||
|
Error(false) {}
|
||||||
|
|
||||||
~raw_fd_ostream();
|
~raw_fd_ostream();
|
||||||
|
|
||||||
|
@ -382,6 +369,21 @@ public:
|
||||||
virtual raw_ostream &resetColor();
|
virtual raw_ostream &resetColor();
|
||||||
|
|
||||||
virtual bool is_displayed() const;
|
virtual bool is_displayed() const;
|
||||||
|
|
||||||
|
/// has_error - Return the value of the flag in this raw_fd_ostream indicating
|
||||||
|
/// whether an output error has been encountered.
|
||||||
|
/// This doesn't implicitly flush any pending output.
|
||||||
|
bool has_error() const {
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// clear_error - Set the flag read by has_error() to false. If the error
|
||||||
|
/// flag is set at the time when this raw_ostream's destructor is called,
|
||||||
|
/// report_fatal_error is called to report the error. Use clear_error()
|
||||||
|
/// after handling the error to avoid this behavior.
|
||||||
|
void clear_error() {
|
||||||
|
Error = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// raw_stdout_ostream - This is a stream that always prints to stdout.
|
/// raw_stdout_ostream - This is a stream that always prints to stdout.
|
||||||
|
|
|
@ -57,13 +57,6 @@ raw_ostream::~raw_ostream() {
|
||||||
|
|
||||||
if (BufferMode == InternalBuffer)
|
if (BufferMode == InternalBuffer)
|
||||||
delete [] OutBufStart;
|
delete [] OutBufStart;
|
||||||
|
|
||||||
// If there are any pending errors, report them now. Clients wishing
|
|
||||||
// to avoid report_fatal_error calls should check for errors with
|
|
||||||
// has_error() and clear the error flag with clear_error() before
|
|
||||||
// destructing raw_ostream objects which may have errors.
|
|
||||||
if (Error)
|
|
||||||
report_fatal_error("IO failure on output stream.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -370,7 +363,7 @@ void format_object_base::home() {
|
||||||
/// stream should be immediately destroyed; the string will be empty
|
/// stream should be immediately destroyed; the string will be empty
|
||||||
/// if no error occurred.
|
/// if no error occurred.
|
||||||
raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
|
raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
|
||||||
unsigned Flags) : pos(0) {
|
unsigned Flags) : Error(false), pos(0) {
|
||||||
assert(Filename != 0 && "Filename is null");
|
assert(Filename != 0 && "Filename is null");
|
||||||
// Verify that we don't have both "append" and "excl".
|
// Verify that we don't have both "append" and "excl".
|
||||||
assert((!(Flags & F_Excl) || !(Flags & F_Append)) &&
|
assert((!(Flags & F_Excl) || !(Flags & F_Append)) &&
|
||||||
|
@ -418,14 +411,22 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
raw_fd_ostream::~raw_fd_ostream() {
|
raw_fd_ostream::~raw_fd_ostream() {
|
||||||
if (FD < 0) return;
|
if (FD >= 0) {
|
||||||
flush();
|
flush();
|
||||||
if (ShouldClose)
|
if (ShouldClose)
|
||||||
while (::close(FD) != 0)
|
while (::close(FD) != 0)
|
||||||
if (errno != EINTR) {
|
if (errno != EINTR) {
|
||||||
error_detected();
|
error_detected();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are any pending errors, report them now. Clients wishing
|
||||||
|
// to avoid report_fatal_error calls should check for errors with
|
||||||
|
// has_error() and clear the error flag with clear_error() before
|
||||||
|
// destructing raw_ostream objects which may have errors.
|
||||||
|
if (has_error())
|
||||||
|
report_fatal_error("IO failure on output stream.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue