llvm.org GIT mirror llvm / 9d44e70
Don't write into MemoryBuffers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101783 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 10 years ago
5 changed file(s) with 15 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
106106 /// into memory, the return value will be null.
107107 /// @returns a pointer to the member's data.
108108 /// @brief Get the data content of the archive member
109 const void* getData() const { return data; }
109 const char* getData() const { return data; }
110110
111111 /// This method determines if the member is a regular compressed file.
112112 /// @returns true iff the archive member is a compressed regular file.
171171 sys::PathWithStatus path; ///< Path of file containing the member
172172 sys::FileStatus info; ///< Status info (size,mode,date)
173173 unsigned flags; ///< Flags about the archive member
174 const void* data; ///< Data for the member
174 const char* data; ///< Data for the member
175175
176176 /// @}
177177 /// @name Constructors
232232 }
233233
234234 Module*
235 llvm::GetBitcodeSymbols(const unsigned char *BufPtr, unsigned Length,
235 llvm::GetBitcodeSymbols(const char *BufPtr, unsigned Length,
236236 const std::string& ModuleID,
237237 LLVMContext& Context,
238238 std::vector& symbols,
239239 std::string* ErrMsg) {
240240 // Get the module.
241241 std::auto_ptr Buffer(
242 MemoryBuffer::getNewMemBuffer(Length, ModuleID.c_str()));
243 memcpy(const_cast(Buffer->getBufferStart()), BufPtr, Length);
242 MemoryBuffer::getMemBufferCopy(StringRef(BufPtr, Length),ModuleID.c_str()));
244243
245244 Module *M = ParseBitcodeFile(Buffer.get(), Context, ErrMsg);
246245 if (!M)
7676 std::vector& symbols,
7777 std::string* ErrMsg);
7878
79 Module* GetBitcodeSymbols(const unsigned char*Buffer,unsigned Length,
79 Module* GetBitcodeSymbols(const char *Buffer, unsigned Length,
8080 const std::string& ModuleID,
8181 LLVMContext& Context,
8282 std::vector& symbols,
347347 std::string FullMemberName = archPath.str() +
348348 "(" + I->getPath().str() + ")";
349349 MemoryBuffer *Buffer =
350 MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
351 memcpy(const_cast(Buffer->getBufferStart()),
352 I->getData(), I->getSize());
350 MemoryBuffer::getMemBufferCopy(StringRef(I->getData(), I->getSize()),
351 FullMemberName.c_str());
353352
354353 Module *M = ParseBitcodeFile(Buffer, Context, ErrMessage);
355354 delete Buffer;
487486 // Now, load the bitcode module to get the Module.
488487 std::string FullMemberName = archPath.str() + "(" +
489488 mbr->getPath().str() + ")";
490 MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(mbr->getSize(),
491 FullMemberName.c_str());
492 memcpy(const_cast(Buffer->getBufferStart()),
493 mbr->getData(), mbr->getSize());
489 MemoryBuffer *Buffer =
490 MemoryBuffer::getMemBufferCopy(StringRef(mbr->getData(), mbr->getSize()),
491 FullMemberName.c_str());
494492
495493 Module *m = getLazyBitcodeModule(Buffer, Context, ErrMsg);
496494 if (!m)
539537 std::string FullMemberName = archPath.str() + "(" +
540538 mbr->getPath().str() + ")";
541539 Module* M =
542 GetBitcodeSymbols((const unsigned char*)At, mbr->getSize(),
543 FullMemberName, Context, symbols, error);
540 GetBitcodeSymbols(At, mbr->getSize(), FullMemberName, Context,
541 symbols, error);
544542
545543 if (M) {
546544 // Insert the module's symbols into the symbol table
617615 archPath.str() + "(" + I->getPath().str() + ")";
618616
619617 MemoryBuffer *Buffer =
620 MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
621 memcpy(const_cast(Buffer->getBufferStart()),
622 I->getData(), I->getSize());
618 MemoryBuffer::getMemBufferCopy(StringRef(I->getData(), I->getSize()),
619 FullMemberName.c_str());
623620 Module *M = ParseBitcodeFile(Buffer, Context);
624621 delete Buffer;
625622 if (!M)
225225 std::string FullMemberName = archPath.str() + "(" + member.getPath().str()
226226 + ")";
227227 Module* M =
228 GetBitcodeSymbols((const unsigned char*)data,fSize,
229 FullMemberName, Context, symbols, ErrMsg);
228 GetBitcodeSymbols(data, fSize, FullMemberName, Context, symbols, ErrMsg);
230229
231230 // If the bitcode parsed successfully
232231 if ( M ) {