Pass a unique_ptr<MemoryBuffer> to the constructors in the Binary hierarchy.

Once the objects are constructed, they own the buffer. Passing a unique_ptr
makes that clear.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211595 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-06-24 13:56:32 +00:00
parent d3aaad2d26
commit 0d50598d71
21 changed files with 104 additions and 88 deletions

View File

@@ -186,20 +186,19 @@ Archive::Child::getAsBinary(LLVMContext *Context) const {
return createBinary(Buff, Context);
}
ErrorOr<Archive*> Archive::create(MemoryBuffer *Source) {
ErrorOr<Archive *> Archive::create(std::unique_ptr<MemoryBuffer> Source) {
std::error_code EC;
std::unique_ptr<Archive> Ret(new Archive(Source, EC));
std::unique_ptr<Archive> Ret(new Archive(std::move(Source), EC));
if (EC)
return EC;
return Ret.release();
}
Archive::Archive(MemoryBuffer *source, std::error_code &ec)
: Binary(Binary::ID_Archive, source), SymbolTable(child_end()) {
Archive::Archive(std::unique_ptr<MemoryBuffer> Source, std::error_code &ec)
: Binary(Binary::ID_Archive, std::move(Source)), SymbolTable(child_end()) {
// Check for sufficient magic.
assert(source);
if (source->getBufferSize() < 8 ||
StringRef(source->getBufferStart(), 8) != Magic) {
if (Data->getBufferSize() < 8 ||
StringRef(Data->getBufferStart(), 8) != Magic) {
ec = object_error::invalid_file_type;
return;
}