[llvm-commits] [llvm] r77149 - /llvm/trunk/lib/VMCore/Value.cpp

Daniel Dunbar daniel at zuster.org
Mon Jul 27 15:43:07 PDT 2009


Hi Dan,

The problem is there can't be a c_str method on StringRef, it has no
way to make that guarantee.

Since you essentially called me out on adding a hack, let me explain. :)

In my opinion, the real problem is that historically clients were
using getNameStart() and expecting it to be null terminated. This
happens to be true, because the contents are in a string map and they
are null terminated, but (a) it may not be the full name, and (b) this
was not really part of the getNameStart() contract.

The right solution is for clients to use an API which doesn't depend
on null termination (and I have actively been moving stuff over). I
added a comment to Value::getName to make this clearer.

Seem ok?

 - Daniel

On Mon, Jul 27, 2009 at 2:07 PM, Dan Gohman<gohman at apple.com> wrote:
>
> On Jul 26, 2009, at 2:22 AM, Daniel Dunbar wrote:
>
>
>> Author: ddunbar
>> Date: Sun Jul 26 04:22:02 2009
>> New Revision: 77149
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=77149&view=rev
>> Log:
>> Make sure getName().data() is always null terminated.
>
> Hi Daniel,
>
> The doxygen comment for StringRef::data() says it may not be null
> terminated. This is also consistent with std::string. If there are
> clients that need a nul-terminated string, shouldn't there be a
> c_str() method?
>
> Dan
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>



More information about the llvm-commits mailing list