Don't write into MemoryBuffers.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101783 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2010-04-19 16:15:31 +00:00
parent 985744ecc6
commit 9d44e70272
5 changed files with 15 additions and 20 deletions

View File

@ -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

View File

@ -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)

View File

@ -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,

View File

@ -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)

View File

@ -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 ) {