Skip to content

Commit e9f1cb1

Browse files
committed
Merge branch 'master' into net-hostLookupOrder-reload-resolv
2 parents 2f19a5a + 74b6a22 commit e9f1cb1

File tree

34 files changed

+403
-123
lines changed

34 files changed

+403
-123
lines changed

doc/go_spec.html

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--{
22
"Title": "The Go Programming Language Specification",
3-
"Subtitle": "Version of September 21, 2022",
3+
"Subtitle": "Version of November 10, 2022",
44
"Path": "/ref/spec"
55
}-->
66

@@ -5083,12 +5083,16 @@ <h3 id="Comparison_operators">Comparison operators</h3>
50835083
<li>
50845084
Struct values are comparable if all their fields are comparable.
50855085
Two struct values are equal if their corresponding
5086-
non-<a href="#Blank_identifier">blank</a> fields are equal.
5086+
non-<a href="#Blank_identifier">blank</a> field values are equal.
5087+
The fields are compared in source order, and comparison stops as
5088+
soon as two field values differ (or all fields have been compared).
50875089
</li>
50885090

50895091
<li>
50905092
Array values are comparable if values of the array element type are comparable.
5091-
Two array values are equal if their corresponding elements are equal.
5093+
Two array values are equal if their corresponding element values are equal.
5094+
The elements are compared in ascending index order, and comparison stops
5095+
as soon as two element values differ (or all elements have been compared).
50925096
</li>
50935097
</ul>
50945098

@@ -8002,6 +8006,9 @@ <h3 id="Package_unsafe">Package <code>unsafe</code></h3>
80028006
type IntegerType int // shorthand for an integer type; it is not a real type
80038007
func Add(ptr Pointer, len IntegerType) Pointer
80048008
func Slice(ptr *ArbitraryType, len IntegerType) []ArbitraryType
8009+
func SliceData(slice []ArbitraryType) *ArbitraryType
8010+
func String(ptr *byte, len IntegerType) string
8011+
func StringData(str string) *byte
80058012
</pre>
80068013

80078014
<!--
@@ -8105,6 +8112,27 @@ <h3 id="Package_unsafe">Package <code>unsafe</code></h3>
81058112
a <a href="#Run_time_panics">run-time panic</a> occurs.
81068113
</p>
81078114

8115+
<p>
8116+
The function <code>SliceData</code> returns a pointer to the underlying array of the <code>slice</code> argument.
8117+
If the slice's capacity <code>cap(slice)</code> is not zero, that pointer is <code>&slice[:1][0]</code>.
8118+
If <code>slice</code> is <code>nil</code>, the result is <code>nil</code>.
8119+
Otherwise it is a non-<code>nil</code> pointer to an unspecified memory address.
8120+
</p>
8121+
8122+
<p>
8123+
The function <code>String</code> returns a <code>string</code> value whose underlying bytes start at
8124+
<code>ptr</code> and whose length is <code>len</code>.
8125+
The same requirements apply to the <code>ptr</code> and <code>len</code> argument as in the function
8126+
<code>Slice</code>. If <code>len</code> is zero, the result is the empty string <code>""</code>.
8127+
Since Go strings are immutable, the bytes passed to <code>String</code> must not be modified afterwards.
8128+
</p>
8129+
8130+
<p>
8131+
The function <code>StringData</code> returns a pointer to the underlying bytes of the <code>str</code> argument.
8132+
For an empty string the return value is unspecified, and may be <code>nil</code>.
8133+
Since Go strings are immutable, the bytes returned by <code>StringData</code> must not be modified.
8134+
</p>
8135+
81088136
<h3 id="Size_and_alignment_guarantees">Size and alignment guarantees</h3>
81098137

81108138
<p>

src/archive/zip/reader.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ func (f *File) Open() (io.ReadCloser, error) {
197197
if err != nil {
198198
return nil, err
199199
}
200+
if strings.HasSuffix(f.Name, "/") {
201+
if f.CompressedSize64 != 0 || f.hasDataDescriptor() {
202+
return &dirReader{ErrFormat}, nil
203+
} else {
204+
return &dirReader{io.EOF}, nil
205+
}
206+
}
200207
size := int64(f.CompressedSize64)
201208
r := io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset, size)
202209
dcomp := f.zip.decompressor(f.Method)
@@ -228,6 +235,18 @@ func (f *File) OpenRaw() (io.Reader, error) {
228235
return r, nil
229236
}
230237

