diff --git a/tool/_testc/python-3.14.8/cpython-pythread.go b/tool/_testc/python-3.14.8/cpython-pythread.go deleted file mode 100644 index 2a58460e0..000000000 --- a/tool/_testc/python-3.14.8/cpython-pythread.go +++ /dev/null @@ -1,17 +0,0 @@ -// Code generated by llcppg; DO NOT EDIT. - -package py - -import ( - "github.com/goplus/lib/c" - "github.com/goplus/lib/c/pthread" - _ "unsafe" -) - -type X_PyTssT struct { - X_isInitialized c.Int - X_key pthread.Key -} - -//go:linkname PY_TIMEOUT_MAX C.PY_TIMEOUT_MAX -var PY_TIMEOUT_MAX c.LongLong diff --git a/tool/_testc/python-3.14.8/llcppg.cfg b/tool/_testc/python-3.14.8/llcppg.cfg index 7bb72c8db..998886eec 100644 --- a/tool/_testc/python-3.14.8/llcppg.cfg +++ b/tool/_testc/python-3.14.8/llcppg.cfg @@ -17,6 +17,7 @@ }, "MacroIgnore": [], "TypeIgnore": [], + "GroupSubdirBy": "fname", "FailFast": 10, "IgnoreInline": true, "Language": "c" diff --git a/tool/_testc/python-3.14.8/pythread.go b/tool/_testc/python-3.14.8/pythread.go index 5691553b7..226402bd6 100644 --- a/tool/_testc/python-3.14.8/pythread.go +++ b/tool/_testc/python-3.14.8/pythread.go @@ -2,7 +2,11 @@ package py -import "github.com/goplus/lib/c" +import ( + "github.com/goplus/lib/c" + "github.com/goplus/lib/c/pthread" + _ "unsafe" +) type PyLockStatus c.Uint @@ -13,4 +17,11 @@ const ( ) type PyThreadTypeLock uintptr +type X_PyTssT struct { + X_isInitialized c.Int + X_key pthread.Key +} type PyTssT = X_PyTssT + +//go:linkname PY_TIMEOUT_MAX C.PY_TIMEOUT_MAX +var PY_TIMEOUT_MAX c.LongLong diff --git a/tool/_testcpp/llvm-22.1.8-support/llcppg-adt.cfg b/tool/_testcpp/llvm-22.1.8-support/llcppg-adt.cfg index 67318aba9..088690a4c 100644 --- a/tool/_testcpp/llvm-22.1.8-support/llcppg-adt.cfg +++ b/tool/_testcpp/llvm-22.1.8-support/llcppg-adt.cfg @@ -14,5 +14,6 @@ "Rename": { }, "TypeIgnore": [], - "NSIgnore": [] + "NSIgnore": [], + "GroupSubdirBy": "dir" } diff --git a/tool/config.go b/tool/config.go index 5d6fd5d26..59bc91c71 100644 --- a/tool/config.go +++ b/tool/config.go @@ -57,7 +57,8 @@ type Config struct { FailFast int `json:"FailFast"` // exit on first N errors, optional IgnoreInline bool `json:"IgnoreInline"` // quietly ignore inline functions NoManglingIgnore bool `json:"NoManglingIgnore"` // quietly ignore functions with no mangled symbol - GroupSubdir bool `json:"GroupSubdir"` // treats sub-directory files as a single file + GroupSubdir bool `json:"GroupSubdir"` // treats sub-directory files as a single file. Deprecated: use GroupSubdirBy instead. + GroupSubdirBy string `json:"GroupSubdirBy"` // criterion to group sub-directory files by, e.g., "dir" or "fname". `GroupSubdir = true` is equivalent to `GroupSubdirBy = "dir"`. } // ----------------------------------------------------------------------------- diff --git a/tool/gen.go b/tool/gen.go index 538de20de..fb5b7362b 100644 --- a/tool/gen.go +++ b/tool/gen.go @@ -173,7 +173,19 @@ func (cfg *Config) NewPackage(pkgPath, pkgName, workDir string, index clang.Inde } defer DisposeSources(files) - groupSubdir := cfg.GroupSubdir + groupSubdirBy := groupSubdirByNone + switch cfg.GroupSubdirBy { + case "dir": + groupSubdirBy = groupSubdirByDir + case "fname": + groupSubdirBy = groupSubdirByFname + case "": + if cfg.GroupSubdir { + groupSubdirBy = groupSubdirByDir + } + default: + log.Println("[WARN] unknown GroupSubdirBy value:", cfg.GroupSubdirBy) + } srcFilePrefix := dir + string(os.PathSeparator) if pkgName == "" { pkgName = path.Base(cfg.Name) @@ -216,7 +228,7 @@ func (cfg *Config) NewPackage(pkgPath, pkgName, workDir string, index clang.Inde return }, GoFileOf: func(headerFile string) (fname string, ok bool) { - return goFileOf(headerFile, srcFilePrefix, groupSubdir) + return goFileOf(headerFile, srcFilePrefix, groupSubdirBy) }, }) return @@ -232,16 +244,27 @@ func listHeaderFiles(selFiles []string, headerDir string) (topHeaders []string) return } -func goFileOf(at, srcFilePrefix string, groupSubdir bool) (fname string, ok bool) { +const ( + groupSubdirByNone = iota + groupSubdirByDir + groupSubdirByFname +) + +func goFileOf(at, srcFilePrefix string, groupSubdirBy int) (fname string, ok bool) { const pathSep = string(os.PathSeparator) const goFileExt = ".go" fname, ok = strings.CutPrefix(at, srcFilePrefix) if ok { - if groupSubdir { + switch groupSubdirBy { + case groupSubdirByDir: if pos := strings.Index(fname, pathSep); pos > 0 { fname = fname[:pos] } - } else { + case groupSubdirByFname: + if pos := strings.LastIndex(fname, pathSep); pos >= 0 { + fname = fname[pos+1:] + } + default: fname = strings.ReplaceAll(fname, pathSep, "-") } if pos := strings.LastIndex(fname, "."); pos > 0 {