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 | 1f659329b63aa1d1af2b2bfc8b174a8ccdaba2c0 (patch) | |
tree | dc64a751796af7cd61a83b0cb8a8d8ca3145a95c /lib/Object/MachOObjectFile.cpp | |
parent | 7e7e89f17819d30703543375120dff52d5aaa414 (diff) | |
download | llvm-1f659329b63aa1d1af2b2bfc8b174a8ccdaba2c0.tar.gz llvm-1f659329b63aa1d1af2b2bfc8b174a8ccdaba2c0.tar.bz2 llvm-1f659329b63aa1d1af2b2bfc8b174a8ccdaba2c0.tar.xz |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211542 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Object/MachOObjectFile.cpp')
-rw-r--r-- | lib/Object/MachOObjectFile.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index a072b0f28c..7fc02fb893 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -423,9 +423,8 @@ static uint32_t getSectionFlags(const MachOObjectFile *O, } MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, - bool Is64bits, std::error_code &EC, - bool BufferOwned) - : ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object, BufferOwned), + bool Is64bits, std::error_code &EC) + : ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object), SymtabLoadCmd(nullptr), DysymtabLoadCmd(nullptr), DataInCodeLoadCmd(nullptr) { uint32_t LoadCommandCount = this->getHeader().ncmds; @@ -1812,19 +1811,18 @@ void MachOObjectFile::ReadULEB128s(uint64_t Index, } } -ErrorOr<ObjectFile *> ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer, - bool BufferOwned) { +ErrorOr<ObjectFile *> ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer) { StringRef Magic = Buffer->getBuffer().slice(0, 4); std::error_code EC; std::unique_ptr<MachOObjectFile> Ret; if (Magic == "\xFE\xED\xFA\xCE") - Ret.reset(new MachOObjectFile(Buffer, false, false, EC, BufferOwned)); + Ret.reset(new MachOObjectFile(Buffer, false, false, EC)); else if (Magic == "\xCE\xFA\xED\xFE") - Ret.reset(new MachOObjectFile(Buffer, true, false, EC, BufferOwned)); + Ret.reset(new MachOObjectFile(Buffer, true, false, EC)); else if (Magic == "\xFE\xED\xFA\xCF") - Ret.reset(new MachOObjectFile(Buffer, false, true, EC, BufferOwned)); + Ret.reset(new MachOObjectFile(Buffer, false, true, EC)); else if (Magic == "\xCF\xFA\xED\xFE") - Ret.reset(new MachOObjectFile(Buffer, true, true, EC, BufferOwned)); + Ret.reset(new MachOObjectFile(Buffer, true, true, EC)); else { delete Buffer; return object_error::parse_failed; |