[go] runtime: avoid append in printint, printuint

4 views
Skip to first unread message

Russ Cox (Gerrit)

unread,
Nov 3, 2025, 3:36:27 PM (3 days ago) Nov 3
to goph...@pubsubhelper.golang.org, Russ Cox, golang-co...@googlegroups.com

Russ Cox has uploaded the change for review

Commit message

runtime: avoid append in printint, printuint

Should make cmd/link/internal/ld.TestAbstractOriginSanity happier.
Change-Id: I121927d42e527ff23d996e7387066f149b11cc59

Change diff

diff --git a/src/internal/strconv/itoa.go b/src/internal/strconv/itoa.go
index d06de47..2375e03 100644
--- a/src/internal/strconv/itoa.go
+++ b/src/internal/strconv/itoa.go
@@ -174,6 +174,14 @@
return smalls[i*2 : i*2+2]
}

+// RuntimeFormatBase10 formats u into the tail of a
+// and returns the offset to the first byte written to a.
+// It is only for use by package runtime.
+// Other packages should use AppendUint.
+func RuntimeFormatBase10(a []byte, u uint64) int {
+ return formatBase10(a, u)
+}
+
// formatBase10 formats the decimal representation of u into the tail of a
// and returns the offset of the first byte written to a. That is, after
//
diff --git a/src/runtime/print.go b/src/runtime/print.go
index e32ecb9..c01db9d 100644
--- a/src/runtime/print.go
+++ b/src/runtime/print.go
@@ -140,13 +140,32 @@
}

func printuint(v uint64) {
+ // Note: Avoiding strconv.AppendUint so that it's clearer
+ // that there are no allocations in this routine.
+ // cmd/link/internal/ld.TestAbstractOriginSanity
+ // sees the append and doesn't realize it doesn't allocate.
var buf [20]byte
- gwrite(strconv.AppendUint(buf[:0], v, 10))
+ i := strconv.RuntimeFormatBase10(buf[:], v)
+ gwrite(buf[i:])
}

func printint(v int64) {
+ // Note: Avoiding strconv.AppendUint so that it's clearer
+ // that there are no allocations in this routine.
+ // cmd/link/internal/ld.TestAbstractOriginSanity
+ // sees the append and doesn't realize it doesn't allocate.
+ neg := v < 0
+ u := uint64(v)
+ if neg {
+ u = -u
+ }
var buf [20]byte
- gwrite(strconv.AppendInt(buf[:0], v, 10))
+ i := strconv.RuntimeFormatBase10(buf[:], u)
+ if neg {
+ i--
+ buf[i] = '-'
+ }
+ gwrite(buf[i:])
}

var minhexdigits = 0 // protected by printlock

Change information

Files:
  • M src/internal/strconv/itoa.go
  • M src/runtime/print.go
Change size: S
Delta: 2 files changed, 29 insertions(+), 2 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I121927d42e527ff23d996e7387066f149b11cc59
Gerrit-Change-Number: 717480
Gerrit-PatchSet: 1
Gerrit-Owner: Russ Cox <r...@golang.org>
unsatisfied_requirement
satisfied_requirement
open
diffy

Russ Cox (Gerrit)

unread,
Nov 3, 2025, 3:36:28 PM (3 days ago) Nov 3
to Russ Cox, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Russ Cox voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I121927d42e527ff23d996e7387066f149b11cc59
Gerrit-Change-Number: 717480
Gerrit-PatchSet: 1
Gerrit-Owner: Russ Cox <r...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-Comment-Date: Mon, 03 Nov 2025 20:36:24 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Russ Cox (Gerrit)

unread,
Nov 3, 2025, 3:37:59 PM (3 days ago) Nov 3
to Russ Cox, goph...@pubsubhelper.golang.org, Cherry Mui, Go LUCI, golang-co...@googlegroups.com
Attention needed from Cherry Mui

Russ Cox added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Russ Cox . resolved

Added a longtest builder.

Open in Gerrit

Related details

Attention is currently required from:
  • Cherry Mui
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I121927d42e527ff23d996e7387066f149b11cc59
Gerrit-Change-Number: 717480
Gerrit-PatchSet: 1
Gerrit-Owner: Russ Cox <r...@golang.org>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-Attention: Cherry Mui <cher...@google.com>
Gerrit-Comment-Date: Mon, 03 Nov 2025 20:37:55 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
satisfied_requirement
open
diffy

Russ Cox (Gerrit)

unread,
Nov 3, 2025, 3:53:45 PM (3 days ago) Nov 3
to Russ Cox, goph...@pubsubhelper.golang.org, Go LUCI, Cherry Mui, golang-co...@googlegroups.com
Attention needed from Cherry Mui

Russ Cox voted and added 1 comment