238+
type dirReader struct {
239+
err error
240+
}
241+
242+
func (r *dirReader) Read([]byte) (int, error) {
243+
return 0, r.err
244+
}
245+
246+
func (r *dirReader) Close() error {
247+
return nil
248+
}
249+
231250
type checksumReader struct {
232251
rc io.ReadCloser
233252
hash hash.Hash32

src/archive/zip/reader_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,3 +1554,33 @@ func TestUnderSize(t *testing.T) {
15541554
})
15551555
}
15561556
}
1557+
1558+
func TestIssue54801(t *testing.T) {
1559+
for _, input := range []string{"testdata/readme.zip", "testdata/dd.zip"} {
1560+
z, err := OpenReader(input)
1561+
if err != nil {
1562+
t.Fatal(err)
1563+
}
1564+
defer z.Close()
1565+
1566+
for _, f := range z.File {
1567+
// Make file a directory
1568+
f.Name += "/"
1569+
1570+
t.Run(f.Name, func(t *testing.T) {
1571+
t.Logf("CompressedSize64: %d, Flags: %#x", f.CompressedSize64, f.Flags)
1572+
1573+
rd, err := f.Open()
1574+
if err != nil {
1575+
t.Fatal(err)
1576+
}
1577+
defer rd.Close()
1578+
1579+
n, got := io.Copy(io.Discard, rd)
1580+
if n != 0 || got != ErrFormat {
1581+
t.Fatalf("Error mismatch, got: %d, %v, want: %v", n, got, ErrFormat)
1582+
}
1583+
})
1584+
}
1585+
}
1586+
}

src/cmd/go/go_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,9 +2348,11 @@ func TestUpxCompression(t *testing.T) {
23482348
}
23492349
}
23502350

