mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
std: pass bytes.Buffer and strings.Builder by pointer
This CL fixes a number of (all true positive) findings of vet's
copylock analyzer patched to treat the Bu{ff,uild}er types
as non-copyable after first use.
This does require imposing an additional indirection
between noder.writer and Encoder since the field is
embedded by value but its constructor now returns a pointer.
Updates golang/go#25907
Updates golang/go#47276
Change-Id: I0b4d77ac12bcecadf06a91709e695365da10766c
Reviewed-on: https://go-review.googlesource.com/c/go/+/635339
Reviewed-by: Robert Findley <rfindley@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
da9c5b142c
commit
198c3cb785
6 changed files with 17 additions and 17 deletions
|
|
@ -354,7 +354,7 @@ func TestWriteAppend(t *testing.T) {
|
||||||
got.Write(b)
|
got.Write(b)
|
||||||
}
|
}
|
||||||
if !Equal(got.Bytes(), want) {
|
if !Equal(got.Bytes(), want) {
|
||||||
t.Fatalf("Bytes() = %q, want %q", got, want)
|
t.Fatalf("Bytes() = %q, want %q", &got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
// With a sufficiently sized buffer, there should be no allocations.
|
// With a sufficiently sized buffer, there should be no allocations.
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ func (l *linker) relocIdx(pr *pkgReader, k pkgbits.SectionKind, idx index) index
|
||||||
// if we do external relocations.
|
// if we do external relocations.
|
||||||
|
|
||||||
w := l.pw.NewEncoderRaw(k)
|
w := l.pw.NewEncoderRaw(k)
|
||||||
l.relocCommon(pr, &w, k, idx)
|
l.relocCommon(pr, w, k, idx)
|
||||||
newidx = w.Idx
|
newidx = w.Idx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,9 +168,9 @@ func (l *linker) relocObj(pr *pkgReader, idx index) index {
|
||||||
assert(wname.Idx == w.Idx)
|
assert(wname.Idx == w.Idx)
|
||||||
assert(wdict.Idx == w.Idx)
|
assert(wdict.Idx == w.Idx)
|
||||||
|
|
||||||
l.relocCommon(pr, &w, pkgbits.SectionObj, idx)
|
l.relocCommon(pr, w, pkgbits.SectionObj, idx)
|
||||||
l.relocCommon(pr, &wname, pkgbits.SectionName, idx)
|
l.relocCommon(pr, wname, pkgbits.SectionName, idx)
|
||||||
l.relocCommon(pr, &wdict, pkgbits.SectionObjDict, idx)
|
l.relocCommon(pr, wdict, pkgbits.SectionObjDict, idx)
|
||||||
|
|
||||||
// Generic types and functions won't have definitions, and imported
|
// Generic types and functions won't have definitions, and imported
|
||||||
// objects may not either.
|
// objects may not either.
|
||||||
|
|
@ -181,15 +181,15 @@ func (l *linker) relocObj(pr *pkgReader, idx index) index {
|
||||||
wext.Sync(pkgbits.SyncObject1)
|
wext.Sync(pkgbits.SyncObject1)
|
||||||
switch tag {
|
switch tag {
|
||||||
case pkgbits.ObjFunc:
|
case pkgbits.ObjFunc:
|
||||||
l.relocFuncExt(&wext, obj)
|
l.relocFuncExt(wext, obj)
|
||||||
case pkgbits.ObjType:
|
case pkgbits.ObjType:
|
||||||
l.relocTypeExt(&wext, obj)
|
l.relocTypeExt(wext, obj)
|
||||||
case pkgbits.ObjVar:
|
case pkgbits.ObjVar:
|
||||||
l.relocVarExt(&wext, obj)
|
l.relocVarExt(wext, obj)
|
||||||
}
|
}
|
||||||
wext.Flush()
|
wext.Flush()
|
||||||
} else {
|
} else {
|
||||||
l.relocCommon(pr, &wext, pkgbits.SectionObjExt, idx)
|
l.relocCommon(pr, wext, pkgbits.SectionObjExt, idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we need to export the inline bodies for functions and
|
// Check if we need to export the inline bodies for functions and
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ func (pw *pkgWriter) typeOf(expr syntax.Expr) types2.Type {
|
||||||
type writer struct {
|
type writer struct {
|
||||||
p *pkgWriter
|
p *pkgWriter
|
||||||
|
|
||||||
pkgbits.Encoder
|
*pkgbits.Encoder
|
||||||
|
|
||||||
// sig holds the signature for the current function body, if any.
|
// sig holds the signature for the current function body, if any.
|
||||||
sig *types2.Signature
|
sig *types2.Signature
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ func TestReset(t *testing.T) {
|
||||||
|
|
||||||
for i, s := range ss {
|
for i, s := range ss {
|
||||||
if s != inflated[i].String() {
|
if s != inflated[i].String() {
|
||||||
t.Errorf("inflated[%d]:\ngot %q\nwant %q", i, inflated[i], s)
|
t.Errorf("inflated[%d]:\ngot %q\nwant %q", i, &inflated[i], s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +92,7 @@ func TestResetDict(t *testing.T) {
|
||||||
|
|
||||||
for i, s := range ss {
|
for i, s := range ss {
|
||||||
if s != inflated[i].String() {
|
if s != inflated[i].String() {
|
||||||
t.Errorf("inflated[%d]:\ngot %q\nwant %q", i, inflated[i], s)
|
t.Errorf("inflated[%d]:\ngot %q\nwant %q", i, &inflated[i], s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ func (pw *PkgEncoder) StringIdx(s string) RelIndex {
|
||||||
// NewEncoder returns an Encoder for a new element within the given
|
// NewEncoder returns an Encoder for a new element within the given
|
||||||
// section, and encodes the given SyncMarker as the start of the
|
// section, and encodes the given SyncMarker as the start of the
|
||||||
// element bitstream.
|
// element bitstream.
|
||||||
func (pw *PkgEncoder) NewEncoder(k SectionKind, marker SyncMarker) Encoder {
|
func (pw *PkgEncoder) NewEncoder(k SectionKind, marker SyncMarker) *Encoder {
|
||||||
e := pw.NewEncoderRaw(k)
|
e := pw.NewEncoderRaw(k)
|
||||||
e.Sync(marker)
|
e.Sync(marker)
|
||||||
return e
|
return e
|
||||||
|
|
@ -131,11 +131,11 @@ func (pw *PkgEncoder) NewEncoder(k SectionKind, marker SyncMarker) Encoder {
|
||||||
// section.
|
// section.
|
||||||
//
|
//
|
||||||
// Most callers should use NewEncoder instead.
|
// Most callers should use NewEncoder instead.
|
||||||
func (pw *PkgEncoder) NewEncoderRaw(k SectionKind) Encoder {
|
func (pw *PkgEncoder) NewEncoderRaw(k SectionKind) *Encoder {
|
||||||
idx := RelIndex(len(pw.elems[k]))
|
idx := RelIndex(len(pw.elems[k]))
|
||||||
pw.elems[k] = append(pw.elems[k], "") // placeholder
|
pw.elems[k] = append(pw.elems[k], "") // placeholder
|
||||||
|
|
||||||
return Encoder{
|
return &Encoder{
|
||||||
p: pw,
|
p: pw,
|
||||||
k: k,
|
k: k,
|
||||||
Idx: idx,
|
Idx: idx,
|
||||||
|
|
|
||||||
|
|
@ -465,7 +465,7 @@ func testCPUProfile(t *testing.T, matches profileMatchFunc, f func(dur time.Dura
|
||||||
f(duration)
|
f(duration)
|
||||||
StopCPUProfile()
|
StopCPUProfile()
|
||||||
|
|
||||||
if p, ok := profileOk(t, matches, prof, duration); ok {
|
if p, ok := profileOk(t, matches, &prof, duration); ok {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -515,7 +515,7 @@ func stackContains(spec string, count uintptr, stk []*profile.Location, labels m
|
||||||
|
|
||||||
type sampleMatchFunc func(spec string, count uintptr, stk []*profile.Location, labels map[string][]string) bool
|
type sampleMatchFunc func(spec string, count uintptr, stk []*profile.Location, labels map[string][]string) bool
|
||||||
|
|
||||||
func profileOk(t *testing.T, matches profileMatchFunc, prof bytes.Buffer, duration time.Duration) (_ *profile.Profile, ok bool) {
|
func profileOk(t *testing.T, matches profileMatchFunc, prof *bytes.Buffer, duration time.Duration) (_ *profile.Profile, ok bool) {
|
||||||
ok = true
|
ok = true
|
||||||
|
|
||||||
var samples uintptr
|
var samples uintptr
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue