/// @brief Create a Binary from Source, autodetecting the file type.
///
-/// @param Source The data to create the Binary from. Ownership is transferred
-/// to the Binary if successful. If an error is returned,
-/// Source is destroyed by createBinary before returning.
-ErrorOr<Binary *> createBinary(std::unique_ptr<MemoryBuffer> &Source,
+/// @param Source The data to create the Binary from.
+ErrorOr<Binary *> createBinary(std::unique_ptr<MemoryBuffer> Source,
LLVMContext *Context = nullptr);
ErrorOr<Binary *> createBinary(StringRef Path);
if (std::error_code EC = BuffOrErr.getError())
return EC;
- return createBinary(*BuffOrErr, Context);
+ return createBinary(std::move(*BuffOrErr), Context);
}
ErrorOr<Archive *> Archive::create(std::unique_ptr<MemoryBuffer> Source) {
return Data->getBufferIdentifier();
}
-ErrorOr<Binary *> object::createBinary(std::unique_ptr<MemoryBuffer> &Buffer,
+ErrorOr<Binary *> object::createBinary(std::unique_ptr<MemoryBuffer> Buffer,
LLVMContext *Context) {
sys::fs::file_magic Type = sys::fs::identify_magic(Buffer->getBuffer());
MemoryBuffer::getFileOrSTDIN(Path);
if (std::error_code EC = FileOrErr.getError())
return EC;
- return createBinary(FileOrErr.get());
+ return createBinary(std::move(*FileOrErr));
}
MemoryBuffer::getFileOrSTDIN(Filename);
if (error(BufferOrErr.getError(), Filename))
return;
- std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get());
LLVMContext &Context = getGlobalContext();
- ErrorOr<Binary *> BinaryOrErr = createBinary(Buffer, &Context);
+ ErrorOr<Binary *> BinaryOrErr =
+ createBinary(std::move(*BufferOrErr), &Context);
if (error(BinaryOrErr.getError(), Filename))
return;
- Buffer.release();
std::unique_ptr<Binary> Bin(BinaryOrErr.get());
if (Archive *A = dyn_cast<Archive>(Bin.get())) {