[cfe-dev] Proposal for solving C string lifetime problem with clang_getDeclSpelling()/Selector::getAsString()

John Thompson john.thompson.jtsoftware at gmail.com
Fri Nov 6 19:18:34 PST 2009


Sorry, I forgot to hit the save button after editing out some other changes
from the patch.  Here's the corrected version.

On Fri, Nov 6, 2009 at 5:29 PM, John Thompson <
john.thompson.jtsoftware at gmail.com> wrote:

> Here's my stab at the CXString conversion.
>
> I also moved getLocationFromCursor to fix a compiler warning.
> -John
>   On Fri, Nov 6, 2009 at 3:27 PM, John Thompson <
> john.thompson.jtsoftware at gmail.com> wrote:
>
>> Sure, I'll take a crack at it.
>>
>> -John
>>
>>   On Fri, Nov 6, 2009 at 11:14 AM, steve naroff <snaroff at apple.com>wrote:
>>
>>> Hi John,
>>>
>>> I just spoke with Doug about this and we came up with the following
>>> proposal...
>>>
>>> The following API would now return a CXString;
>>>
>>> CINDEX_LINKAGE CXString clang_getDeclSpelling(CXDecl);
>>>
>>> The interface to CXString would be:
>>>
>>> const char *clang_getCString(CXString);
>>> void clang_disposeString(CXString); /* client must always call this when
>>> it no longer needs the string */
>>>
>>> The implementation of CXString would be:
>>>
>>> /* Note that both of these slots are effectively 'private' */
>>> typedef struct {
>>>  const char *Spelling;
>>>  /* A 1 value indicates the clang_ indexing API needed to allocate the
>>> string (and it must be freed by clang_disposeString()). */
>>>  int MustFreeString;
>>> } CXString;
>>>
>>> The benefit of this abstraction is we can use it in other places if
>>> necessary (when dealing with string lifetime issues that cross the C/C++
>>> language barrier).
>>>
>>> What do you (or others interested in this) think? From my perspective, it
>>> seems cleaner than the other proposals that have been discussed.
>>>
>>> If we can agree on the change, are you interested in making this change?
>>>
>>> Thanks much,
>>>
>>> snaroff
>>>
>>>
>>>
>>>
>>>
>>
>>
>> --
>> John Thompson
>> John.Thompson.JTSoftware at gmail.com
>>
>>
>
>
> --
> John Thompson
> John.Thompson.JTSoftware at gmail.com
>
>


-- 
John Thompson
John.Thompson.JTSoftware at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20091106/81ae8519/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CXString.patch
Type: application/octet-stream
Size: 16912 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20091106/81ae8519/attachment.obj>


More information about the cfe-dev mailing list