<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-text-flowed" style="font-family: -moz-fixed;
font-size: 14px;" lang="x-western">On 2/13/2013 5:46 AM, Chris
Lattner wrote:
<br>
<blockquote type="cite" style="color: #000000;">On Feb 10, 2013,
at 9:13 AM, Moritz Maxeiner <a class="moz-txt-link-rfc2396E"
href="mailto:moritzmaxeiner@googlemail.com"><moritzmaxeiner@googlemail.com></a>
wrote:
<br>
<br>
<blockquote type="cite" style="color: #000000;">Add two new
functions to the C API:
<br>
<br>
LLVMCreateMemoryBufferWithMemoryRange - exposes
MemoryBuffer::getMemBuffer
<br>
LLVMCreateMemoryBufferWithMemoryRangeCopy - exposes
MemoryBuffer::getMemBufferCopy
<br>
</blockquote>
These new APIs should take a "const char*" + length. The memory
buffer may have embedded nul's in it.
<br>
</blockquote>
<br>
Of course, my bad. I assume the BufferName may not contain nuls,
so I added the lengths only for the
<br>
InputData, if that is not the case - i.e. the BufferName may
contain nuls - I'll change that as well.
<br>
For now, here the patch with length added for the InputData:
<br>
<br>
Index: lib/IR/Core.cpp
<br>
===================================================================
<br>
--- lib/IR/Core.cpp (revision 175052)
<br>
+++ lib/IR/Core.cpp (working copy)
<br>
@@ -2369,6 +2369,29 @@
<br>
return 1;
<br>
}
<br>
<br>
+LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(
<br>
+ const char *InputData,
<br>
+ size_t InputDataLength,
<br>
+ const char *BufferName,
<br>
+ bool RequiresNullTerminator) {
<br>
+
<br>
+ return wrap(MemoryBuffer::getMemBuffer(
<br>
+ StringRef(InputData, InputDataLength),
<br>
+ StringRef(BufferName),
<br>
+ RequiresNullTerminator));
<br>
+}
<br>
+
<br>
+LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(
<br>
+ const char *InputData,
<br>
+ size_t InputDataLength,
<br>
+ const char *BufferName) {
<br>
+
<br>
+ return wrap(MemoryBuffer::getMemBufferCopy(
<br>
+ StringRef(InputData, InputDataLength),
<br>
+ StringRef(BufferName)));
<br>
+}
<br>
+
<br>
+
<br>
void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) {
<br>
delete unwrap(MemBuf);
<br>
}
<br>
Index: include/llvm-c/Core.h
<br>
===================================================================
<br>
--- include/llvm-c/Core.h (revision 175052)
<br>
+++ include/llvm-c/Core.h (working copy)
<br>
@@ -2548,6 +2548,13 @@
<br>
char
**OutMessage);
<br>
LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef
*OutMemBuf,
<br>
char **OutMessage);
<br>
+LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const
char *InputData,
<br>
+ size_t
InputDataLength,
<br>
+ const
char *BufferName,
<br>
+ bool
RequiresNullTerminator);
<br>
+LLVMMemoryBufferRef
LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
<br>
+ size_t InputDataLength,
<br>
+
const char *BufferName);
<br>
void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
<br>
<br>
/**
<pre wrap="">
</pre>
</div>
</body>
</html>