mirror of
https://github.com/burrowers/garble.git
synced 2025-12-24 12:58:05 +08:00
take advantage of some APIs added in Go 1.24
Primarily new iterator APIs in the strings and go/types packages. While here, verify that the processImportCfg hack is stil needed as of go1.24.2.
This commit is contained in:
committed by
Paul Scheduikat
parent
2bb1d49874
commit
32e1e0aa2b
13
main.go
13
main.go
@@ -695,7 +695,7 @@ func (tf *transformer) transformAsm(args []string) ([]string, error) {
|
||||
|
||||
// Preprocessor lines to include another file.
|
||||
// For example: #include "foo.h"
|
||||
if quoted := strings.TrimPrefix(line, "#include"); quoted != line {
|
||||
if quoted, ok := strings.CutPrefix(line, "#include"); ok {
|
||||
quoted = strings.TrimSpace(quoted)
|
||||
path, err := strconv.Unquote(quoted)
|
||||
if err != nil { // note that strconv.Unquote errors do not include the input string
|
||||
@@ -1185,10 +1185,9 @@ func (tf *transformer) transformLinkname(localName, newName string) (string, str
|
||||
|
||||
var newForeignName string
|
||||
if receiver, name, ok := strings.Cut(foreignName, "."); ok {
|
||||
if strings.HasPrefix(receiver, "(*") {
|
||||
if receiver, ok = strings.CutPrefix(receiver, "(*"); ok {
|
||||
// pkg/path.(*Receiver).method
|
||||
receiver = strings.TrimPrefix(receiver, "(*")
|
||||
receiver = strings.TrimSuffix(receiver, ")")
|
||||
receiver, _ = strings.CutSuffix(receiver, ")")
|
||||
receiver = "(*" + hashWithPackage(lpkg, receiver) + ")"
|
||||
} else {
|
||||
// pkg/path.Receiver.method
|
||||
@@ -1234,7 +1233,7 @@ func (tf *transformer) processImportCfg(flags []string, requiredPkgs []string) (
|
||||
}
|
||||
}
|
||||
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
for line := range strings.SplitSeq(string(data), "\n") {
|
||||
if line == "" || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
@@ -1332,7 +1331,7 @@ func (tf *transformer) processImportCfg(flags []string, requiredPkgs []string) (
|
||||
// See exporttest/*.go in testdata/scripts/test.txt.
|
||||
// For now, spot the pattern and avoid the unnecessary error;
|
||||
// the dependency is unused, so the packagefile line is redundant.
|
||||
// This still triggers as of go1.21.
|
||||
// This still triggers as of go1.24.
|
||||
if strings.HasSuffix(tf.curPkg.ImportPath, ".test]") && strings.HasPrefix(tf.curPkg.ImportPath, impPath) {
|
||||
continue
|
||||
}
|
||||
@@ -2257,7 +2256,7 @@ func flagValue(flags []string, name string) string {
|
||||
// those whose values compose a list.
|
||||
func flagValueIter(flags []string, name string, fn func(string)) {
|
||||
for i, arg := range flags {
|
||||
if val := strings.TrimPrefix(arg, name+"="); val != arg {
|
||||
if val, ok := strings.CutPrefix(arg, name+"="); ok {
|
||||
// -name=value
|
||||
fn(val)
|
||||
}
|
||||
|
||||
13
reflect.go
13
reflect.go
@@ -68,9 +68,7 @@ func (ri *reflectInspector) ignoreReflectedTypes(ssaPkg *ssa.Package) {
|
||||
// so some logic is required to find the methods a type has
|
||||
|
||||
method := func(mset *types.MethodSet) {
|
||||
for i := range mset.Len() {
|
||||
at := mset.At(i)
|
||||
|
||||
for at := range mset.Methods() {
|
||||
if m := ssaPkg.Prog.MethodValue(at); m != nil {
|
||||
ri.checkFunction(m)
|
||||
} else {
|
||||
@@ -78,7 +76,6 @@ func (ri *reflectInspector) ignoreReflectedTypes(ssaPkg *ssa.Package) {
|
||||
// handle interface declarations
|
||||
ri.checkInterfaceMethod(m)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,15 +107,14 @@ func (ri *reflectInspector) checkMethodSignature(reflectParams map[int]bool, sig
|
||||
return
|
||||
}
|
||||
|
||||
params := sig.Params()
|
||||
for i := range params.Len() {
|
||||
i := 0
|
||||
for param := range sig.Params().Variables() {
|
||||
if reflectParams[i] {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
||||
ignore := false
|
||||
param := params.At(i)
|
||||
|
||||
switch x := param.Type().(type) {
|
||||
case *types.Struct:
|
||||
ignore = true
|
||||
@@ -136,6 +132,7 @@ func (ri *reflectInspector) checkMethodSignature(reflectParams map[int]bool, sig
|
||||
reflectParams[i] = true
|
||||
ri.recursivelyRecordUsedForReflect(param.Type())
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user