[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 15:27:40 PST 2009


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20091106/308d4b15/attachment.html>


More information about the cfe-dev mailing list