aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2021-02-08 14:01:08 -0500
committerCherry Zhang <cherryyz@google.com>2021-02-08 14:01:08 -0500
commit50449de66aad9997690f40680cbca4ba26a41628 (patch)
treee0bd9207cd647415db62dc6ea4e31ce7018f1d76
parent7b0dfb177f3ae81641af898bb5479256fb21fd5d (diff)
parent1901853098bbe25a1bbedc0ee53c6658d754151e (diff)
downloadgo-50449de66aad9997690f40680cbca4ba26a41628.tar.gz
go-50449de66aad9997690f40680cbca4ba26a41628.zip
[dev.regabi] all: merge master (1901853) into dev.regabi
Merge List: + 2021-02-08 1901853098 runtime/metrics: fix panic in readingAllMetric example + 2021-02-08 ed3e4afa12 syscall/plan9: remove spooky fd action at a distance + 2021-02-05 724d0720b3 doc/go1.16: add missed heading tag in vet section + 2021-02-05 b54cd94d47 embed, io/fs: clarify that leading and trailing slashes are disallowed + 2021-02-05 4516afebed testing/fstest: avoid symlink-induced failures in tester + 2021-02-04 8869086d8f runtime: fix typo in histogram.go + 2021-02-03 e491c6eea9 math/big: fix comment in divRecursiveStep Change-Id: I5e2bd18f42251eeb4ad0bf5c93a08c6a9b873d7b
-rw-r--r--doc/go1.16.html2
-rw-r--r--src/embed/embed.go18
-rw-r--r--src/io/fs/fs.go1
-rw-r--r--src/math/big/nat.go2
-rw-r--r--src/runtime/histogram.go2
-rw-r--r--src/runtime/metrics/example_test.go2
-rw-r--r--src/syscall/exec_plan9.go5
-rw-r--r--src/testing/fstest/testfs.go25
-rw-r--r--src/testing/fstest/testfs_test.go31
9 files changed, 67 insertions, 21 deletions
diff --git a/doc/go1.16.html b/doc/go1.16.html
index 8d31f63fa2..878bf0d029 100644
--- a/doc/go1.16.html
+++ b/doc/go1.16.html
@@ -364,6 +364,8 @@ func TestFoo(t *testing.T) {
}
</pre>
+<h4 id="vet-frame-pointer">New warning for frame pointer</h4>
+
<p><!-- CL 248686, CL 276372 -->
The vet tool now warns about amd64 assembly that clobbers the BP
register (the frame pointer) without saving and restoring it,
diff --git a/src/embed/embed.go b/src/embed/embed.go
index 5f984aaf71..7f2719d2a7 100644
--- a/src/embed/embed.go
+++ b/src/embed/embed.go
@@ -61,12 +61,15 @@
// The Go build system will recognize the directives and arrange for the declared variable
// (in the example above, content) to be populated with the matching files from the file system.
//
-// The //go:embed directive accepts multiple space-separated patterns for brevity,
-// but it can also be repeated, to avoid very long lines when there are many patterns.
-// The patterns are interpreted relative to the package directory containing the source file.
-// The path separator is a forward slash, even on Windows systems.
-// To allow for naming files with spaces in their names, patterns can be written
-// as Go double-quoted or back-quoted string literals.
+// The //go:embed directive accepts multiple space-separated patterns for
+// brevity, but it can also be repeated, to avoid very long lines when there are
+// many patterns. The patterns are interpreted relative to the package directory
+// containing the source file. The path separator is a forward slash, even on
+// Windows systems. Patterns may not contain ‘.’ or ‘..’ or empty path elements,
+// nor may they begin or end with a slash. To match everything in the current
+// directory, use ‘*’ instead of ‘.’. To allow for naming files with spaces in
+// their names, patterns can be written as Go double-quoted or back-quoted
+// string literals.
//
// If a pattern names a directory, all files in the subtree rooted at that directory are
// embedded (recursively), except that files with names beginning with ‘.’ or ‘_’
@@ -87,9 +90,6 @@
// Matches for empty directories are ignored. After that, each pattern in a //go:embed line
// must match at least one file or non-empty directory.
//
-// Patterns must not contain ‘.’ or ‘..’ path elements nor begin with a leading slash.
-// To match everything in the current directory, use ‘*’ instead of ‘.’.
-//
// If any patterns are invalid or have invalid matches, the build will fail.
//
// Strings and Bytes
diff --git a/src/io/fs/fs.go b/src/io/fs/fs.go
index b691a86049..c330f123ad 100644
--- a/src/io/fs/fs.go
+++ b/src/io/fs/fs.go
@@ -36,6 +36,7 @@ type FS interface {
// sequences of path elements, like “x/y/z”.
// Path names must not contain a “.” or “..” or empty element,
// except for the special case that the root directory is named “.”.
+// Leading and trailing slashes (like “/x” or “x/”) are not allowed.
//
// Paths are slash-separated on all systems, even Windows.
// Backslashes must not appear in path names.
diff --git a/src/math/big/nat.go b/src/math/big/nat.go
index 068176e1c1..bbd6c8850b 100644
--- a/src/math/big/nat.go
+++ b/src/math/big/nat.go
@@ -881,7 +881,7 @@ func (z nat) divRecursiveStep(u, v nat, depth int, tmp *nat, temps []*nat) {
// then floor(u1/v1) >= floor(u/v)
//
// Moreover, the difference is at most 2 if len(v1) >= len(u/v)
- // We choose s = B-1 since len(v)-B >= B+1 >= len(u/v)
+ // We choose s = B-1 since len(v)-s >= B+1 >= len(u/v)
s := (B - 1)
// Except for the first step, the top bits are always
// a division remainder, so the quotient length is <= n.
diff --git a/src/runtime/histogram.go b/src/runtime/histogram.go
index 42baa6c5e2..da4910d341 100644
--- a/src/runtime/histogram.go
+++ b/src/runtime/histogram.go
@@ -26,7 +26,7 @@ const (
// The number of super-buckets (timeHistNumSuperBuckets), on the
// other hand, defines the range. To reserve room for sub-buckets,
// bit timeHistSubBucketBits is the first bit considered for
- // super-buckets, so super-bucket indicies are adjusted accordingly.
+ // super-buckets, so super-bucket indices are adjusted accordingly.
//
// As an example, consider 45 super-buckets with 16 sub-buckets.
//
diff --git a/src/runtime/metrics/example_test.go b/src/runtime/metrics/example_test.go
index cade0c38bf..624d9d8a6b 100644
--- a/src/runtime/metrics/example_test.go
+++ b/src/runtime/metrics/example_test.go
@@ -88,7 +88,7 @@ func medianBucket(h *metrics.Float64Histogram) float64 {
total = 0
for i, count := range h.Counts {
total += count
- if total > thresh {
+ if total >= thresh {
return h.Buckets[i]
}
}
diff --git a/src/syscall/exec_plan9.go b/src/syscall/exec_plan9.go
index 47ccbdc384..12c4237f69 100644
--- a/src/syscall/exec_plan9.go
+++ b/src/syscall/exec_plan9.go
@@ -320,14 +320,15 @@ func cexecPipe(p []int) error {
return e
}
- fd, e := Open("#d/"+itoa(p[1]), O_CLOEXEC)
+ fd, e := Open("#d/"+itoa(p[1]), O_RDWR|O_CLOEXEC)
if e != nil {
Close(p[0])
Close(p[1])
return e
}
- Close(fd)
+ Close(p[1])
+ p[1] = fd
return nil
}
diff --git a/src/testing/fstest/testfs.go b/src/testing/fstest/testfs.go
index a7f8007333..8fc8acaaf3 100644
--- a/src/testing/fstest/testfs.go
+++ b/src/testing/fstest/testfs.go
@@ -403,9 +403,10 @@ func (t *fsTester) checkStat(path string, entry fs.DirEntry) {
return
}
fentry := formatEntry(entry)
- finfo := formatInfoEntry(info)
- if fentry != finfo {
- t.errorf("%s: mismatch:\n\tentry = %s\n\tfile.Stat() = %s", path, fentry, finfo)
+ fientry := formatInfoEntry(info)
+ // Note: mismatch here is OK for symlink, because Open dereferences symlink.
+ if fentry != fientry && entry.Type()&fs.ModeSymlink == 0 {
+ t.errorf("%s: mismatch:\n\tentry = %s\n\tfile.Stat() = %s", path, fentry, fientry)
}
einfo, err := entry.Info()
@@ -413,12 +414,22 @@ func (t *fsTester) checkStat(path string, entry fs.DirEntry) {
t.errorf("%s: entry.Info: %v", path, err)
return
}
- fentry = formatInfo(einfo)
- finfo = formatInfo(info)
- if fentry != finfo {
- t.errorf("%s: mismatch:\n\tentry.Info() = %s\n\tfile.Stat() = %s\n", path, fentry, finfo)
+ finfo := formatInfo(info)
+ if entry.Type()&fs.ModeSymlink != 0 {
+ // For symlink, just check that entry.Info matches entry on common fields.
+ // Open deferences symlink, so info itself may differ.
+ feentry := formatInfoEntry(einfo)
+ if fentry != feentry {
+ t.errorf("%s: mismatch\n\tentry = %s\n\tentry.Info() = %s\n", path, fentry, feentry)
+ }
+ } else {
+ feinfo := formatInfo(einfo)
+ if feinfo != finfo {
+ t.errorf("%s: mismatch:\n\tentry.Info() = %s\n\tfile.Stat() = %s\n", path, feinfo, finfo)
+ }
}
+ // Stat should be the same as Open+Stat, even for symlinks.
info2, err := fs.Stat(t.fsys, path)
if err != nil {
t.errorf("%s: fs.Stat: %v", path, err)
diff --git a/src/testing/fstest/testfs_test.go b/src/testing/fstest/testfs_test.go
new file mode 100644
index 0000000000..5b8813c343
--- /dev/null
+++ b/src/testing/fstest/testfs_test.go
@@ -0,0 +1,31 @@
+// 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 fstest
+
+import (
+ "internal/testenv"
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+func TestSymlink(t *testing.T) {
+ testenv.MustHaveSymlink(t)
+
+ tmp := t.TempDir()
+ tmpfs := os.DirFS(tmp)
+
+ if err := os.WriteFile(filepath.Join(tmp, "hello"), []byte("hello, world\n"), 0644); err != nil {
+ t.Fatal(err)
+ }
+
+ if err := os.Symlink(filepath.Join(tmp, "hello"), filepath.Join(tmp, "hello.link")); err != nil {
+ t.Fatal(err)
+ }
+
+ if err := TestFS(tmpfs, "hello", "hello.link"); err != nil {
+ t.Fatal(err)
+ }
+}