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

steve naroff snaroff at apple.com
Mon Nov 9 08:38:16 PST 2009


Hey John,

Thanks for implementing this...I'm going to integrate the patch now.

snaroff

On Nov 6, 2009, at 10:18 PM, John Thompson wrote:

> 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
>
> <CXString.patch>_______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20091109/4f128649/attachment.html>


More information about the cfe-dev mailing list