[llvm] r317656 - Convert FileOutputBuffer::commit to Error.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 7 17:50:29 PST 2017
Author: rafael
Date: Tue Nov 7 17:50:29 2017
New Revision: 317656
URL: http://llvm.org/viewvc/llvm-project?rev=317656&view=rev
Log:
Convert FileOutputBuffer::commit to Error.
Modified:
llvm/trunk/include/llvm/Support/FileOutputBuffer.h
llvm/trunk/lib/Support/FileOutputBuffer.cpp
llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
llvm/trunk/unittests/Support/FileOutputBufferTest.cpp
Modified: llvm/trunk/include/llvm/Support/FileOutputBuffer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileOutputBuffer.h?rev=317656&r1=317655&r2=317656&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileOutputBuffer.h (original)
+++ llvm/trunk/include/llvm/Support/FileOutputBuffer.h Tue Nov 7 17:50:29 2017
@@ -57,7 +57,7 @@ public:
/// is called, the file is deleted in the destructor. The optional parameter
/// is used if it turns out you want the file size to be smaller than
/// initially requested.
- virtual std::error_code commit() = 0;
+ virtual Error commit() = 0;
/// If this object was previously committed, the destructor just deletes
/// this object. If this object was not committed, the destructor
Modified: llvm/trunk/lib/Support/FileOutputBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FileOutputBuffer.cpp?rev=317656&r1=317655&r2=317656&view=diff
==============================================================================
--- llvm/trunk/lib/Support/FileOutputBuffer.cpp (original)
+++ llvm/trunk/lib/Support/FileOutputBuffer.cpp Tue Nov 7 17:50:29 2017
@@ -49,14 +49,14 @@ public:
size_t getBufferSize() const override { return Buffer->size(); }
- std::error_code commit() override {
+ Error commit() override {
// Unmap buffer, letting OS flush dirty pages to file on disk.
Buffer.reset();
// Atomically replace the existing file with the new one.
auto EC = fs::rename(TempPath, FinalPath);
sys::DontRemoveFileOnSignal(TempPath);
- return EC;
+ return errorCodeToError(EC);
}
~OnDiskBuffer() override {
@@ -96,14 +96,14 @@ public:
size_t getBufferSize() const override { return Buffer.size(); }
- std::error_code commit() override {
+ Error commit() override {
int FD;
std::error_code EC;
if (auto EC = openFileForWrite(FinalPath, FD, fs::F_None, Mode))
- return EC;
+ return errorCodeToError(EC);
raw_fd_ostream OS(FD, /*shouldClose=*/true, /*unbuffered=*/true);
OS << StringRef((const char *)Buffer.base(), Buffer.size());
- return std::error_code();
+ return Error::success();
}
private:
Modified: llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp?rev=317656&r1=317655&r2=317656&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp Tue Nov 7 17:50:29 2017
@@ -121,8 +121,8 @@ void WriteObjectFile(const Object<ELFT>
else
Buffer = std::move(*BufferOrErr);
Obj.write(*Buffer);
- if (auto EC = Buffer->commit())
- reportError(File, EC);
+ if (auto E = Buffer->commit())
+ reportError(File, errorToErrorCode(std::move(E)));
}
template <class ELFT>
Modified: llvm/trunk/unittests/Support/FileOutputBufferTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/FileOutputBufferTest.cpp?rev=317656&r1=317655&r2=317656&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/FileOutputBufferTest.cpp (original)
+++ llvm/trunk/unittests/Support/FileOutputBufferTest.cpp Tue Nov 7 17:50:29 2017
@@ -51,7 +51,7 @@ TEST(FileOutputBuffer, Test) {
// Write to end of buffer to verify it is writable.
memcpy(Buffer->getBufferEnd() - 20, "AABBCCDDEEFFGGHHIIJJ", 20);
// Commit buffer.
- ASSERT_NO_ERROR(Buffer->commit());
+ ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit()));
}
// Verify file is correct size.
@@ -89,7 +89,7 @@ TEST(FileOutputBuffer, Test) {
memcpy(Buffer->getBufferStart(), "AABBCCDDEEFFGGHHIIJJ", 20);
// Write to end of buffer to verify it is writable.
memcpy(Buffer->getBufferEnd() - 20, "AABBCCDDEEFFGGHHIIJJ", 20);
- ASSERT_NO_ERROR(Buffer->commit());
+ ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit()));
}
// Verify file is correct size.
@@ -109,7 +109,7 @@ TEST(FileOutputBuffer, Test) {
// Start buffer with special header.
memcpy(Buffer->getBufferStart(), "AABBCCDDEEFFGGHHIIJJ", 20);
// Commit buffer.
- ASSERT_NO_ERROR(Buffer->commit());
+ ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit()));
}
// Verify file exists and is executable.
fs::file_status Status;
More information about the llvm-commits
mailing list