From: Rafael Espindola Date: Sun, 17 Aug 2014 22:12:58 +0000 (+0000) Subject: Convert a few ownership comments with std::unique_ptr. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86925f9d1939189c022bfefe053474dd4df36909;p=clang Convert a few ownership comments with std::unique_ptr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215853 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/VirtualFileSystem.h b/include/clang/Basic/VirtualFileSystem.h index 92b8404715..86f8dd66fd 100644 --- a/include/clang/Basic/VirtualFileSystem.h +++ b/include/clang/Basic/VirtualFileSystem.h @@ -250,10 +250,8 @@ llvm::sys::fs::UniqueID getNextVirtualUniqueID(); /// \brief Gets a \p FileSystem for a virtual file system described in YAML /// format. -/// -/// Takes ownership of \p Buffer. IntrusiveRefCntPtr -getVFSFromYAML(llvm::MemoryBuffer *Buffer, +getVFSFromYAML(std::unique_ptr Buffer, llvm::SourceMgr::DiagHandlerTy DiagHandler, void *DiagContext = nullptr, IntrusiveRefCntPtr ExternalFS = getRealFileSystem()); diff --git a/lib/Basic/VirtualFileSystem.cpp b/lib/Basic/VirtualFileSystem.cpp index a5c83b88af..60c3052bdd 100644 --- a/lib/Basic/VirtualFileSystem.cpp +++ b/lib/Basic/VirtualFileSystem.cpp @@ -514,9 +514,7 @@ public: /// \brief Parses \p Buffer, which is expected to be in YAML format and /// returns a virtual file system representing its contents. - /// - /// Takes ownership of \p Buffer. - static VFSFromYAML *create(MemoryBuffer *Buffer, + static VFSFromYAML *create(std::unique_ptr Buffer, SourceMgr::DiagHandlerTy DiagHandler, void *DiagContext, IntrusiveRefCntPtr ExternalFS); @@ -865,13 +863,13 @@ DirectoryEntry::~DirectoryEntry() { llvm::DeleteContainerPointers(Contents); } VFSFromYAML::~VFSFromYAML() { llvm::DeleteContainerPointers(Roots); } -VFSFromYAML *VFSFromYAML::create(MemoryBuffer *Buffer, +VFSFromYAML *VFSFromYAML::create(std::unique_ptr Buffer, SourceMgr::DiagHandlerTy DiagHandler, void *DiagContext, IntrusiveRefCntPtr ExternalFS) { SourceMgr SM; - yaml::Stream Stream(Buffer, SM); + yaml::Stream Stream(Buffer.release(), SM); SM.setDiagHandler(DiagHandler, DiagContext); yaml::document_iterator DI = Stream.begin(); @@ -993,10 +991,11 @@ VFSFromYAML::openFileForRead(const Twine &Path, } IntrusiveRefCntPtr -vfs::getVFSFromYAML(MemoryBuffer *Buffer, SourceMgr::DiagHandlerTy DiagHandler, - void *DiagContext, +vfs::getVFSFromYAML(std::unique_ptr Buffer, + SourceMgr::DiagHandlerTy DiagHandler, void *DiagContext, IntrusiveRefCntPtr ExternalFS) { - return VFSFromYAML::create(Buffer, DiagHandler, DiagContext, ExternalFS); + return VFSFromYAML::create(std::move(Buffer), DiagHandler, DiagContext, + ExternalFS); } UniqueID vfs::getNextVirtualUniqueID() { diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 070b00c63a..fbfad94ec3 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2034,7 +2034,7 @@ createVFSFromCompilerInvocation(const CompilerInvocation &CI, } IntrusiveRefCntPtr FS = - vfs::getVFSFromYAML(Buffer->release(), /*DiagHandler*/ nullptr); + vfs::getVFSFromYAML(std::move(Buffer.get()), /*DiagHandler*/ nullptr); if (!FS.get()) { Diags.Report(diag::err_invalid_vfs_overlay) << File; return IntrusiveRefCntPtr(); diff --git a/unittests/Basic/VirtualFileSystemTest.cpp b/unittests/Basic/VirtualFileSystemTest.cpp index e7d361e252..89836816e8 100644 --- a/unittests/Basic/VirtualFileSystemTest.cpp +++ b/unittests/Basic/VirtualFileSystemTest.cpp @@ -540,7 +540,8 @@ public: getFromYAMLRawString(StringRef Content, IntrusiveRefCntPtr ExternalFS) { MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Content); - return getVFSFromYAML(Buffer, CountingDiagHandler, this, ExternalFS); + return getVFSFromYAML(std::unique_ptr(Buffer), + CountingDiagHandler, this, ExternalFS); } IntrusiveRefCntPtr getFromYAMLString(