Votes added by Russ Cox

Commit-Queue+1

1 comment

Patchset-level comments
Russ Cox . unresolved

Hmm, the longtest trybot failure is now complaining about castogstatus "calling" panic, which happens here:

	print("runtime: castogscanstatus oldval=", hex(oldval), " newval=", hex(newval), "\n")
throw("castogscanstatus")
panic("not reached")

That "panic" has been there since 2015.

Open in Gerrit

Related details

Attention is currently required from:
  • Cherry Mui
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I121927d42e527ff23d996e7387066f149b11cc59
    Gerrit-Change-Number: 717480
    Gerrit-PatchSet: 1
    Gerrit-Owner: Russ Cox <r...@golang.org>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Russ Cox <r...@golang.org>
    Gerrit-Attention: Cherry Mui <cher...@google.com>
    Gerrit-Comment-Date: Mon, 03 Nov 2025 20:53:42 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Cherry Mui (Gerrit)

    unread,
    Nov 3, 2025, 5:13:21 PM (3 days ago) Nov 3
    to Russ Cox, goph...@pubsubhelper.golang.org, Go LUCI, golang-co...@googlegroups.com
    Attention needed from Russ Cox

    Cherry Mui voted Code-Review+2

    Code-Review+2
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Russ Cox
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I121927d42e527ff23d996e7387066f149b11cc59
    Gerrit-Change-Number: 717480
    Gerrit-PatchSet: 1
    Gerrit-Owner: Russ Cox <r...@golang.org>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Russ Cox <r...@golang.org>
    Gerrit-Attention: Russ Cox <r...@golang.org>
    Gerrit-Comment-Date: Mon, 03 Nov 2025 22:13:18 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Russ Cox (Gerrit)

    unread,
    Nov 3, 2025, 5:58:56 PM (3 days ago) Nov 3
    to Russ Cox, goph...@pubsubhelper.golang.org, Cherry Mui, Go LUCI, golang-co...@googlegroups.com

    Russ Cox voted Commit-Queue+1

    Commit-Queue+1
    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I121927d42e527ff23d996e7387066f149b11cc59
      Gerrit-Change-Number: 717480
      Gerrit-PatchSet: 2
      Gerrit-Owner: Russ Cox <r...@golang.org>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Russ Cox <r...@golang.org>
      Gerrit-Comment-Date: Mon, 03 Nov 2025 22:58:52 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Russ Cox (Gerrit)

      unread,
      Nov 3, 2025, 6:03:48 PM (3 days ago) Nov 3
      to Russ Cox, goph...@pubsubhelper.golang.org, Cherry Mui, Go LUCI, golang-co...@googlegroups.com

      Russ Cox added 1 comment

      Patchset-level comments

      Hmm, the longtest trybot failure is now complaining about castogstatus "calling" panic, which happens here:

      	print("runtime: castogscanstatus oldval=", hex(oldval), " newval=", hex(newval), "\n")
      throw("castogscanstatus")
      panic("not reached")

      That "panic" has been there since 2015.

      Russ Cox

      CL 717406 fixed this one. Maybe now strconv is the only one left.

      Open in Gerrit

      Related details

      Attention set is empty
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I121927d42e527ff23d996e7387066f149b11cc59
      Gerrit-Change-Number: 717480
      Gerrit-PatchSet: 2
      Gerrit-Owner: Russ Cox <r...@golang.org>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Russ Cox <r...@golang.org>
      Gerrit-Comment-Date: Mon, 03 Nov 2025 23:03:42 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Russ Cox <r...@golang.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Russ Cox (Gerrit)

      unread,
      Nov 3, 2025, 7:37:09 PM (2 days ago) Nov 3
      to Russ Cox, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Cherry Mui, golang-co...@googlegroups.com

      Russ Cox submitted the change

      Unreviewed changes

      1 is the latest approved patch-set.
      No files were changed between the latest approved patch-set and the submitted one.

      Change information

      Commit message:
      runtime: avoid append in printint, printuint

      Should make cmd/link/internal/ld.TestAbstractOriginSanity happier.
      Change-Id: I121927d42e527ff23d996e7387066f149b11cc59
      Files:
      • M src/internal/strconv/itoa.go
      • M src/runtime/print.go
      Change size: S
      Delta: 2 files changed, 29 insertions(+), 2 deletions(-)
      Branch: refs/heads/master
      Submit Requirements:
      • requirement satisfiedCode-Review: +2 by Cherry Mui
      • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
      Open in Gerrit
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: merged
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I121927d42e527ff23d996e7387066f149b11cc59
      Gerrit-Change-Number: 717480
      Gerrit-PatchSet: 3
      open
      diffy
      satisfied_requirement
      Reply all
      Reply to author
      Forward
      0 new messages