purego: apply go fix modernizations (#504)
Go 1.27's go fix rewrites constructs that newer standard library APIs express better. Running it over every GOOS/GOARCH this module builds for turns up three sites, all mechanical: compareStatus walks the lines of a /proc status file, so the slice from strings.Split only exists to be ranged over; SplitSeq yields the same lines without materializing it. The same function sorts a field list with sort.Slice and a less function that is plain string comparison, which is what slices.Sort does for an ordered element type. NewCallback asks whether an argument is assignable to CDecl, a type known at compile time, so reflect.TypeFor names it directly instead of building a value to take the type of. The cgo-enabled cross builds could not be analyzed on the machine this ran on, which has no cross C toolchain; darwin/amd64 and darwin/arm64 with cgo were covered and reported nothing. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
- commit
- 63002e03babc73db86f10d03de8c1da435a35eea
- author
- Hajime Hoshi · · 2026-08-30 10:50 UTC
- committer
- GitHub · · 2026-08-30 10:50 UTC
- parent
- f389379
- signature
- GPG Unverified
B5690EEEBB952194The key is unknown - refs
- tag: v0.11.0-alpha.11
2 files · +5 -5
M syscall_linux_test.go +4 -4
| @@ -10,7 +10,7 @@ import ( | |||
| 10 | 10 | "os" | |
| 11 | 11 | "path/filepath" | |
| 12 | 12 | "runtime" | |
| 13 | - | "sort" | |
| 13 | + | "slices" | |
| 14 | 14 | "strings" | |
| 15 | 15 | "syscall" | |
| 16 | 16 | "testing" | |
| @@ -119,8 +119,8 @@ func compareStatus(filter, expect string) error { | |||
| 119 | 119 | // "... : bad file descriptor. | |
| 120 | 120 | continue | |
| 121 | 121 | } | |
| 122 | - | lines := strings.Split(string(d), "\n") | |
| 123 | - | for _, line := range lines { | |
| 122 | + | lines := strings.SplitSeq(string(d), "\n") | |
| 123 | + | for line := range lines { | |
| 124 | 124 | // Different kernel vintages pad differently. | |
| 125 | 125 | line = strings.TrimSpace(line) | |
| 126 | 126 | if strings.HasPrefix(line, "Pid:\t") { | |
| @@ -149,7 +149,7 @@ func compareStatus(filter, expect string) error { | |||
| 149 | 149 | // https://github.com/golang/go/issues/46145 | |
| 150 | 150 | // Containers don't reliably output this line in sorted order so manually sort and compare that. | |
| 151 | 151 | a := strings.Split(line[8:], " ") | |
| 152 | - | sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) | |
| 152 | + | slices.Sort(a) | |
| 153 | 153 | got := strings.Join(a, " ") | |
| 154 | 154 | if got == expected[8:] { | |
| 155 | 155 | foundAThread = true | |
| @@ -10,7 +10,7 @@ import ( | |||||
| 10 | "os" | 10 | "os" | ||
| 11 | "path/filepath" | 11 | "path/filepath" | ||
| 12 | "runtime" | 12 | "runtime" | ||
| 13 | - | "sort" | 13 | + | "slices" |
| 14 | "strings" | 14 | "strings" | ||
| 15 | "syscall" | 15 | "syscall" | ||
| 16 | "testing" | 16 | "testing" | ||
| @@ -119,8 +119,8 @@ func compareStatus(filter, expect string) error { | |||||
| 119 | // "... : bad file descriptor. | 119 | // "... : bad file descriptor. | ||
| 120 | continue | 120 | continue | ||
| 121 | } | 121 | } | ||
| 122 | - | lines := strings.Split(string(d), "\n") | 122 | + | lines := strings.SplitSeq(string(d), "\n") |
| 123 | - | for _, line := range lines { | 123 | + | for line := range lines { |
| 124 | // Different kernel vintages pad differently. | 124 | // Different kernel vintages pad differently. | ||
| 125 | line = strings.TrimSpace(line) | 125 | line = strings.TrimSpace(line) | ||
| 126 | if strings.HasPrefix(line, "Pid:\t") { | 126 | if strings.HasPrefix(line, "Pid:\t") { | ||
| @@ -149,7 +149,7 @@ func compareStatus(filter, expect string) error { | |||||
| 149 | // https://github.com/golang/go/issues/46145 | 149 | // https://github.com/golang/go/issues/46145 | ||
| 150 | // Containers don't reliably output this line in sorted order so manually sort and compare that. | 150 | // Containers don't reliably output this line in sorted order so manually sort and compare that. | ||
| 151 | a := strings.Split(line[8:], " ") | 151 | a := strings.Split(line[8:], " ") | ||
| 152 | - | sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) | 152 | + | slices.Sort(a) |
| 153 | got := strings.Join(a, " ") | 153 | got := strings.Join(a, " ") | ||
| 154 | if got == expected[8:] { | 154 | if got == expected[8:] { | ||
| 155 | foundAThread = true | 155 | foundAThread = true | ||
M syscall_windows.go +1 -1
| @@ -28,7 +28,7 @@ func NewCallback(fn any) uintptr { | |||
| 28 | 28 | ty := reflect.TypeOf(fn) | |
| 29 | 29 | for i := range ty.NumIn() { | |
| 30 | 30 | in := ty.In(i) | |
| 31 | - | if !in.AssignableTo(reflect.TypeOf(CDecl{})) { | |
| 31 | + | if !in.AssignableTo(reflect.TypeFor[CDecl]()) { | |
| 32 | 32 | continue | |
| 33 | 33 | } | |
| 34 | 34 | if i != 0 { | |
| @@ -28,7 +28,7 @@ func NewCallback(fn any) uintptr { | |||||
| 28 | ty := reflect.TypeOf(fn) | 28 | ty := reflect.TypeOf(fn) | ||
| 29 | for i := range ty.NumIn() { | 29 | for i := range ty.NumIn() { | ||
| 30 | in := ty.In(i) | 30 | in := ty.In(i) | ||
| 31 | - | if !in.AssignableTo(reflect.TypeOf(CDecl{})) { | 31 | + | if !in.AssignableTo(reflect.TypeFor[CDecl]()) { |
| 32 | continue | 32 | continue | ||
| 33 | } | 33 | } | ||
| 34 | if i != 0 { | 34 | if i != 0 { | ||