diff options
author | Dan Gohman <gohman@apple.com> | 2010-09-01 14:20:41 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-09-01 14:20:41 +0000 |
commit | d4c454317a38d65957edebe62bfc69fc8d9885e8 (patch) | |
tree | dbf117519d428f04854447edee010962e68e5753 /lib/Support | |
parent | 41154114f64c1531764236e9268d2a5ac52e3e91 (diff) |
Make tool_output_file's raw_ostream instance a member variable instead
of a base class.
This makes it possible to unregister the file from FilesToRemove when
the file is done. Also, this eliminates the need for
formatted_tool_output_file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112706 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/FormattedStream.cpp | 3 | ||||
-rw-r--r-- | lib/Support/raw_ostream.cpp | 32 |
2 files changed, 18 insertions, 17 deletions
diff --git a/lib/Support/FormattedStream.cpp b/lib/Support/FormattedStream.cpp index 77bdfab220..c72b5a1751 100644 --- a/lib/Support/FormattedStream.cpp +++ b/lib/Support/FormattedStream.cpp @@ -98,6 +98,3 @@ formatted_raw_ostream &llvm::fdbgs() { static formatted_raw_ostream S(dbgs()); return S; } - -/// ~formatted_tool_output_file - Out-of-line destructor. -formatted_tool_output_file::~formatted_tool_output_file() {} diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index 371dc8b255..dba46df362 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -670,25 +670,29 @@ uint64_t raw_null_ostream::current_pos() const { // tool_output_file //===----------------------------------------------------------------------===// -/// SetupRemoveOnSignal - This is a helper for tool_output_file's constructor -/// to allow the signal handlers to be installed before constructing the -/// base class raw_fd_ostream. -static const char *SetupRemoveOnSignal(const char *Filename) { +tool_output_file::CleanupInstaller::CleanupInstaller(const char *filename) + : Filename(filename), Keep(false) { // Arrange for the file to be deleted if the process is killed. - if (strcmp(Filename, "-") != 0) + if (Filename != "-") sys::RemoveFileOnSignal(sys::Path(Filename)); - return Filename; } -tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo, - unsigned Flags) - : raw_fd_ostream(SetupRemoveOnSignal(filename), ErrorInfo, Flags), - Filename(filename), - Keep(!ErrorInfo.empty() /* If open fails, no cleanup is needed. */) { -} - -tool_output_file::~tool_output_file() { +tool_output_file::CleanupInstaller::~CleanupInstaller() { // Delete the file if the client hasn't told us not to. if (!Keep && Filename != "-") sys::Path(Filename).eraseFromDisk(); + + // Ok, the file is successfully written and closed, or deleted. There's no + // further need to clean it up on signals. + if (Filename != "-") + sys::DontRemoveFileOnSignal(sys::Path(Filename)); +} + +tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo, + unsigned Flags) + : Installer(filename), + OS(filename, ErrorInfo, Flags) { + // If open fails, no cleanup is needed. + if (!ErrorInfo.empty()) + Installer.Keep = true; } |