diff --git a/chore/_xtool/llcppsymg/llcppsymg.go b/chore/_xtool/llcppsymg/llcppsymg.go index af1a8538..8d356a63 100644 --- a/chore/_xtool/llcppsymg/llcppsymg.go +++ b/chore/_xtool/llcppsymg/llcppsymg.go @@ -53,6 +53,7 @@ func main() { config, err := getConf(data) check(err) + defer config.Delete() if err != nil { fmt.Fprintln(os.Stderr, "Failed to parse config file:", cfgFile) @@ -77,19 +78,24 @@ func check(err error) { } } -func getConf(data []byte) (*types.Config, error) { - conf := cjson.ParseBytes(data) - if conf == nil { - return nil, errors.New("failed to parse config") +func getConf(data []byte) (types.Conf, error) { + parsedConf := cjson.ParseBytes(data) + if parsedConf == nil { + return types.Conf{}, errors.New("failed to parse config") } + config := &types.Config{ - Name: getStringItem(conf, "name", ""), - CFlags: getStringItem(conf, "cflags", ""), - Libs: getStringItem(conf, "libs", ""), - Include: getStringArrayItem(conf, "include"), - TrimPrefixes: getStringArrayItem(conf, "trimPrefixes"), + Name: getStringItem(parsedConf, "name", ""), + CFlags: getStringItem(parsedConf, "cflags", ""), + Libs: getStringItem(parsedConf, "libs", ""), + Include: getStringArrayItem(parsedConf, "include"), + TrimPrefixes: getStringArrayItem(parsedConf, "trimPrefixes"), } - return config, nil + + return types.Conf{ + JSON: parsedConf, + Config: config, + }, nil } func getString(obj *cjson.JSON) (value string) { diff --git a/chore/llcppg/types/types.go b/chore/llcppg/types/types.go index e71885ef..bd516458 100644 --- a/chore/llcppg/types/types.go +++ b/chore/llcppg/types/types.go @@ -16,6 +16,10 @@ package types +import ( + "github.com/goplus/llgo/c/cjson" +) + // Config represents a configuration for the llcppg tool. type Config struct { Name string `json:"name"` @@ -26,6 +30,11 @@ type Config struct { JSONPath string `json:"jsonPath"` } +type Conf struct { + *cjson.JSON + *Config +} + type CPPSymbol struct { Symbol string `json:"symbol"` Type string `json:"type"`