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
This commit is contained in:
Rafael Espindola
2014-06-23 21:53:12 +00:00
parent 7e7e89f178
commit 1f659329b6
23 changed files with 117 additions and 154 deletions

View File

@ -208,7 +208,7 @@ class ObjectFile : public SymbolicFile {
ObjectFile(const ObjectFile &other) LLVM_DELETED_FUNCTION;
protected:
ObjectFile(unsigned int Type, MemoryBuffer *Source, bool BufferOwned = true);
ObjectFile(unsigned int Type, MemoryBuffer *Source);
const uint8_t *base() const {
return reinterpret_cast<const uint8_t *>(Data->getBufferStart());
@ -334,10 +334,9 @@ public:
/// @brief Create ObjectFile from path.
static ErrorOr<ObjectFile *> createObjectFile(StringRef ObjectPath);
static ErrorOr<ObjectFile *> createObjectFile(MemoryBuffer *Object,
bool BufferOwned,
sys::fs::file_magic Type);
static ErrorOr<ObjectFile *> createObjectFile(MemoryBuffer *Object) {
return createObjectFile(Object, true, sys::fs::file_magic::unknown);
return createObjectFile(Object, sys::fs::file_magic::unknown);
}
@ -346,12 +345,9 @@ public:
}
public:
static ErrorOr<ObjectFile *> createCOFFObjectFile(MemoryBuffer *Object,
bool BufferOwned = true);
static ErrorOr<ObjectFile *> createELFObjectFile(MemoryBuffer *Object,
bool BufferOwned = true);
static ErrorOr<ObjectFile *> createMachOObjectFile(MemoryBuffer *Object,
bool BufferOwned = true);
static ErrorOr<ObjectFile *> createCOFFObjectFile(MemoryBuffer *Object);
static ErrorOr<ObjectFile *> createELFObjectFile(MemoryBuffer *Object);
static ErrorOr<ObjectFile *> createMachOObjectFile(MemoryBuffer *Object);
};
// Inline function definitions.