2351+
var gocacheverify = godebug.New("gocacheverify")
2352+
23512353
func TestCacheListStale(t *testing.T) {
23522354
tooSlow(t)
2353-
if godebug.Get("gocacheverify") == "1" {
2355+
if gocacheverify.Value() == "1" {
23542356
t.Skip("GODEBUG gocacheverify")
23552357
}
23562358
tg := testgo(t)
@@ -2373,7 +2375,7 @@ func TestCacheListStale(t *testing.T) {
23732375
func TestCacheCoverage(t *testing.T) {
23742376
tooSlow(t)
23752377

2376-
if godebug.Get("gocacheverify") == "1" {
2378+
if gocacheverify.Value() == "1" {
23772379
t.Skip("GODEBUG gocacheverify")
23782380
}
23792381

@@ -2407,7 +2409,7 @@ func TestIssue22588(t *testing.T) {
24072409

24082410
func TestIssue22531(t *testing.T) {
24092411
tooSlow(t)
2410-
if godebug.Get("gocacheverify") == "1" {
2412+
if gocacheverify.Value() == "1" {
24112413
t.Skip("GODEBUG gocacheverify")
24122414
}
24132415
tg := testgo(t)
@@ -2436,7 +2438,7 @@ func TestIssue22531(t *testing.T) {
24362438

24372439
func TestIssue22596(t *testing.T) {
24382440
tooSlow(t)
2439-
if godebug.Get("gocacheverify") == "1" {
2441+
if gocacheverify.Value() == "1" {
24402442
t.Skip("GODEBUG gocacheverify")
24412443
}
24422444
tg := testgo(t)
@@ -2466,7 +2468,7 @@ func TestIssue22596(t *testing.T) {
24662468
func TestTestCache(t *testing.T) {
24672469
tooSlow(t)
24682470

2469-
if godebug.Get("gocacheverify") == "1" {
2471+
if gocacheverify.Value() == "1" {
24702472
t.Skip("GODEBUG gocacheverify")
24712473
}
24722474
tg := testgo(t)

src/cmd/go/internal/fsys/fsys.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,29 @@ func Trace(op, path string) {
3636
traceMu.Lock()
3737
defer traceMu.Unlock()
3838
fmt.Fprintf(traceFile, "%d gofsystrace %s %s\n", os.Getpid(), op, path)
39-
if traceStack != "" {
40-
if match, _ := pathpkg.Match(traceStack, path); match {
39+
if pattern := gofsystracestack.Value(); pattern != "" {
40+
if match, _ := pathpkg.Match(pattern, path); match {
4141
traceFile.Write(debug.Stack())
4242
}
4343
}
4444
}
4545

4646
var (
47-
doTrace bool
48-
traceStack string
49-
traceFile *os.File
50-
traceMu sync.Mutex
47+
doTrace bool
48+
traceFile *os.File
49+
traceMu sync.Mutex
50+
51+
gofsystrace = godebug.New("gofsystrace")
52+
gofsystracelog = godebug.New("gofsystracelog")
53+
gofsystracestack = godebug.New("gofsystracestack")
5154
)
5255

5356
func init() {
54-
if godebug.Get("gofsystrace") != "1" {
57+
if gofsystrace.Value() != "1" {
5558
return
5659
}
5760
doTrace = true
58-
traceStack = godebug.Get("gofsystracestack")
59-
if f := godebug.Get("gofsystracelog"); f != "" {
61+
if f := gofsystracelog.Value(); f != "" {
6062
// Note: No buffering on writes to this file, so no need to worry about closing it at exit.
6163
var err error
6264
traceFile, err = os.OpenFile(f, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)

src/cmd/go/internal/modindex/read.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
// It will be removed before the release.
3838
// TODO(matloob): Remove enabled once we have more confidence on the
3939
// module index.
40-
var enabled bool = godebug.Get("goindex") != "0"
40+
var enabled = godebug.New("goindex").Value() != "0"
4141

4242
// Module represents and encoded module index file. It is used to
4343
// do the equivalent of build.Import of packages in the module and answer other
@@ -368,6 +368,8 @@ func relPath(path, modroot string) string {
368368
return str.TrimFilePathPrefix(filepath.Clean(path), filepath.Clean(modroot))
369369
}
370370

371+
var installgorootAll = godebug.New("installgoroot").Value() == "all"
372+
371373
// Import is the equivalent of build.Import given the information in Module.
372374
func (rp *IndexPackage) Import(bctxt build.Context, mode build.ImportMode) (p *build.Package, err error) {
373375
defer unprotect(protect(), &err)
@@ -436,7 +438,7 @@ func (rp *IndexPackage) Import(bctxt build.Context, mode build.ImportMode) (p *b
436438
p.PkgTargetRoot = ctxt.joinPath(p.Root, pkgtargetroot)
437439

438440
// Set the install target if applicable.
439-
if !p.Goroot || (strings.EqualFold(godebug.Get("installgoroot"), "all") && p.ImportPath != "unsafe" && p.ImportPath != "builtin") {
441+
if !p.Goroot || (installgorootAll && p.ImportPath != "unsafe" && p.ImportPath != "builtin") {
440442
p.PkgObj = ctxt.joinPath(p.Root, pkga)
441443
}
442444
}

src/crypto/x509/x509.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,8 @@ func signaturePublicKeyAlgoMismatchError(expectedPubKeyAlgo PublicKeyAlgorithm,
813813
return fmt.Errorf("x509: signature algorithm specifies an %s public key, but have public key of type %T", expectedPubKeyAlgo.String(), pubKey)
814814
}
815815

816+
var x509sha1 = godebug.New("x509sha1")
817+
816818
// checkSignature verifies that signature is a valid signature over signed from
817819
// a crypto.PublicKey.
818820
func checkSignature(algo SignatureAlgorithm, signed, signature []byte, publicKey crypto.PublicKey, allowSHA1 bool) (err error) {
@@ -835,7 +837,7 @@ func checkSignature(algo SignatureAlgorithm, signed, signature []byte, publicKey
835837
return InsecureAlgorithmError(algo)
836838
case crypto.SHA1:
837839
// SHA-1 signatures are mostly disabled. See go.dev/issue/41682.
838-
if !allowSHA1 && godebug.Get("x509sha1") != "1" {
840+
if !allowSHA1 && x509sha1.Value() != "1" {
839841
return InsecureAlgorithmError(algo)
840842
}
841843
fallthrough

src/database/sql/sql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3228,7 +3228,7 @@ func rowsColumnInfoSetupConnLocked(rowsi driver.Rows) []*ColumnType {
32283228
// select query will close any cursor *Rows if the parent *Rows is closed.
32293229
//
32303230
// If any of the first arguments implementing Scanner returns an error,
3231-
// that error will be wrapped in the returned error
3231+
// that error will be wrapped in the returned error.
32323232
func (rs *Rows) Scan(dest ...any) error {
32333233
rs.closemu.RLock()
32343234

src/go/build/build.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ func nameExt(name string) string {
521521
return name[i:]
522522
}
523523

524+
var installgoroot = godebug.New("installgoroot")
525+
524526
// Import returns details about the Go package named by the import path,
525527
// interpreting local import paths relative to the srcDir directory.
526528
// If the path is a local import path naming a package that can be imported
@@ -783,7 +785,7 @@ Found:
783785
p.PkgTargetRoot = ctxt.joinPath(p.Root, pkgtargetroot)
784786

785787
// Set the install target if applicable.
786-
if !p.Goroot || (strings.EqualFold(godebug.Get("installgoroot"), "all") && p.ImportPath != "unsafe" && p.ImportPath != "builtin") {
788+
if !p.Goroot || (installgoroot.Value() == "all" && p.ImportPath != "unsafe" && p.ImportPath != "builtin") {
787789
p.PkgObj = ctxt.joinPath(p.Root, pkga)
788790
}
789791
}

src/go/build/deps_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,10 @@ var depsRules = `
5252
internal/goarch, unsafe
5353
< internal/abi;
5454
55-
unsafe
56-
< internal/godebug;
57-
5855
# RUNTIME is the core runtime group of packages, all of them very light-weight.
5956
internal/abi, internal/cpu, internal/goarch,
6057
internal/coverage/rtcov, internal/goexperiment,
61-
internal/goos, internal/godebug, unsafe
58+
internal/goos, unsafe
6259
< internal/bytealg
6360
< internal/itoa
6461
< internal/unsafeheader
@@ -70,6 +67,7 @@ var depsRules = `
7067
< sync/atomic
7168
< internal/race
7269
< sync
70+
< internal/godebug
7371
< internal/reflectlite
7472
< errors
7573
< internal/oserror, math/bits

src/internal/cpu/cpu_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestDisableAllCapabilities(t *testing.T) {
4848
func TestAllCapabilitiesDisabled(t *testing.T) {
4949
MustHaveDebugOptionsSupport(t)
5050

51-
if godebug.Get("cpu.all") != "off" {
51+
if godebug.New("cpu.all").Value() != "off" {
5252
t.Skipf("skipping test: GODEBUG=cpu.all=off not set")
5353
}
5454

src/internal/cpu/cpu_x86_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestDisableSSE3(t *testing.T) {
2828
func TestSSE3DebugOption(t *testing.T) {
2929
MustHaveDebugOptionsSupport(t)
3030

31-
if godebug.Get("cpu.sse3") != "off" {
31+
if godebug.New("cpu.sse3").Value() != "off" {
3232
t.Skipf("skipping test: GODEBUG=cpu.sse3=off not set")
3333
}
3434

src/internal/fuzz/fuzz.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"reflect"
2222
"runtime"
2323
"strings"
24-
"sync"
2524
"time"
2625
)
2726

@@ -1077,14 +1076,8 @@ var zeroVals []any = []any{
10771076
uint64(0),
10781077
}
10791078

1080-
var (
1081-
debugInfo bool
1082-
debugInfoOnce sync.Once
1083-
)
1079+
var debugInfo = godebug.New("fuzzdebug").Value() == "1"
10841080

10851081
func shouldPrintDebugInfo() bool {
1086-
debugInfoOnce.Do(func() {
1087-
debugInfo = godebug.Get("fuzzdebug") == "1"
1088-
})
10891082
return debugInfo
10901083
}

src/internal/godebug/export_test.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)