From 49c1da474d68045458b9462b743e3f0f7dcefdfb Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 28 Oct 2025 21:54:33 -0400 Subject: [PATCH] internal/itoa, internal/runtime/strconv: delete Replaced by internal/strconv. Change-Id: I0656a9ad5075e60339e963fbae7d194d2f3e16be Reviewed-on: https://go-review.googlesource.com/c/go/+/716001 Reviewed-by: David Chase LUCI-TryBot-Result: Go LUCI --- src/cmd/internal/objabi/pkgspecial.go | 2 +- src/go/build/deps_test.go | 4 +- src/internal/coverage/pkid.go | 2 +- src/internal/itoa/itoa.go | 57 ----------- src/internal/itoa/itoa_test.go | 51 ---------- src/internal/poll/fd_io_plan9.go | 4 +- src/internal/poll/fd_unix.go | 4 +- src/internal/runtime/cgroup/cgroup_linux.go | 14 +-- src/internal/runtime/strconv/atoi.go | 75 -------------- src/internal/runtime/strconv/atoi_test.go | 104 -------------------- src/net/dnsclient.go | 4 +- src/net/dnsclient_unix.go | 4 +- src/net/interface.go | 4 +- src/net/interface_plan9.go | 6 +- src/net/ip.go | 4 +- src/net/ipsock_plan9.go | 7 +- src/net/lookup_plan9.go | 4 +- src/net/netip/netip.go | 7 +- src/net/tcpsock.go | 6 +- src/net/tcpsockopt_plan9.go | 4 +- src/net/udpsock.go | 6 +- src/os/exec_plan9.go | 4 +- src/os/exec_posix.go | 8 +- src/os/executable_plan9.go | 4 +- src/os/signal/signal_plan9_test.go | 4 +- src/os/tempfile.go | 4 +- src/reflect/value.go | 6 +- src/runtime/mgcpacer.go | 6 +- src/runtime/os_linux.go | 6 +- src/runtime/proc.go | 6 +- src/runtime/runtime1.go | 12 +-- src/runtime/string.go | 18 ++-- src/syscall/exec_linux.go | 10 +- src/syscall/exec_plan9.go | 4 +- src/syscall/syscall_js.go | 6 +- src/syscall/syscall_linux.go | 4 +- src/syscall/syscall_unix.go | 6 +- src/syscall/syscall_wasip1.go | 6 +- src/syscall/syscall_windows.go | 6 +- src/time/zoneinfo_js.go | 6 +- 40 files changed, 104 insertions(+), 395 deletions(-) delete mode 100644 src/internal/itoa/itoa.go delete mode 100644 src/internal/itoa/itoa_test.go delete mode 100644 src/internal/runtime/strconv/atoi.go delete mode 100644 src/internal/runtime/strconv/atoi_test.go diff --git a/src/cmd/internal/objabi/pkgspecial.go b/src/cmd/internal/objabi/pkgspecial.go index 94efa6883b..bf30f0cc7f 100644 --- a/src/cmd/internal/objabi/pkgspecial.go +++ b/src/cmd/internal/objabi/pkgspecial.go @@ -55,7 +55,6 @@ var runtimePkgs = []string{ "internal/runtime/gc/scan", "internal/runtime/maps", "internal/runtime/math", - "internal/runtime/strconv", "internal/runtime/sys", "internal/runtime/syscall/linux", "internal/runtime/syscall/windows", @@ -71,6 +70,7 @@ var runtimePkgs = []string{ "internal/goexperiment", "internal/goos", "internal/profilerecord", + "internal/strconv", "internal/stringslite", } diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index 10b27cfe92..bc7eae69de 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -87,7 +87,6 @@ var depsRules = ` structs < internal/bytealg < internal/stringslite - < internal/itoa < internal/unsafeheader < internal/race < internal/msan @@ -100,7 +99,6 @@ var depsRules = ` < internal/runtime/gc < internal/runtime/math < internal/runtime/maps - < internal/runtime/strconv < internal/runtime/cgroup < internal/runtime/gc/scan < runtime @@ -301,7 +299,7 @@ var depsRules = ` FMT < text/template/parse; - internal/bytealg, internal/itoa, math/bits, slices, strconv, unique + internal/bytealg, math/bits, slices, strconv, unique < net/netip; FMT, net/netip diff --git a/src/internal/coverage/pkid.go b/src/internal/coverage/pkid.go index 09501e6bd2..213a1ecfd1 100644 --- a/src/internal/coverage/pkid.go +++ b/src/internal/coverage/pkid.go @@ -63,12 +63,12 @@ var rtPkgs = [...]string{ "internal/runtime/exithook", "internal/runtime/gc", "internal/runtime/math", - "internal/runtime/strconv", "internal/runtime/sys", "internal/runtime/maps", "internal/runtime/syscall/linux", "internal/runtime/syscall/windows", "internal/runtime/cgroup", + "internal/strconv", "internal/stringslite", "runtime", } diff --git a/src/internal/itoa/itoa.go b/src/internal/itoa/itoa.go deleted file mode 100644 index 4340ae0e2d..0000000000 --- a/src/internal/itoa/itoa.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2021 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Simple conversions to avoid depending on strconv. - -package itoa - -// Itoa converts val to a decimal string. -func Itoa(val int) string { - if val < 0 { - return "-" + Uitoa(uint(-val)) - } - return Uitoa(uint(val)) -} - -// Uitoa converts val to a decimal string. -func Uitoa(val uint) string { - if val == 0 { // avoid string allocation - return "0" - } - var buf [20]byte // big enough for 64bit value base 10 - i := len(buf) - 1 - for val >= 10 { - q := val / 10 - buf[i] = byte('0' + val - q*10) - i-- - val = q - } - // val < 10 - buf[i] = byte('0' + val) - return string(buf[i:]) -} - -const hex = "0123456789abcdef" - -// Uitox converts val (a uint) to a hexadecimal string. -func Uitox(val uint) string { - if val == 0 { // avoid string allocation - return "0x0" - } - var buf [20]byte // big enough for 64bit value base 16 + 0x - i := len(buf) - 1 - for val >= 16 { - q := val / 16 - buf[i] = hex[val%16] - i-- - val = q - } - // val < 16 - buf[i] = hex[val%16] - i-- - buf[i] = 'x' - i-- - buf[i] = '0' - return string(buf[i:]) -} diff --git a/src/internal/itoa/itoa_test.go b/src/internal/itoa/itoa_test.go deleted file mode 100644 index 8bed888532..0000000000 --- a/src/internal/itoa/itoa_test.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2021 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package itoa_test - -import ( - "fmt" - "internal/itoa" - "math" - "testing" -) - -var ( - minInt64 int64 = math.MinInt64 - maxInt64 int64 = math.MaxInt64 - maxUint64 uint64 = math.MaxUint64 -) - -func TestItoa(t *testing.T) { - tests := []int{int(minInt64), math.MinInt32, -999, -100, -1, 0, 1, 100, 999, math.MaxInt32, int(maxInt64)} - for _, tt := range tests { - got := itoa.Itoa(tt) - want := fmt.Sprint(tt) - if want != got { - t.Fatalf("Itoa(%d) = %s, want %s", tt, got, want) - } - } -} - -func TestUitoa(t *testing.T) { - tests := []uint{0, 1, 100, 999, math.MaxUint32, uint(maxUint64)} - for _, tt := range tests { - got := itoa.Uitoa(tt) - want := fmt.Sprint(tt) - if want != got { - t.Fatalf("Uitoa(%d) = %s, want %s", tt, got, want) - } - } -} - -func TestUitox(t *testing.T) { - tests := []uint{0, 1, 15, 100, 999, math.MaxUint32, uint(maxUint64)} - for _, tt := range tests { - got := itoa.Uitox(tt) - want := fmt.Sprintf("%#x", tt) - if want != got { - t.Fatalf("Uitox(%x) = %s, want %s", tt, got, want) - } - } -} diff --git a/src/internal/poll/fd_io_plan9.go b/src/internal/poll/fd_io_plan9.go index 3205ac8513..ab9ae13eb4 100644 --- a/src/internal/poll/fd_io_plan9.go +++ b/src/internal/poll/fd_io_plan9.go @@ -5,7 +5,7 @@ package poll import ( - "internal/itoa" + "internal/strconv" "runtime" "sync" "syscall" @@ -72,7 +72,7 @@ func (aio *asyncIO) Cancel() { if aio.pid == -1 { return } - f, e := syscall.Open("/proc/"+itoa.Itoa(aio.pid)+"/note", syscall.O_WRONLY) + f, e := syscall.Open("/proc/"+strconv.Itoa(aio.pid)+"/note", syscall.O_WRONLY) if e != nil { return } diff --git a/src/internal/poll/fd_unix.go b/src/internal/poll/fd_unix.go index 31e6e21120..f56173524d 100644 --- a/src/internal/poll/fd_unix.go +++ b/src/internal/poll/fd_unix.go @@ -7,7 +7,7 @@ package poll import ( - "internal/itoa" + "internal/strconv" "internal/syscall/unix" "io" "sync/atomic" @@ -379,7 +379,7 @@ func (fd *FD) Write(p []byte) (int, error) { // If we don't check this we will panic // with slice bounds out of range. // Use a more informative panic. - panic("invalid return from write: got " + itoa.Itoa(n) + " from a write of " + itoa.Itoa(max-nn)) + panic("invalid return from write: got " + strconv.Itoa(n) + " from a write of " + strconv.Itoa(max-nn)) } nn += n } diff --git a/src/internal/runtime/cgroup/cgroup_linux.go b/src/internal/runtime/cgroup/cgroup_linux.go index 91815b4a1d..7b35a9bc18 100644 --- a/src/internal/runtime/cgroup/cgroup_linux.go +++ b/src/internal/runtime/cgroup/cgroup_linux.go @@ -6,8 +6,8 @@ package cgroup import ( "internal/bytealg" - "internal/runtime/strconv" "internal/runtime/syscall/linux" + "internal/strconv" ) var ( @@ -220,8 +220,8 @@ func parseV1Number(buf []byte) (int64, error) { } buf = buf[:i] - val, ok := strconv.Atoi64(string(buf)) - if !ok { + val, err := strconv.ParseInt(string(buf), 10, 64) + if err != nil { return 0, errMalformedFile } @@ -280,13 +280,13 @@ func parseV2Limit(buf []byte) (float64, bool, error) { } periodStr = periodStr[:i] - quota, ok := strconv.Atoi64(string(quotaStr)) - if !ok { + quota, err := strconv.ParseInt(string(quotaStr), 10, 64) + if err != nil { return 0, false, errMalformedFile } - period, ok := strconv.Atoi64(string(periodStr)) - if !ok { + period, err := strconv.ParseInt(string(periodStr), 10, 64) + if err != nil { return 0, false, errMalformedFile } diff --git a/src/internal/runtime/strconv/atoi.go b/src/internal/runtime/strconv/atoi.go deleted file mode 100644 index 0308757c6f..0000000000 --- a/src/internal/runtime/strconv/atoi.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2025 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package strconv - -import ( - "internal/runtime/math" -) - -// Atoi64 parses an int64 from a string s. -// The bool result reports whether s is a number -// representable by a value of type int64. -func Atoi64(s string) (int64, bool) { - if s == "" { - return 0, false - } - - neg := false - if s[0] == '-' { - neg = true - s = s[1:] - } - - un := uint64(0) - for i := 0; i < len(s); i++ { - c := s[i] - if c < '0' || c > '9' { - return 0, false - } - if un > math.MaxUint64/10 { - // overflow - return 0, false - } - un *= 10 - un1 := un + uint64(c) - '0' - if un1 < un { - // overflow - return 0, false - } - un = un1 - } - - if !neg && un > uint64(math.MaxInt64) { - return 0, false - } - if neg && un > uint64(math.MaxInt64)+1 { - return 0, false - } - - n := int64(un) - if neg { - n = -n - } - - return n, true -} - -// Atoi is like Atoi64 but for integers -// that fit into an int. -func Atoi(s string) (int, bool) { - if n, ok := Atoi64(s); n == int64(int(n)) { - return int(n), ok - } - return 0, false -} - -// Atoi32 is like Atoi but for integers -// that fit into an int32. -func Atoi32(s string) (int32, bool) { - if n, ok := Atoi64(s); n == int64(int32(n)) { - return int32(n), ok - } - return 0, false -} diff --git a/src/internal/runtime/strconv/atoi_test.go b/src/internal/runtime/strconv/atoi_test.go deleted file mode 100644 index 71a8030b1d..0000000000 --- a/src/internal/runtime/strconv/atoi_test.go +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2025 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package strconv_test - -import ( - "internal/runtime/strconv" - "testing" -) - -const intSize = 32 << (^uint(0) >> 63) - -type atoi64Test struct { - in string - out int64 - ok bool -} - -var atoi64tests = []atoi64Test{ - {"", 0, false}, - {"0", 0, true}, - {"-0", 0, true}, - {"1", 1, true}, - {"-1", -1, true}, - {"12345", 12345, true}, - {"-12345", -12345, true}, - {"012345", 12345, true}, - {"-012345", -12345, true}, - {"12345x", 0, false}, - {"-12345x", 0, false}, - {"98765432100", 98765432100, true}, - {"-98765432100", -98765432100, true}, - {"20496382327982653440", 0, false}, - {"-20496382327982653440", 0, false}, - {"9223372036854775807", 1<<63 - 1, true}, - {"-9223372036854775807", -(1<<63 - 1), true}, - {"9223372036854775808", 0, false}, - {"-9223372036854775808", -1 << 63, true}, - {"9223372036854775809", 0, false}, - {"-9223372036854775809", 0, false}, -} - -func TestAtoi(t *testing.T) { - switch intSize { - case 32: - for i := range atoi32tests { - test := &atoi32tests[i] - out, ok := strconv.Atoi(test.in) - if test.out != int32(out) || test.ok != ok { - t.Errorf("Atoi(%q) = (%v, %v) want (%v, %v)", - test.in, out, ok, test.out, test.ok) - } - } - case 64: - for i := range atoi64tests { - test := &atoi64tests[i] - out, ok := strconv.Atoi(test.in) - if test.out != int64(out) || test.ok != ok { - t.Errorf("Atoi(%q) = (%v, %v) want (%v, %v)", - test.in, out, ok, test.out, test.ok) - } - } - } -} - -type atoi32Test struct { - in string - out int32 - ok bool -} - -var atoi32tests = []atoi32Test{ - {"", 0, false}, - {"0", 0, true}, - {"-0", 0, true}, - {"1", 1, true}, - {"-1", -1, true}, - {"12345", 12345, true}, - {"-12345", -12345, true}, - {"012345", 12345, true}, - {"-012345", -12345, true}, - {"12345x", 0, false}, - {"-12345x", 0, false}, - {"987654321", 987654321, true}, - {"-987654321", -987654321, true}, - {"2147483647", 1<<31 - 1, true}, - {"-2147483647", -(1<<31 - 1), true}, - {"2147483648", 0, false}, - {"-2147483648", -1 << 31, true}, - {"2147483649", 0, false}, - {"-2147483649", 0, false}, -} - -func TestAtoi32(t *testing.T) { - for i := range atoi32tests { - test := &atoi32tests[i] - out, ok := strconv.Atoi32(test.in) - if test.out != out || test.ok != ok { - t.Errorf("Atoi32(%q) = (%v, %v) want (%v, %v)", - test.in, out, ok, test.out, test.ok) - } - } -} diff --git a/src/net/dnsclient.go b/src/net/dnsclient.go index 5f135cc211..eb509d175f 100644 --- a/src/net/dnsclient.go +++ b/src/net/dnsclient.go @@ -7,7 +7,7 @@ package net import ( "cmp" "internal/bytealg" - "internal/itoa" + "internal/strconv" "slices" _ "unsafe" // for go:linkname @@ -36,7 +36,7 @@ func reverseaddr(addr string) (arpa string, err error) { return "", &DNSError{Err: "unrecognized address", Name: addr} } if ip.To4() != nil { - return itoa.Uitoa(uint(ip[15])) + "." + itoa.Uitoa(uint(ip[14])) + "." + itoa.Uitoa(uint(ip[13])) + "." + itoa.Uitoa(uint(ip[12])) + ".in-addr.arpa.", nil + return strconv.Itoa(int(ip[15])) + "." + strconv.Itoa(int(ip[14])) + "." + strconv.Itoa(int(ip[13])) + "." + strconv.Itoa(int(ip[12])) + ".in-addr.arpa.", nil } // Must be IPv6 buf := make([]byte, 0, len(ip)*4+len("ip6.arpa.")) diff --git a/src/net/dnsclient_unix.go b/src/net/dnsclient_unix.go index 940fcccf7f..40f7606294 100644 --- a/src/net/dnsclient_unix.go +++ b/src/net/dnsclient_unix.go @@ -17,7 +17,7 @@ import ( "errors" "internal/bytealg" "internal/godebug" - "internal/itoa" + "internal/strconv" "internal/stringslite" "io" "os" @@ -559,7 +559,7 @@ func (o hostLookupOrder) String() string { if s, ok := lookupOrderName[o]; ok { return s } - return "hostLookupOrder=" + itoa.Itoa(int(o)) + "??" + return "hostLookupOrder=" + strconv.Itoa(int(o)) + "??" } func (r *Resolver) goLookupHostOrder(ctx context.Context, name string, order hostLookupOrder, conf *dnsConfig) (addrs []string, err error) { diff --git a/src/net/interface.go b/src/net/interface.go index b6057780c4..5ae3a3a149 100644 --- a/src/net/interface.go +++ b/src/net/interface.go @@ -6,7 +6,7 @@ package net import ( "errors" - "internal/itoa" + "internal/strconv" "sync" "time" _ "unsafe" @@ -246,7 +246,7 @@ func (zc *ipv6ZoneCache) name(index int) string { zoneCache.RUnlock() } if !ok { // last resort - name = itoa.Uitoa(uint(index)) + name = strconv.Itoa(index) } return name } diff --git a/src/net/interface_plan9.go b/src/net/interface_plan9.go index 93c783b56e..88f1325ab2 100644 --- a/src/net/interface_plan9.go +++ b/src/net/interface_plan9.go @@ -6,7 +6,7 @@ package net import ( "errors" - "internal/itoa" + "internal/strconv" "internal/stringslite" "os" ) @@ -40,8 +40,8 @@ func interfaceTable(ifindex int) ([]Interface, error) { func readInterface(i int) (*Interface, error) { ifc := &Interface{ - Index: i + 1, // Offset the index by one to suit the contract - Name: netdir + "/ipifc/" + itoa.Itoa(i), // Name is the full path to the interface path in plan9 + Index: i + 1, // Offset the index by one to suit the contract + Name: netdir + "/ipifc/" + strconv.Itoa(i), // Name is the full path to the interface path in plan9 } ifcstat := ifc.Name + "/status" diff --git a/src/net/ip.go b/src/net/ip.go index e3ee6ca70a..7d58e89e11 100644 --- a/src/net/ip.go +++ b/src/net/ip.go @@ -14,7 +14,7 @@ package net import ( "internal/bytealg" - "internal/itoa" + "internal/strconv" "internal/stringslite" "net/netip" ) @@ -515,7 +515,7 @@ func (n *IPNet) String() string { if l == -1 { return nn.String() + "/" + m.String() } - return nn.String() + "/" + itoa.Uitoa(uint(l)) + return nn.String() + "/" + strconv.Itoa(l) } // ParseIP parses s as an IP address, returning the result. diff --git a/src/net/ipsock_plan9.go b/src/net/ipsock_plan9.go index 6ae9cf3cc1..2bd5071d56 100644 --- a/src/net/ipsock_plan9.go +++ b/src/net/ipsock_plan9.go @@ -7,10 +7,9 @@ package net import ( "context" "internal/bytealg" - "internal/itoa" + "internal/strconv" "io/fs" "os" - "strconv" "syscall" ) @@ -338,9 +337,9 @@ func plan9LocalAddr(addr Addr) string { if port == 0 { return "" } - return itoa.Itoa(port) + return strconv.Itoa(port) } - return ip.String() + "!" + itoa.Itoa(port) + return ip.String() + "!" + strconv.Itoa(port) } func hangupCtlWrite(ctx context.Context, proto string, ctl *os.File, msg string) error { diff --git a/src/net/lookup_plan9.go b/src/net/lookup_plan9.go index c9bab29ade..836beb3b17 100644 --- a/src/net/lookup_plan9.go +++ b/src/net/lookup_plan9.go @@ -8,7 +8,7 @@ import ( "context" "errors" "internal/bytealg" - "internal/itoa" + "internal/strconv" "internal/stringslite" "io" "os" @@ -87,7 +87,7 @@ func queryCS1(ctx context.Context, net string, ip IP, port int) (clone, dest str if len(ip) != 0 && !ip.IsUnspecified() { ips = ip.String() } - lines, err := queryCS(ctx, net, ips, itoa.Itoa(port)) + lines, err := queryCS(ctx, net, ips, strconv.Itoa(port)) if err != nil { return } diff --git a/src/net/netip/netip.go b/src/net/netip/netip.go index b1b15b4728..10882db6a4 100644 --- a/src/net/netip/netip.go +++ b/src/net/netip/netip.go @@ -16,7 +16,6 @@ import ( "errors" "internal/bytealg" "internal/byteorder" - "internal/itoa" "math" "strconv" "unique" @@ -684,12 +683,12 @@ func (ip Addr) Prefix(b int) (Prefix, error) { return Prefix{}, nil case z4: if b > 32 { - return Prefix{}, errors.New("prefix length " + itoa.Itoa(b) + " too large for IPv4") + return Prefix{}, errors.New("prefix length " + strconv.Itoa(b) + " too large for IPv4") } effectiveBits += 96 default: if b > 128 { - return Prefix{}, errors.New("prefix length " + itoa.Itoa(b) + " too large for IPv6") + return Prefix{}, errors.New("prefix length " + strconv.Itoa(b) + " too large for IPv6") } } ip.addr = ip.addr.and(mask6(effectiveBits)) @@ -1593,5 +1592,5 @@ func (p Prefix) String() string { if !p.IsValid() { return "invalid Prefix" } - return p.ip.String() + "/" + itoa.Itoa(p.Bits()) + return p.ip.String() + "/" + strconv.Itoa(p.Bits()) } diff --git a/src/net/tcpsock.go b/src/net/tcpsock.go index 376bf238c7..35eda25ead 100644 --- a/src/net/tcpsock.go +++ b/src/net/tcpsock.go @@ -6,7 +6,7 @@ package net import ( "context" - "internal/itoa" + "internal/strconv" "io" "net/netip" "os" @@ -47,9 +47,9 @@ func (a *TCPAddr) String() string { } ip := ipEmptyString(a.IP) if a.Zone != "" { - return JoinHostPort(ip+"%"+a.Zone, itoa.Itoa(a.Port)) + return JoinHostPort(ip+"%"+a.Zone, strconv.Itoa(a.Port)) } - return JoinHostPort(ip, itoa.Itoa(a.Port)) + return JoinHostPort(ip, strconv.Itoa(a.Port)) } func (a *TCPAddr) isWildcard() bool { diff --git a/src/net/tcpsockopt_plan9.go b/src/net/tcpsockopt_plan9.go index 017e87518a..4c7958b8bd 100644 --- a/src/net/tcpsockopt_plan9.go +++ b/src/net/tcpsockopt_plan9.go @@ -7,7 +7,7 @@ package net import ( - "internal/itoa" + "internal/strconv" "syscall" "time" ) @@ -22,7 +22,7 @@ func setKeepAliveIdle(fd *netFD, d time.Duration) error { return nil } - cmd := "keepalive " + itoa.Itoa(int(d/time.Millisecond)) + cmd := "keepalive " + strconv.Itoa(int(d/time.Millisecond)) _, e := fd.ctl.WriteAt([]byte(cmd), 0) return e } diff --git a/src/net/udpsock.go b/src/net/udpsock.go index f9a3bee867..fcd6a06568 100644 --- a/src/net/udpsock.go +++ b/src/net/udpsock.go @@ -6,7 +6,7 @@ package net import ( "context" - "internal/itoa" + "internal/strconv" "net/netip" "syscall" ) @@ -47,9 +47,9 @@ func (a *UDPAddr) String() string { } ip := ipEmptyString(a.IP) if a.Zone != "" { - return JoinHostPort(ip+"%"+a.Zone, itoa.Itoa(a.Port)) + return JoinHostPort(ip+"%"+a.Zone, strconv.Itoa(a.Port)) } - return JoinHostPort(ip, itoa.Itoa(a.Port)) + return JoinHostPort(ip, strconv.Itoa(a.Port)) } func (a *UDPAddr) isWildcard() bool { diff --git a/src/os/exec_plan9.go b/src/os/exec_plan9.go index a3d363b344..7d50ab2628 100644 --- a/src/os/exec_plan9.go +++ b/src/os/exec_plan9.go @@ -5,7 +5,7 @@ package os import ( - "internal/itoa" + "internal/strconv" "syscall" "time" ) @@ -40,7 +40,7 @@ func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e } func (p *Process) writeProcFile(file string, data string) error { - f, e := OpenFile("/proc/"+itoa.Itoa(p.Pid)+"/"+file, O_WRONLY, 0) + f, e := OpenFile("/proc/"+strconv.Itoa(p.Pid)+"/"+file, O_WRONLY, 0) if e != nil { return e } diff --git a/src/os/exec_posix.go b/src/os/exec_posix.go index 6b6977ab78..9f83db1555 100644 --- a/src/os/exec_posix.go +++ b/src/os/exec_posix.go @@ -7,7 +7,7 @@ package os import ( - "internal/itoa" + "internal/strconv" "internal/syscall/execenv" "runtime" "syscall" @@ -132,16 +132,16 @@ func (p *ProcessState) String() string { case status.Exited(): code := status.ExitStatus() if runtime.GOOS == "windows" && uint(code) >= 1<<16 { // windows uses large hex numbers - res = "exit status " + itoa.Uitox(uint(code)) + res = "exit status 0x" + strconv.FormatUint(uint64(code), 16) } else { // unix systems use small decimal integers - res = "exit status " + itoa.Itoa(code) // unix + res = "exit status " + strconv.Itoa(code) // unix } case status.Signaled(): res = "signal: " + status.Signal().String() case status.Stopped(): res = "stop signal: " + status.StopSignal().String() if status.StopSignal() == syscall.SIGTRAP && status.TrapCause() != 0 { - res += " (trap " + itoa.Itoa(status.TrapCause()) + ")" + res += " (trap " + strconv.Itoa(status.TrapCause()) + ")" } case status.Continued(): res = "continued" diff --git a/src/os/executable_plan9.go b/src/os/executable_plan9.go index 8d8c83260f..fcb269665b 100644 --- a/src/os/executable_plan9.go +++ b/src/os/executable_plan9.go @@ -7,12 +7,12 @@ package os import ( - "internal/itoa" + "internal/strconv" "syscall" ) func executable() (string, error) { - fn := "/proc/" + itoa.Itoa(Getpid()) + "/text" + fn := "/proc/" + strconv.Itoa(Getpid()) + "/text" f, err := Open(fn) if err != nil { return "", err diff --git a/src/os/signal/signal_plan9_test.go b/src/os/signal/signal_plan9_test.go index 8357199aa4..1d76cfcaaa 100644 --- a/src/os/signal/signal_plan9_test.go +++ b/src/os/signal/signal_plan9_test.go @@ -5,7 +5,7 @@ package signal import ( - "internal/itoa" + "internal/strconv" "os" "runtime" "syscall" @@ -157,7 +157,7 @@ func TestStop(t *testing.T) { } func postNote(pid int, note string) error { - f, err := os.OpenFile("/proc/"+itoa.Itoa(pid)+"/note", os.O_WRONLY, 0) + f, err := os.OpenFile("/proc/"+strconv.Itoa(pid)+"/note", os.O_WRONLY, 0) if err != nil { return err } diff --git a/src/os/tempfile.go b/src/os/tempfile.go index 428dc965b7..085423805f 100644 --- a/src/os/tempfile.go +++ b/src/os/tempfile.go @@ -7,7 +7,7 @@ package os import ( "errors" "internal/bytealg" - "internal/itoa" + "internal/strconv" _ "unsafe" // for go:linkname ) @@ -20,7 +20,7 @@ import ( func runtime_rand() uint64 func nextRandom() string { - return itoa.Uitoa(uint(uint32(runtime_rand()))) + return strconv.FormatUint(uint64(uint32(runtime_rand())), 10) } // CreateTemp creates a new temporary file in the directory dir, diff --git a/src/reflect/value.go b/src/reflect/value.go index c0ac45de77..b5d5aa8bf2 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -8,7 +8,7 @@ import ( "errors" "internal/abi" "internal/goarch" - "internal/itoa" + "internal/strconv" "internal/unsafeheader" "math" "runtime" @@ -3573,7 +3573,7 @@ func cvtStringRunes(v Value, t Type) Value { func cvtSliceArrayPtr(v Value, t Type) Value { n := t.Elem().Len() if n > v.Len() { - panic("reflect: cannot convert slice with length " + itoa.Itoa(v.Len()) + " to pointer to array with length " + itoa.Itoa(n)) + panic("reflect: cannot convert slice with length " + strconv.Itoa(v.Len()) + " to pointer to array with length " + strconv.Itoa(n)) } h := (*unsafeheader.Slice)(v.ptr) return Value{t.common(), h.Data, v.flag&^(flagIndir|flagAddr|flagKindMask) | flag(Pointer)} @@ -3583,7 +3583,7 @@ func cvtSliceArrayPtr(v Value, t Type) Value { func cvtSliceArray(v Value, t Type) Value { n := t.Len() if n > v.Len() { - panic("reflect: cannot convert slice with length " + itoa.Itoa(v.Len()) + " to array with length " + itoa.Itoa(n)) + panic("reflect: cannot convert slice with length " + strconv.Itoa(v.Len()) + " to array with length " + strconv.Itoa(n)) } h := (*unsafeheader.Slice)(v.ptr) typ := t.common() diff --git a/src/runtime/mgcpacer.go b/src/runtime/mgcpacer.go index 17e2f405e4..bd454b5cea 100644 --- a/src/runtime/mgcpacer.go +++ b/src/runtime/mgcpacer.go @@ -9,7 +9,7 @@ import ( "internal/goexperiment" "internal/runtime/atomic" "internal/runtime/math" - "internal/runtime/strconv" + "internal/strconv" _ "unsafe" // for go:linkname ) @@ -1313,8 +1313,8 @@ func readGOGC() int32 { if p == "off" { return -1 } - if n, ok := strconv.Atoi32(p); ok { - return n + if n, err := strconv.ParseInt(p, 10, 32); err == nil { + return int32(n) } return 100 } diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go index 1b7d5731cc..7e6af22d48 100644 --- a/src/runtime/os_linux.go +++ b/src/runtime/os_linux.go @@ -8,8 +8,8 @@ import ( "internal/abi" "internal/goarch" "internal/runtime/atomic" - "internal/runtime/strconv" "internal/runtime/syscall/linux" + "internal/strconv" "unsafe" ) @@ -339,8 +339,8 @@ func getHugePageSize() uintptr { return 0 } n-- // remove trailing newline - v, ok := strconv.Atoi(slicebytetostringtmp((*byte)(ptr), int(n))) - if !ok || v < 0 { + v, err := strconv.Atoi(slicebytetostringtmp((*byte)(ptr), int(n))) + if err != nil || v < 0 { v = 0 } if v&(v-1) != 0 { diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 36949fb2cf..6c16effc95 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -11,8 +11,8 @@ import ( "internal/goos" "internal/runtime/atomic" "internal/runtime/exithook" - "internal/runtime/strconv" "internal/runtime/sys" + "internal/strconv" "internal/stringslite" "unsafe" ) @@ -918,8 +918,8 @@ func schedinit() { lock(&sched.lock) sched.lastpoll.Store(nanotime()) var procs int32 - if n, ok := strconv.Atoi32(gogetenv("GOMAXPROCS")); ok && n > 0 { - procs = n + if n, err := strconv.ParseInt(gogetenv("GOMAXPROCS"), 10, 32); err == nil && n > 0 { + procs = int32(n) sched.customGOMAXPROCS = true } else { // Use numCPUStartup for initial GOMAXPROCS for two reasons: diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go index 15b546783b..3ec5c44ebd 100644 --- a/src/runtime/runtime1.go +++ b/src/runtime/runtime1.go @@ -8,7 +8,7 @@ import ( "internal/bytealg" "internal/goarch" "internal/runtime/atomic" - "internal/runtime/strconv" + "internal/strconv" "unsafe" ) @@ -532,17 +532,17 @@ func parsegodebug(godebug string, seen map[string]bool) { // is int, not int32, and should only be updated // if specified in GODEBUG. if seen == nil && key == "memprofilerate" { - if n, ok := strconv.Atoi(value); ok { + if n, err := strconv.Atoi(value); err == nil { MemProfileRate = n } } else { for _, v := range dbgvars { if v.name == key { - if n, ok := strconv.Atoi32(value); ok { + if n, err := strconv.ParseInt(value, 10, 32); err == nil { if seen == nil && v.value != nil { - *v.value = n + *v.value = int32(n) } else if v.atomic != nil { - v.atomic.Store(n) + v.atomic.Store(int32(n)) } } } @@ -578,7 +578,7 @@ func setTraceback(level string) { fallthrough default: t = tracebackAll - if n, ok := strconv.Atoi(level); ok && n == int(uint32(n)) { + if n, err := strconv.Atoi(level); err == nil && n == int(uint32(n)) { t |= uint32(n) << tracebackShift } } diff --git a/src/runtime/string.go b/src/runtime/string.go index 3726d9235b..15b3868cbc 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -9,8 +9,8 @@ import ( "internal/bytealg" "internal/goarch" "internal/runtime/math" - "internal/runtime/strconv" "internal/runtime/sys" + "internal/strconv" "unsafe" ) @@ -420,11 +420,11 @@ func parseByteCount(s string) (int64, bool) { // Handle the easy non-suffix case. last := s[len(s)-1] if last >= '0' && last <= '9' { - n, ok := strconv.Atoi64(s) - if !ok || n < 0 { + n, err := strconv.ParseInt(s, 10, 64) + if err != nil || n < 0 { return 0, false } - return n, ok + return n, true } // Failing a trailing digit, this must always end in 'B'. // Also at this point there must be at least one digit before @@ -435,11 +435,11 @@ func parseByteCount(s string) (int64, bool) { // The one before that must always be a digit or 'i'. if c := s[len(s)-2]; c >= '0' && c <= '9' { // Trivial 'B' suffix. - n, ok := strconv.Atoi64(s[:len(s)-1]) - if !ok || n < 0 { + n, err := strconv.ParseInt(s[:len(s)-1], 10, 64) + if err != nil || n < 0 { return 0, false } - return n, ok + return n, true } else if c != 'i' { return 0, false } @@ -466,8 +466,8 @@ func parseByteCount(s string) (int64, bool) { for i := 0; i < power; i++ { m *= 1024 } - n, ok := strconv.Atoi64(s[:len(s)-3]) - if !ok || n < 0 { + n, err := strconv.ParseInt(s[:len(s)-3], 10, 64) + if err != nil || n < 0 { return 0, false } un := uint64(n) diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go index 14c13e273a..73582d0aea 100644 --- a/src/syscall/exec_linux.go +++ b/src/syscall/exec_linux.go @@ -8,7 +8,7 @@ package syscall import ( errpkg "errors" - "internal/itoa" + "internal/strconv" "runtime" "unsafe" ) @@ -681,7 +681,7 @@ childerror: func formatIDMappings(idMap []SysProcIDMap) []byte { var data []byte for _, im := range idMap { - data = append(data, itoa.Itoa(im.ContainerID)+" "+itoa.Itoa(im.HostID)+" "+itoa.Itoa(im.Size)+"\n"...) + data = append(data, strconv.Itoa(im.ContainerID)+" "+strconv.Itoa(im.HostID)+" "+strconv.Itoa(im.Size)+"\n"...) } return data } @@ -710,7 +710,7 @@ func writeIDMappings(path string, idMap []SysProcIDMap) error { // This is needed since kernel 3.19, because you can't write gid_map without // disabling setgroups() system call. func writeSetgroups(pid int, enable bool) error { - sgf := "/proc/" + itoa.Itoa(pid) + "/setgroups" + sgf := "/proc/" + strconv.Itoa(pid) + "/setgroups" fd, err := Open(sgf, O_RDWR, 0) if err != nil { return err @@ -735,7 +735,7 @@ func writeSetgroups(pid int, enable bool) error { // for a process and it is called from the parent process. func writeUidGidMappings(pid int, sys *SysProcAttr) error { if sys.UidMappings != nil { - uidf := "/proc/" + itoa.Itoa(pid) + "/uid_map" + uidf := "/proc/" + strconv.Itoa(pid) + "/uid_map" if err := writeIDMappings(uidf, sys.UidMappings); err != nil { return err } @@ -746,7 +746,7 @@ func writeUidGidMappings(pid int, sys *SysProcAttr) error { if err := writeSetgroups(pid, sys.GidMappingsEnableSetgroups); err != nil && err != ENOENT { return err } - gidf := "/proc/" + itoa.Itoa(pid) + "/gid_map" + gidf := "/proc/" + strconv.Itoa(pid) + "/gid_map" if err := writeIDMappings(gidf, sys.GidMappings); err != nil { return err } diff --git a/src/syscall/exec_plan9.go b/src/syscall/exec_plan9.go index 91705e175e..f0481e8bf0 100644 --- a/src/syscall/exec_plan9.go +++ b/src/syscall/exec_plan9.go @@ -7,7 +7,7 @@ package syscall import ( - "internal/itoa" + "internal/strconv" "runtime" "sync" "unsafe" @@ -327,7 +327,7 @@ func cexecPipe(p []int) error { return e } - fd, e := Open("#d/"+itoa.Itoa(p[1]), O_RDWR|O_CLOEXEC) + fd, e := Open("#d/"+strconv.Itoa(p[1]), O_RDWR|O_CLOEXEC) if e != nil { Close(p[0]) Close(p[1]) diff --git a/src/syscall/syscall_js.go b/src/syscall/syscall_js.go index c320e34f26..bb8d70b73d 100644 --- a/src/syscall/syscall_js.go +++ b/src/syscall/syscall_js.go @@ -8,8 +8,8 @@ package syscall import ( errorspkg "errors" - "internal/itoa" "internal/oserror" + "internal/strconv" "sync" "unsafe" ) @@ -62,7 +62,7 @@ func (e Errno) Error() string { return s } } - return "errno " + itoa.Itoa(int(e)) + return "errno " + strconv.Itoa(int(e)) } func (e Errno) Is(target error) bool { @@ -110,7 +110,7 @@ func (s Signal) String() string { return str } } - return "signal " + itoa.Itoa(int(s)) + return "signal " + strconv.Itoa(int(s)) } var signals = [...]string{} diff --git a/src/syscall/syscall_linux.go b/src/syscall/syscall_linux.go index ec9f771daa..9418bd8494 100644 --- a/src/syscall/syscall_linux.go +++ b/src/syscall/syscall_linux.go @@ -12,8 +12,8 @@ package syscall import ( - "internal/itoa" "internal/runtime/syscall/linux" + "internal/strconv" "runtime" "slices" "unsafe" @@ -361,7 +361,7 @@ func Futimesat(dirfd int, path string, tv []Timeval) (err error) { func Futimes(fd int, tv []Timeval) (err error) { // Believe it or not, this is the best we can do on Linux // (and is what glibc does). - return Utimes("/proc/self/fd/"+itoa.Itoa(fd), tv) + return Utimes("/proc/self/fd/"+strconv.Itoa(fd), tv) } const ImplementsGetwd = true diff --git a/src/syscall/syscall_unix.go b/src/syscall/syscall_unix.go index 7de2272b59..d957b77dc4 100644 --- a/src/syscall/syscall_unix.go +++ b/src/syscall/syscall_unix.go @@ -10,10 +10,10 @@ import ( errorspkg "errors" "internal/asan" "internal/bytealg" - "internal/itoa" "internal/msan" "internal/oserror" "internal/race" + "internal/strconv" "runtime" "sync" "unsafe" @@ -114,7 +114,7 @@ func (e Errno) Error() string { return s } } - return "errno " + itoa.Itoa(int(e)) + return "errno " + strconv.Itoa(int(e)) } func (e Errno) Is(target error) bool { @@ -176,7 +176,7 @@ func (s Signal) String() string { return str } } - return "signal " + itoa.Itoa(int(s)) + return "signal " + strconv.Itoa(int(s)) } func Read(fd int, p []byte) (n int, err error) { diff --git a/src/syscall/syscall_wasip1.go b/src/syscall/syscall_wasip1.go index c9225293a0..9b5f502e30 100644 --- a/src/syscall/syscall_wasip1.go +++ b/src/syscall/syscall_wasip1.go @@ -8,8 +8,8 @@ package syscall import ( "errors" - "internal/itoa" "internal/oserror" + "internal/strconv" "unsafe" ) @@ -71,7 +71,7 @@ func (e Errno) Error() string { return s } } - return "errno " + itoa.Itoa(int(e)) + return "errno " + strconv.Itoa(int(e)) } func (e Errno) Is(target error) bool { @@ -201,7 +201,7 @@ func (s Signal) String() string { case SIGSYS: return "bad system call" default: - return "signal " + itoa.Itoa(int(s)) + return "signal " + strconv.Itoa(int(s)) } } diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go index f86f03e20f..817eeb6811 100644 --- a/src/syscall/syscall_windows.go +++ b/src/syscall/syscall_windows.go @@ -10,10 +10,10 @@ import ( errorspkg "errors" "internal/asan" "internal/bytealg" - "internal/itoa" "internal/msan" "internal/oserror" "internal/race" + "internal/strconv" "sync" "unsafe" ) @@ -170,7 +170,7 @@ func (e Errno) error() string { if err != nil { n, err = formatMessage(flags, 0, uint32(e), 0, b, nil) if err != nil { - return "winapi error #" + itoa.Itoa(int(e)) + return "winapi error #" + strconv.Itoa(int(e)) } } // trim terminating \r and \n @@ -1358,7 +1358,7 @@ func (s Signal) String() string { return str } } - return "signal " + itoa.Itoa(int(s)) + return "signal " + strconv.Itoa(int(s)) } func LoadCreateSymbolicLink() error { diff --git a/src/time/zoneinfo_js.go b/src/time/zoneinfo_js.go index 8da34a21fb..11d944a904 100644 --- a/src/time/zoneinfo_js.go +++ b/src/time/zoneinfo_js.go @@ -7,7 +7,7 @@ package time import ( - "internal/itoa" + "internal/strconv" "syscall/js" ) @@ -36,10 +36,10 @@ func initLocal() { } else { z.name += "+" } - z.name += itoa.Itoa(offset / 60) + z.name += strconv.Itoa(offset / 60) min := offset % 60 if min != 0 { - z.name += ":" + itoa.Itoa(min) + z.name += ":" + strconv.Itoa(min) } localLoc.zone = []zone{z} } -- 2.52.0