From 3ff9563c3e391954b2e224afcf8b2b0fcc3888aa Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Thu, 16 Dec 2010 03:29:14 +0000 Subject: MemoryBuffer now return an error_code and returns a OwningPtr via an out parm. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121958 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Archive/Archive.cpp | 14 ++++++-------- lib/Archive/ArchiveWriter.cpp | 11 +++++------ 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'lib/Archive') diff --git a/lib/Archive/Archive.cpp b/lib/Archive/Archive.cpp index 3ce7fbdc94..20d9deec99 100644 --- a/lib/Archive/Archive.cpp +++ b/lib/Archive/Archive.cpp @@ -148,13 +148,13 @@ Archive::Archive(const sys::Path& filename, LLVMContext& C) bool Archive::mapToMemory(std::string* ErrMsg) { - error_code ec; - mapfile = MemoryBuffer::getFile(archPath.c_str(), ec); - if (mapfile == 0) { + OwningPtr File; + if (error_code ec = MemoryBuffer::getFile(archPath.c_str(), File)) { if (ErrMsg) *ErrMsg = ec.message(); return true; } + mapfile = File.take(); base = mapfile->getBufferStart(); return false; } @@ -218,10 +218,8 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName, LLVMContext& Context, std::vector& symbols, std::string* ErrMsg) { - error_code ec; - std::auto_ptr Buffer( - MemoryBuffer::getFileOrSTDIN(fName.c_str(), ec)); - if (!Buffer.get()) { + OwningPtr Buffer; + if (error_code ec = MemoryBuffer::getFileOrSTDIN(fName.c_str(), Buffer)) { if (ErrMsg) *ErrMsg = "Could not open file '" + fName.str() + "'" + ": " + ec.message(); return true; @@ -246,7 +244,7 @@ llvm::GetBitcodeSymbols(const char *BufPtr, unsigned Length, std::vector& symbols, std::string* ErrMsg) { // Get the module. - std::auto_ptr Buffer( + OwningPtr Buffer( MemoryBuffer::getMemBufferCopy(StringRef(BufPtr, Length),ModuleID.c_str())); Module *M = ParseBitcodeFile(Buffer.get(), Context, ErrMsg); diff --git a/lib/Archive/ArchiveWriter.cpp b/lib/Archive/ArchiveWriter.cpp index e9222c5e09..07516c6aa4 100644 --- a/lib/Archive/ArchiveWriter.cpp +++ b/lib/Archive/ArchiveWriter.cpp @@ -213,13 +213,13 @@ Archive::writeMember( const char *data = (const char*)member.getData(); MemoryBuffer *mFile = 0; if (!data) { - error_code ec; - mFile = MemoryBuffer::getFile(member.getPath().c_str(), ec); - if (mFile == 0) { + OwningPtr File; + if (error_code ec = MemoryBuffer::getFile(member.getPath().c_str(), File)) { if (ErrMsg) *ErrMsg = ec.message(); return true; } + mFile = File.take(); data = mFile->getBufferStart(); fSize = mFile->getBufferSize(); } @@ -411,9 +411,8 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress, // Map in the archive we just wrote. { - error_code ec; - OwningPtr arch(MemoryBuffer::getFile(TmpArchive.c_str(), ec)); - if (arch == 0) { + OwningPtr arch; + if (error_code ec = MemoryBuffer::getFile(TmpArchive.c_str(), arch)) { if (ErrMsg) *ErrMsg = ec.message(); return true; -- cgit v1.2.3