detached 63002e0

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 UnverifiedB5690EEEBB952194 The 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 (
1010 "os"
1111 "path/filepath"
1212 "runtime"
13- "sort"
13+ "slices"
1414 "strings"
1515 "syscall"
1616 "testing"
@@ -119,8 +119,8 @@ func compareStatus(filter, expect string) error {
119119 // "... : bad file descriptor.
120120 continue
121121 }
122- lines := strings.Split(string(d), "\n")
123- for _, line := range lines {
122+ lines := strings.SplitSeq(string(d), "\n")
123+ for line := range lines {
124124 // Different kernel vintages pad differently.
125125 line = strings.TrimSpace(line)
126126 if strings.HasPrefix(line, "Pid:\t") {
@@ -149,7 +149,7 @@ func compareStatus(filter, expect string) error {
149149 // https://github.com/golang/go/issues/46145
150150 // Containers don't reliably output this line in sorted order so manually sort and compare that.
151151 a := strings.Split(line[8:], " ")
152- sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
152+ slices.Sort(a)
153153 got := strings.Join(a, " ")
154154 if got == expected[8:] {
155155 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 continue120 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/46145149 // 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 = true155 foundAThread = true
M syscall_windows.go +1 -1
@@ -28,7 +28,7 @@ func NewCallback(fn any) uintptr {
2828 ty := reflect.TypeOf(fn)
2929 for i := range ty.NumIn() {
3030 in := ty.In(i)
31- if !in.AssignableTo(reflect.TypeOf(CDecl{})) {
31+ if !in.AssignableTo(reflect.TypeFor[CDecl]()) {
3232 continue
3333 }
3434 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 continue32 continue
33 }33 }
34 if i != 0 {34 if i != 0 {

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close