llvm.org GIT mirror llvm / 95689f0
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 David Blaikie 5 years ago
4 changed file(s) with 7 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
124124
125125 /// @brief Create a Binary from Source, autodetecting the file type.
126126 ///
127 /// @param Source The data to create the Binary from. Ownership is transferred
128 /// to the Binary if successful. If an error is returned,
129 /// Source is destroyed by createBinary before returning.
130 ErrorOr createBinary(std::unique_ptr &Source,
127 /// @param Source The data to create the Binary from.
128 ErrorOr createBinary(std::unique_ptr Source,
131129 LLVMContext *Context = nullptr);
132130
133131 ErrorOr createBinary(StringRef Path);
180180 if (std::error_code EC = BuffOrErr.getError())
181181 return EC;
182182
183 return createBinary(*BuffOrErr, Context);
183 return createBinary(std::move(*BuffOrErr), Context);
184184 }
185185
186186 ErrorOr Archive::create(std::unique_ptr Source) {
3737 return Data->getBufferIdentifier();
3838 }
3939
40 ErrorOr object::createBinary(std::unique_ptr &Buffer,
40 ErrorOr object::createBinary(std::unique_ptr Buffer,
4141 LLVMContext *Context) {
4242 sys::fs::file_magic Type = sys::fs::identify_magic(Buffer->getBuffer());
4343
7878 MemoryBuffer::getFileOrSTDIN(Path);
7979 if (std::error_code EC = FileOrErr.getError())
8080 return EC;
81 return createBinary(FileOrErr.get());
81 return createBinary(std::move(*FileOrErr));
8282 }
992992 MemoryBuffer::getFileOrSTDIN(Filename);
993993 if (error(BufferOrErr.getError(), Filename))
994994 return;
995 std::unique_ptr Buffer = std::move(BufferOrErr.get());
996995
997996 LLVMContext &Context = getGlobalContext();
998 ErrorOr BinaryOrErr = createBinary(Buffer, &Context);
997 ErrorOr BinaryOrErr =
998 createBinary(std::move(*BufferOrErr), &Context);
999999 if (error(BinaryOrErr.getError(), Filename))
10001000 return;
1001 Buffer.release();
10021001 std::unique_ptr Bin(BinaryOrErr.get());
10031002
10041003 if (Archive *A = dyn_cast(Bin.get())) {