[llvm-commits] [PATCH 3/5] [llvm-c] Add LLVMCreateMemoryBufferFromData.

Gregory Szorc gregory.szorc at gmail.com
Wed Mar 21 21:26:42 PDT 2012


On 3/19/2012 1:24 PM, Anders Waldenborg wrote:
> ---
>  include/llvm-c/Core.h |    4 ++++
>  lib/VMCore/Core.cpp   |   13 +++++++++++++
>  2 files changed, 17 insertions(+), 0 deletions(-)

+LLVMBool LLVMCreateMemoryBufferFromData(LLVMMemoryBufferRef *OutMemBuf,
+					const char *name,
+					const char *data,
+					int len) {
                                        ^^^
                                        use unsigned or size_t.
StringRef takes size_t yet the existing C APIs all use unsigned. I'll
defer final judgement to others.

+  MemoryBuffer *MB;
+
+  StringRef buf(data, len);
+
+  MB = MemoryBuffer::getMemBufferCopy(buf, name);
+  *OutMemBuf = wrap(MB);
   ^
   Possible NULL access.

You should also add docs to the header and call out that the buffer is
copied.




More information about the llvm-commits mailing list