diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-06-23 21:53:12 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-06-23 21:53:12 +0000 |
commit | c3f9b5a53458bb66899d6e90e9e032dfdfa5ba2b (patch) | |
tree | da0146a72b490ea2f0dfd25e6f1415e70b094058 /llvm/lib/Object/Binary.cpp | |
parent | d81c48392888bcc62ed8628ee3005a34d151ea96 (diff) | |
download | bcm5719-llvm-c3f9b5a53458bb66899d6e90e9e032dfdfa5ba2b.tar.gz bcm5719-llvm-c3f9b5a53458bb66899d6e90e9e032dfdfa5ba2b.zip |
Make ObjectFile and BitcodeReader always own the MemoryBuffer.
This allows us to just use a std::unique_ptr to store the pointer to the buffer.
The flip side is that they have to support releasing the buffer back to the
caller.
Overall this looks like a more efficient and less brittle api.
llvm-svn: 211542
Diffstat (limited to 'llvm/lib/Object/Binary.cpp')
-rw-r--r-- | llvm/lib/Object/Binary.cpp | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/llvm/lib/Object/Binary.cpp b/llvm/lib/Object/Binary.cpp index c55ed0c7598..785b3d2318b 100644 --- a/llvm/lib/Object/Binary.cpp +++ b/llvm/lib/Object/Binary.cpp @@ -25,13 +25,10 @@ using namespace llvm; using namespace object; -Binary::~Binary() { - if (BufferOwned) - delete Data; -} +Binary::~Binary() {} -Binary::Binary(unsigned int Type, MemoryBuffer *Source, bool BufferOwned) - : TypeID(Type), BufferOwned(BufferOwned), Data(Source) {} +Binary::Binary(unsigned int Type, MemoryBuffer *Source) + : TypeID(Type), Data(Source) {} StringRef Binary::getData() const { return Data->getBuffer(); @@ -41,14 +38,13 @@ StringRef Binary::getFileName() const { return Data->getBufferIdentifier(); } -ErrorOr<Binary *> object::createBinary(MemoryBuffer *Source, +ErrorOr<Binary *> object::createBinary(MemoryBuffer *Buffer, LLVMContext *Context) { - std::unique_ptr<MemoryBuffer> scopedSource(Source); - sys::fs::file_magic Type = sys::fs::identify_magic(Source->getBuffer()); + sys::fs::file_magic Type = sys::fs::identify_magic(Buffer->getBuffer()); switch (Type) { case sys::fs::file_magic::archive: - return Archive::create(scopedSource.release()); + return Archive::create(Buffer); case sys::fs::file_magic::elf_relocatable: case sys::fs::file_magic::elf_executable: case sys::fs::file_magic::elf_shared_object: @@ -67,10 +63,9 @@ ErrorOr<Binary *> object::createBinary(MemoryBuffer *Source, case sys::fs::file_magic::coff_import_library: case sys::fs::file_magic::pecoff_executable: case sys::fs::file_magic::bitcode: - return ObjectFile::createSymbolicFile(scopedSource.release(), true, Type, - Context); + return ObjectFile::createSymbolicFile(Buffer, Type, Context); case sys::fs::file_magic::macho_universal_binary: - return MachOUniversalBinary::create(scopedSource.release()); + return MachOUniversalBinary::create(Buffer); case sys::fs::file_magic::unknown: case sys::fs::file_magic::windows_resource: // Unrecognized object file format. |