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

steve naroff snaroff at apple.com
Fri Nov 6 11:14:37 PST 2009


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



  
  



More information about the cfe-dev mailing list