mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: use slices.ContainsFunc
Now that Go 1.22.6 is the minimum bootstrap toolchain (cf. CL 606156), the slices package (introduced in Go 1.21) can be used in packages built using the bootstrap toolchain. For #64751 Change-Id: Ib36f39016f57c5e110f78a85ca9c806d91356024 Reviewed-on: https://go-review.googlesource.com/c/go/+/612316 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
ad6ee21bbf
commit
9deda35ff8
1 changed files with 13 additions and 21 deletions
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
@ -781,17 +782,14 @@ func (p *Package) mangleName(n *Name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *File) isMangledName(s string) bool {
|
func (f *File) isMangledName(s string) bool {
|
||||||
prefix := "_C"
|
t, ok := strings.CutPrefix(s, "_C")
|
||||||
if strings.HasPrefix(s, prefix) {
|
if !ok {
|
||||||
t := s[len(prefix):]
|
|
||||||
for _, k := range nameKinds {
|
|
||||||
if strings.HasPrefix(t, k+"_") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
return slices.ContainsFunc(nameKinds, func(k string) bool {
|
||||||
|
return strings.HasPrefix(t, k+"_")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// rewriteCalls rewrites all calls that pass pointers to check that
|
// rewriteCalls rewrites all calls that pass pointers to check that
|
||||||
// they follow the rules for passing pointers between Go and C.
|
// they follow the rules for passing pointers between Go and C.
|
||||||
|
|
@ -1050,12 +1048,9 @@ func (p *Package) hasPointer(f *File, t ast.Expr, top bool) bool {
|
||||||
}
|
}
|
||||||
return p.hasPointer(f, t.Elt, top)
|
return p.hasPointer(f, t.Elt, top)
|
||||||
case *ast.StructType:
|
case *ast.StructType:
|
||||||
for _, field := range t.Fields.List {
|
return slices.ContainsFunc(t.Fields.List, func(field *ast.Field) bool {
|
||||||
if p.hasPointer(f, field.Type, top) {
|
return p.hasPointer(f, field.Type, top)
|
||||||
return true
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
case *ast.StarExpr: // Pointer type.
|
case *ast.StarExpr: // Pointer type.
|
||||||
if !top {
|
if !top {
|
||||||
return true
|
return true
|
||||||
|
|
@ -3202,12 +3197,9 @@ func (c *typeConv) dwarfHasPointer(dt dwarf.Type, pos token.Pos) bool {
|
||||||
return c.dwarfHasPointer(dt.Type, pos)
|
return c.dwarfHasPointer(dt.Type, pos)
|
||||||
|
|
||||||
case *dwarf.StructType:
|
case *dwarf.StructType:
|
||||||
for _, f := range dt.Field {
|
return slices.ContainsFunc(dt.Field, func(f *dwarf.StructField) bool {
|
||||||
if c.dwarfHasPointer(f.Type, pos) {
|
return c.dwarfHasPointer(f.Type, pos)
|
||||||
return true
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
|
|
||||||
case *dwarf.TypedefType:
|
case *dwarf.TypedefType:
|
||||||
if dt.Name == "_GoString_" || dt.Name == "_GoBytes_" {
|
if dt.Name == "_GoString_" || dt.Name == "_GoBytes_" {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue