diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-04-19 16:15:31 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-04-19 16:15:31 +0000 |
commit | 9d44e702725a534c8e80edce52c7e71f71f37c06 (patch) | |
tree | 45d25ae2ef771d9801de0119b21b8cda349bd17d | |
parent | 985744ecc606211cb165e231a24a27b7e7835494 (diff) |
Don't write into MemoryBuffers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101783 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Bitcode/Archive.h | 4 | ||||
-rw-r--r-- | lib/Archive/Archive.cpp | 5 | ||||
-rw-r--r-- | lib/Archive/ArchiveInternals.h | 2 | ||||
-rw-r--r-- | lib/Archive/ArchiveReader.cpp | 21 | ||||
-rw-r--r-- | lib/Archive/ArchiveWriter.cpp | 3 |
5 files changed, 15 insertions, 20 deletions
diff --git a/include/llvm/Bitcode/Archive.h b/include/llvm/Bitcode/Archive.h index 67f2a4a999..83a37585fa 100644 --- a/include/llvm/Bitcode/Archive.h +++ b/include/llvm/Bitcode/Archive.h @@ -107,7 +107,7 @@ class ArchiveMember : public ilist_node<ArchiveMember> { /// into memory, the return value will be null. /// @returns a pointer to the member's data. /// @brief Get the data content of the archive member - const void* getData() const { return data; } + const char* getData() const { return data; } /// This method determines if the member is a regular compressed file. /// @returns true iff the archive member is a compressed regular file. @@ -172,7 +172,7 @@ class ArchiveMember : public ilist_node<ArchiveMember> { sys::PathWithStatus path; ///< Path of file containing the member sys::FileStatus info; ///< Status info (size,mode,date) unsigned flags; ///< Flags about the archive member - const void* data; ///< Data for the member + const char* data; ///< Data for the member /// @} /// @name Constructors diff --git a/lib/Archive/Archive.cpp b/lib/Archive/Archive.cpp index 4f100f7b11..54c715c604 100644 --- a/lib/Archive/Archive.cpp +++ b/lib/Archive/Archive.cpp @@ -233,15 +233,14 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName, } Module* -llvm::GetBitcodeSymbols(const unsigned char *BufPtr, unsigned Length, +llvm::GetBitcodeSymbols(const char *BufPtr, unsigned Length, const std::string& ModuleID, LLVMContext& Context, std::vector<std::string>& symbols, std::string* ErrMsg) { // Get the module. std::auto_ptr<MemoryBuffer> Buffer( - MemoryBuffer::getNewMemBuffer(Length, ModuleID.c_str())); - memcpy(const_cast<char *>(Buffer->getBufferStart()), BufPtr, Length); + MemoryBuffer::getMemBufferCopy(StringRef(BufPtr, Length),ModuleID.c_str())); Module *M = ParseBitcodeFile(Buffer.get(), Context, ErrMsg); if (!M) diff --git a/lib/Archive/ArchiveInternals.h b/lib/Archive/ArchiveInternals.h index baea544d20..08f20e7481 100644 --- a/lib/Archive/ArchiveInternals.h +++ b/lib/Archive/ArchiveInternals.h @@ -77,7 +77,7 @@ namespace llvm { std::vector<std::string>& symbols, std::string* ErrMsg); - Module* GetBitcodeSymbols(const unsigned char*Buffer,unsigned Length, + Module* GetBitcodeSymbols(const char *Buffer, unsigned Length, const std::string& ModuleID, LLVMContext& Context, std::vector<std::string>& symbols, diff --git a/lib/Archive/ArchiveReader.cpp b/lib/Archive/ArchiveReader.cpp index cbd0bb3975..05d32de008 100644 --- a/lib/Archive/ArchiveReader.cpp +++ b/lib/Archive/ArchiveReader.cpp @@ -348,9 +348,8 @@ Archive::getAllModules(std::vector<Module*>& Modules, std::string FullMemberName = archPath.str() + "(" + I->getPath().str() + ")"; MemoryBuffer *Buffer = - MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str()); - memcpy(const_cast<char *>(Buffer->getBufferStart()), - I->getData(), I->getSize()); + MemoryBuffer::getMemBufferCopy(StringRef(I->getData(), I->getSize()), + FullMemberName.c_str()); Module *M = ParseBitcodeFile(Buffer, Context, ErrMessage); delete Buffer; @@ -488,10 +487,9 @@ Archive::findModuleDefiningSymbol(const std::string& symbol, // Now, load the bitcode module to get the Module. std::string FullMemberName = archPath.str() + "(" + mbr->getPath().str() + ")"; - MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(mbr->getSize(), - FullMemberName.c_str()); - memcpy(const_cast<char *>(Buffer->getBufferStart()), - mbr->getData(), mbr->getSize()); + MemoryBuffer *Buffer = + MemoryBuffer::getMemBufferCopy(StringRef(mbr->getData(), mbr->getSize()), + FullMemberName.c_str()); Module *m = getLazyBitcodeModule(Buffer, Context, ErrMsg); if (!m) @@ -540,8 +538,8 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols, std::string FullMemberName = archPath.str() + "(" + mbr->getPath().str() + ")"; Module* M = - GetBitcodeSymbols((const unsigned char*)At, mbr->getSize(), - FullMemberName, Context, symbols, error); + GetBitcodeSymbols(At, mbr->getSize(), FullMemberName, Context, + symbols, error); if (M) { // Insert the module's symbols into the symbol table @@ -618,9 +616,8 @@ bool Archive::isBitcodeArchive() { archPath.str() + "(" + I->getPath().str() + ")"; MemoryBuffer *Buffer = - MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str()); - memcpy(const_cast<char *>(Buffer->getBufferStart()), - I->getData(), I->getSize()); + MemoryBuffer::getMemBufferCopy(StringRef(I->getData(), I->getSize()), + FullMemberName.c_str()); Module *M = ParseBitcodeFile(Buffer, Context); delete Buffer; if (!M) diff --git a/lib/Archive/ArchiveWriter.cpp b/lib/Archive/ArchiveWriter.cpp index a02601a4aa..21d4f6566c 100644 --- a/lib/Archive/ArchiveWriter.cpp +++ b/lib/Archive/ArchiveWriter.cpp @@ -226,8 +226,7 @@ Archive::writeMember( std::string FullMemberName = archPath.str() + "(" + member.getPath().str() + ")"; Module* M = - GetBitcodeSymbols((const unsigned char*)data,fSize, - FullMemberName, Context, symbols, ErrMsg); + GetBitcodeSymbols(data, fSize, FullMemberName, Context, symbols, ErrMsg); // If the bitcode parsed successfully if ( M ) { |