Skip to content

Commit

Permalink
Merge pull request goplus#732 from luoliwoshang/c/clang/freetoken
Browse files Browse the repository at this point in the history
c/clang:free tokens
  • Loading branch information
xushiwei authored Aug 20, 2024
2 parents 7eeca21 + 3794d7a commit 9053cbb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions c/clang/clang.go
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,14 @@ func (t *TranslationUnit) Tokenize(ran SourceRange, tokens **Token, numTokens *c
t.wrapTokenize(&ran, tokens, numTokens)
}

// CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU, CXToken *Tokens, unsigned NumTokens);

/**
* Free the given set of tokens.
*/
// llgo:link (*TranslationUnit).DisposeTokens C.clang_disposeTokens
func (t *TranslationUnit) DisposeTokens(tokens *Token, numTokens c.Uint) {}

/**
* Determine the spelling of the given token.
*
Expand Down
2 changes: 2 additions & 0 deletions chore/_xtool/castdump/castdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func printMacro(cursor clang.Cursor, unit *clang.TranslationUnit) {
var numTokens c.Uint
var tokens *clang.Token
unit.Tokenize(ran, &tokens, &numTokens)
defer unit.DisposeTokens(tokens, numTokens)

tokensSlice := unsafe.Slice(tokens, int(numTokens))
for _, tok := range tokensSlice {
tokStr := unit.Token(tok)
Expand Down

0 comments on commit 9053cbb

Please sign in to comment.