mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-15 23:31:37 +00:00
Correct the ownership passing semantics of object::createBinary and make them explicit in the type system.
createBinary documented that it destroyed the parameter in error cases, though by observation it does not. By passing the unique_ptr by value rather than lvalue reference, callers are now explicit about passing ownership and the function implements the documented contract. Remove the explicit documentation, since now the behavior cannot be anything other than what was documented, so it's redundant. Also drops a unique_ptr::release in llvm-nm that was always run on a null unique_ptr anyway. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213557 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d8fa9295c8
commit
95689f0845
@ -125,10 +125,8 @@ public:
|
|||||||
|
|
||||||
/// @brief Create a Binary from Source, autodetecting the file type.
|
/// @brief Create a Binary from Source, autodetecting the file type.
|
||||||
///
|
///
|
||||||
/// @param Source The data to create the Binary from. Ownership is transferred
|
/// @param Source The data to create the Binary from.
|
||||||
/// to the Binary if successful. If an error is returned,
|
ErrorOr<Binary *> createBinary(std::unique_ptr<MemoryBuffer> Source,
|
||||||
/// Source is destroyed by createBinary before returning.
|
|
||||||
ErrorOr<Binary *> createBinary(std::unique_ptr<MemoryBuffer> &Source,
|
|
||||||
LLVMContext *Context = nullptr);
|
LLVMContext *Context = nullptr);
|
||||||
|
|
||||||
ErrorOr<Binary *> createBinary(StringRef Path);
|
ErrorOr<Binary *> createBinary(StringRef Path);
|
||||||
|
@ -181,7 +181,7 @@ Archive::Child::getAsBinary(LLVMContext *Context) const {
|
|||||||
if (std::error_code EC = BuffOrErr.getError())
|
if (std::error_code EC = BuffOrErr.getError())
|
||||||
return EC;
|
return EC;
|
||||||
|
|
||||||
return createBinary(*BuffOrErr, Context);
|
return createBinary(std::move(*BuffOrErr), Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<Archive *> Archive::create(std::unique_ptr<MemoryBuffer> Source) {
|
ErrorOr<Archive *> Archive::create(std::unique_ptr<MemoryBuffer> Source) {
|
||||||
|
@ -38,7 +38,7 @@ StringRef Binary::getFileName() const {
|
|||||||
return Data->getBufferIdentifier();
|
return Data->getBufferIdentifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<Binary *> object::createBinary(std::unique_ptr<MemoryBuffer> &Buffer,
|
ErrorOr<Binary *> object::createBinary(std::unique_ptr<MemoryBuffer> Buffer,
|
||||||
LLVMContext *Context) {
|
LLVMContext *Context) {
|
||||||
sys::fs::file_magic Type = sys::fs::identify_magic(Buffer->getBuffer());
|
sys::fs::file_magic Type = sys::fs::identify_magic(Buffer->getBuffer());
|
||||||
|
|
||||||
@ -79,5 +79,5 @@ ErrorOr<Binary *> object::createBinary(StringRef Path) {
|
|||||||
MemoryBuffer::getFileOrSTDIN(Path);
|
MemoryBuffer::getFileOrSTDIN(Path);
|
||||||
if (std::error_code EC = FileOrErr.getError())
|
if (std::error_code EC = FileOrErr.getError())
|
||||||
return EC;
|
return EC;
|
||||||
return createBinary(FileOrErr.get());
|
return createBinary(std::move(*FileOrErr));
|
||||||
}
|
}
|
||||||
|
@ -993,13 +993,12 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
|
|||||||
MemoryBuffer::getFileOrSTDIN(Filename);
|
MemoryBuffer::getFileOrSTDIN(Filename);
|
||||||
if (error(BufferOrErr.getError(), Filename))
|
if (error(BufferOrErr.getError(), Filename))
|
||||||
return;
|
return;
|
||||||
std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get());
|
|
||||||
|
|
||||||
LLVMContext &Context = getGlobalContext();
|
LLVMContext &Context = getGlobalContext();
|
||||||
ErrorOr<Binary *> BinaryOrErr = createBinary(Buffer, &Context);
|
ErrorOr<Binary *> BinaryOrErr =
|
||||||
|
createBinary(std::move(*BufferOrErr), &Context);
|
||||||
if (error(BinaryOrErr.getError(), Filename))
|
if (error(BinaryOrErr.getError(), Filename))
|
||||||
return;
|
return;
|
||||||
Buffer.release();
|
|
||||||
std::unique_ptr<Binary> Bin(BinaryOrErr.get());
|
std::unique_ptr<Binary> Bin(BinaryOrErr.get());
|
||||||
|
|
||||||
if (Archive *A = dyn_cast<Archive>(Bin.get())) {
|
if (Archive *A = dyn_cast<Archive>(Bin.get())) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user