llcppsymg:remove one leading underscore only in mac

This commit is contained in:
luoliwoshang
2024-10-26 18:43:14 +08:00
parent e6bfe1fc88
commit 7747082ae8
7 changed files with 56 additions and 39 deletions

View File

@@ -2,6 +2,7 @@ package parse
import (
"errors"
"runtime"
"strconv"
"strings"
@@ -129,12 +130,13 @@ func (p *SymbolProcessor) collectFuncInfo(cursor clang.Cursor) {
symbol := cursor.Mangling()
defer symbol.Dispose()
// Remove all leading underscores from C++ symbol names
// On Linux, C++ symbols typically have one leading underscore
// On macOS, C++ symbols may have two leading underscores
// We remove all leading underscores to handle both cases consistently
// For consistency, we remove the first leading underscore on macOS
symbolName := c.GoString(symbol.CStr())
symbolName = strings.TrimLeft(symbolName, "_")
if runtime.GOOS == "darwin" {
symbolName = strings.TrimPrefix(symbolName, "_")
}
p.SymbolMap[symbolName] = &SymbolInfo{
GoName: p.genGoName(cursor),
ProtoName: p.genProtoName(cursor),