llvm.org GIT mirror llvm / 9916d2a
Use RequiresNullTerminator to create buffers without a null terminator instead of copying. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127835 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 9 years ago
3 changed file(s) with 8 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
8080 /// getMemBuffer - Open the specified memory range as a MemoryBuffer. Note
8181 /// that InputData must be null terminated.
8282 static MemoryBuffer *getMemBuffer(StringRef InputData,
83 StringRef BufferName = "");
83 StringRef BufferName = "",
84 bool RequiresNullTerminator = true);
8485
8586 /// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
8687 /// copying the contents and taking ownership of it. InputData does not
9191 /// getMemBuffer - Open the specified memory range as a MemoryBuffer. Note
9292 /// that EndPtr[0] must be a null byte and be accessible!
9393 MemoryBuffer *MemoryBuffer::getMemBuffer(StringRef InputData,
94 StringRef BufferName) {
95 return GetNamedBuffer(InputData, BufferName, true);
94 StringRef BufferName,
95 bool RequiresNullTerminator) {
96 return GetNamedBuffer(InputData, BufferName,
97 RequiresNullTerminator);
9698 }
9799
98100 /// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
113113 return makeLTOModule(buffer.get(), errMsg);
114114 }
115115
116 /// makeBuffer - Create a MemoryBuffer from a memory range. MemoryBuffer
117 /// requires the byte past end of the buffer to be a zero. We might get lucky
118 /// and already be that way, otherwise make a copy. Also if next byte is on a
119 /// different page, don't assume it is readable.
116 /// makeBuffer - Create a MemoryBuffer from a memory range.
120117 MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) {
121118 const char *startPtr = (char*)mem;
122119 const char *endPtr = startPtr+length;
123 if (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0 ||
124 *endPtr != 0)
125 return MemoryBuffer::getMemBufferCopy(StringRef(startPtr, length));
126
127 return MemoryBuffer::getMemBuffer(StringRef(startPtr, length));
120 return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), "", false);
128121 }
129122
130123