diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-06-23 22:00:37 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-06-23 22:00:37 +0000 |
commit | 6304e941082cc97240856ff602f4ae0dfcc08230 (patch) | |
tree | b41276453a57d065caf55cb342366b79ac81b11b /llvm/lib/Object/Binary.cpp | |
parent | aed5c966849821b5368f0e742439bae579f42da3 (diff) | |
download | bcm5719-llvm-6304e941082cc97240856ff602f4ae0dfcc08230.tar.gz bcm5719-llvm-6304e941082cc97240856ff602f4ae0dfcc08230.zip |
Pass a std::unique_ptr& to the create??? methods is lib/Object.
This makes the buffer ownership on error conditions very natural. The buffer
is only moved out of the argument if an object is constructed that now
owns the buffer.
llvm-svn: 211546
Diffstat (limited to 'llvm/lib/Object/Binary.cpp')
-rw-r--r-- | llvm/lib/Object/Binary.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/llvm/lib/Object/Binary.cpp b/llvm/lib/Object/Binary.cpp index 785b3d2318b..ee6f58cd750 100644 --- a/llvm/lib/Object/Binary.cpp +++ b/llvm/lib/Object/Binary.cpp @@ -38,13 +38,13 @@ StringRef Binary::getFileName() const { return Data->getBufferIdentifier(); } -ErrorOr<Binary *> object::createBinary(MemoryBuffer *Buffer, +ErrorOr<Binary *> object::createBinary(std::unique_ptr<MemoryBuffer> &Buffer, LLVMContext *Context) { sys::fs::file_magic Type = sys::fs::identify_magic(Buffer->getBuffer()); switch (Type) { case sys::fs::file_magic::archive: - return Archive::create(Buffer); + return Archive::create(Buffer.release()); case sys::fs::file_magic::elf_relocatable: case sys::fs::file_magic::elf_executable: case sys::fs::file_magic::elf_shared_object: @@ -65,7 +65,7 @@ ErrorOr<Binary *> object::createBinary(MemoryBuffer *Buffer, case sys::fs::file_magic::bitcode: return ObjectFile::createSymbolicFile(Buffer, Type, Context); case sys::fs::file_magic::macho_universal_binary: - return MachOUniversalBinary::create(Buffer); + return MachOUniversalBinary::create(Buffer.release()); case sys::fs::file_magic::unknown: case sys::fs::file_magic::windows_resource: // Unrecognized object file format. @@ -78,5 +78,5 @@ ErrorOr<Binary *> object::createBinary(StringRef Path) { std::unique_ptr<MemoryBuffer> File; if (std::error_code EC = MemoryBuffer::getFileOrSTDIN(Path, File)) return EC; - return createBinary(File.release()); + return createBinary(File); } |