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

Anders Waldenborg anders at 0x63.nu
Thu Mar 22 12:17:14 PDT 2012


On Wed, Mar 21, 2012 at 09:26:42PM -0700, Gregory Szorc wrote:
> +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.

At least 'int' doesn't make any sense.

Patch updated to use unsigned instead attached.
0001-llvm-c-Add-LLVMCreateMemoryBufferFromData.patch

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

Exact same behaviour as the other LLVMCreateMemoryBuffer* functions.

Attached
0003-llvm-c-Add-some-extra-checking-to-LLVMCreateMemoryBu.patch
changes that in all of these functions. And the other functions also
have an "OutMessage" parameter that get the same error checking.

Personally I prefer having it crash than trying to cover up all
misuses of the API. Or if feeling friendly just have an assert.

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

0002-llvm-c-Basic-MemoryBuffer-documentation.patch adds documentation
to all LLVMCreateMemoryBuffer* functions.


thanks,
 anders
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-llvm-c-Add-LLVMCreateMemoryBufferFromData.patch
Type: text/x-diff
Size: 1754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120322/3a99f153/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-llvm-c-Basic-MemoryBuffer-documentation.patch
Type: text/x-diff
Size: 2294 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120322/3a99f153/attachment-0001.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-llvm-c-Add-some-extra-checking-to-LLVMCreateMemoryBu.patch
Type: text/x-diff
Size: 2536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120322/3a99f153/attachment-0002.patch>


More information about the llvm-commits mailing list