Skip to content

Commit

Permalink
[dev.boringcrypto] all: merge master into dev.boringcrypto
Browse files Browse the repository at this point in the history
Change-Id: Ic5f71c04f08c03319c043f35be501875adb0a3b0
  • Loading branch information
chressie committed Apr 27, 2022
2 parents ca6fd39 + f0ee7fd commit ec7f516
Show file tree
Hide file tree
Showing 204 changed files with 6,594 additions and 4,893 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.

Note that the Go project uses the issue tracker for bug reports and
proposals only. See https://golang.org/wiki/Questions for a list of
proposals only. See https://go.dev/wiki/Questions for a list of
places to ask questions about the Go language.

[rf]: https://reneefrench.blogspot.com/
Expand Down
8 changes: 4 additions & 4 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

## Supported Versions

We support the past two Go releases (for example, Go 1.12.x and Go 1.13.x).
We support the past two Go releases (for example, Go 1.17.x and Go 1.18.x when Go 1.18.x is the latest stable release).

See https://golang.org/wiki/Go-Release-Cycle and in particular the
[Release Maintenance](https://github.com/golang/go/wiki/Go-Release-Cycle#release-maintenance)
See https://go.dev/wiki/Go-Release-Cycle and in particular the
[Release Maintenance](https://go.dev/wiki/Go-Release-Cycle#release-maintenance)
part of that page.

## Reporting a Vulnerability

See https://golang.org/security for how to report a vulnerability.
See https://go.dev/security for how to report a vulnerability.
3 changes: 3 additions & 0 deletions api/next/30715.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg net/http, type MaxBytesError struct #30715
pkg net/http, type MaxBytesError struct, Limit int64 #30715
pkg net/http, method (*MaxBytesError) Error() string #30715
1 change: 1 addition & 0 deletions api/next/50599.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg os/exec, method (*Cmd) Environ() []string #50599
2 changes: 2 additions & 0 deletions api/next/51684.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pkg regexp/syntax, const ErrNestingDepth = "expression nests too deeply" #51684
pkg regexp/syntax, const ErrNestingDepth ErrorCode #51684
3 changes: 0 additions & 3 deletions api/next/regexpdepth.txt

This file was deleted.

25 changes: 25 additions & 0 deletions doc/go1.19.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
TODO: complete this section
</p>

<dl id="crypto/tls"><dt><a href="/pkg/crypto/tls/">crypto/tls</a></dt>
<dd>
<p><!-- CL 400974 -->
The <code>tls10default</code> <code>GODEBUG</code> option has been
removed. It is still possible to enable TLS 1.0 client-side by setting
<code>Config.MinVersion</code>.
</p>
</dd>
</dl><!-- crypto/tls -->

<dl id="image/draw"><dt><a href="/pkg/image/draw/">image/draw</a></dt>
<dd>
<p><!-- CL 396795 -->
Expand Down Expand Up @@ -132,6 +142,21 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
</dd>
</dl><!-- net -->

<dl id="os/exec"><dt><a href="/pkg/os/exec/">os/exec</a></dt>
<dd><!-- https://go.dev/issue/50599 -->
<p>
An <code>exec.Cmd</code> with a non-empty <code>Dir</code> and a
nil <code>Env</code> now implicitly sets the <code>PWD</code> environment
variable for the subprocess to match <code>Dir</code>.
</p>
<p>
The new method <code>(*exec.Cmd).Environ</code> reports the
environment that would be used to run the command, including the
aforementioned <code>PWD</code> variable.
</p>
</dd>
</dl> <!-- os/exec -->

<dl id="runtime"><dt><a href="/pkg/runtime/">runtime</a></dt>
<dd>
<p><!-- https://go.dev/issue/51461 -->
Expand Down
18 changes: 14 additions & 4 deletions doc/go_spec.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of March 30, 2022",
"Subtitle": "Version of April 19, 2022",
"Path": "/ref/spec"
}-->

Expand Down Expand Up @@ -1278,7 +1278,8 @@ <h4 id="Basic_interfaces">Basic interfaces</h4>
<p>
Every type that is a member of the type set of an interface implements that interface.
Any given type may implement several distinct interfaces.
For instance, all types implement the <i>empty interface</i> which stands for the set of all types:
For instance, all types implement the <i>empty interface</i> which stands for the set
of all (non-interface) types:
</p>

<pre>
Expand Down Expand Up @@ -1380,7 +1381,7 @@ <h4 id="General_interfaces">General interfaces</h4>
of its interface elements.
</li>

<li>The type set of a method specification is the set of types
<li>The type set of a method specification is the set of all non-interface types
whose method sets include that method.
</li>

Expand All @@ -1389,7 +1390,7 @@ <h4 id="General_interfaces">General interfaces</h4>
</li>

<li>The type set of a term of the form <code>~T</code>
is the set of types whose underlying type is <code>T</code>.
is the set of all types whose underlying type is <code>T</code>.
</li>

<li>The type set of a <i>union</i> of terms
Expand All @@ -1398,6 +1399,15 @@ <h4 id="General_interfaces">General interfaces</h4>
</li>
</ul>

<p>
The quantification "the set of all non-interface types" refers not just to all (non-interface)
types declared in the program at hand, but all possible types in all possible programs, and
hence is infinite.
Similarly, given the set of all non-interface types that implement a particular method, the
intersection of the method sets of those types will contain exactly that method, even if all
types in the program at hand always pair that method with another method.
</p>

<p>
By construction, an interface's type set never contains an interface type.
</p>
Expand Down
31 changes: 4 additions & 27 deletions misc/cgo/test/callback_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
// license that can be found in the LICENSE file.

#include <string.h>
#include <sys/types.h>
#include <unistd.h>

#include "_cgo_export.h"

void
Expand All @@ -31,32 +30,10 @@ IntoC(void)
BackIntoGo();
}

#ifdef WIN32
#include <windows.h>
long long
mysleep(int seconds) {
long long st = GetTickCount();
Sleep(1000 * seconds);
return st;
}
#else
#include <sys/time.h>
long long
mysleep(int seconds) {
long long st;
struct timeval tv;
gettimeofday(&tv, NULL);
st = tv.tv_sec * 1000 + tv.tv_usec / 1000;
sleep(seconds);
return st;
}
#endif

long long
twoSleep(int n)
void
Issue1560InC(void)
{
BackgroundSleep(n);
return mysleep(n);
Issue1560FromC();
}

void
Expand Down
2 changes: 1 addition & 1 deletion misc/cgo/test/cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "testing"
// These wrappers are here for gotest to find.

func Test1328(t *testing.T) { test1328(t) }
func Test1560(t *testing.T) { test1560(t) }
func Test1635(t *testing.T) { test1635(t) }
func Test3250(t *testing.T) { test3250(t) }
func Test3729(t *testing.T) { test3729(t) }
Expand Down Expand Up @@ -89,7 +90,6 @@ func TestLibgcc(t *testing.T) { testLibgcc(t) }
func TestMultipleAssign(t *testing.T) { testMultipleAssign(t) }
func TestNaming(t *testing.T) { testNaming(t) }
func TestPanicFromC(t *testing.T) { testPanicFromC(t) }
func TestParallelSleep(t *testing.T) { testParallelSleep(t) }
func TestPrintf(t *testing.T) { testPrintf(t) }
func TestReturnAfterGrow(t *testing.T) { testReturnAfterGrow(t) }
func TestReturnAfterGrowFromGo(t *testing.T) { testReturnAfterGrowFromGo(t) }
Expand Down
53 changes: 28 additions & 25 deletions misc/cgo/test/testx.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"sync"
"sync/atomic"
"testing"
"time"
"unsafe"
)

Expand All @@ -30,8 +29,7 @@ extern void doAdd(int, int);
void IntoC(void);
// issue 1560
// mysleep returns the absolute start time in ms.
long long mysleep(int seconds);
extern void Issue1560InC(void);
// twoSleep returns the absolute start time of the first sleep
// in ms.
Expand Down Expand Up @@ -183,35 +181,40 @@ func test1328(t *testing.T) {
}

// issue 1560
// Test that C functions and Go functions run in parallel.

var sleepDone = make(chan int64)
var (
issue1560 int32

// parallelSleep returns the absolute difference between the start time
// of the two sleeps.
func parallelSleep(n int) int64 {
t := int64(C.twoSleep(C.int(n))) - <-sleepDone
if t < 0 {
return -t
issue1560Ch = make(chan bool, 2)
)

//export Issue1560FromC
func Issue1560FromC() {
for atomic.LoadInt32(&issue1560) != 1 {
runtime.Gosched()
}
atomic.AddInt32(&issue1560, 1)
for atomic.LoadInt32(&issue1560) != 3 {
runtime.Gosched()
}
return t
issue1560Ch <- true
}

//export BackgroundSleep
func BackgroundSleep(n int32) {
go func() {
sleepDone <- int64(C.mysleep(C.int(n)))
}()
func Issue1560FromGo() {
atomic.AddInt32(&issue1560, 1)
for atomic.LoadInt32(&issue1560) != 2 {
runtime.Gosched()
}
atomic.AddInt32(&issue1560, 1)
issue1560Ch <- true
}

func testParallelSleep(t *testing.T) {
sleepSec := 1
dt := time.Duration(parallelSleep(sleepSec)) * time.Millisecond
t.Logf("difference in start time for two sleep(%d) is %v", sleepSec, dt)
// bug used to run sleeps in serial, producing a 2*sleepSec-second delay.
// we detect if the start times of those sleeps are > 0.5*sleepSec-second.
if dt >= time.Duration(sleepSec)*time.Second/2 {
t.Fatalf("parallel %d-second sleeps slept for %f seconds", sleepSec, dt.Seconds())
}
func test1560(t *testing.T) {
go Issue1560FromGo()
go C.Issue1560InC()
<-issue1560Ch
<-issue1560Ch
}

// issue 2462
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap.bash
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ if [ "$BOOTSTRAP_FORMAT" = "mintgz" ]; then
echo "Preparing to generate build system's ${OUTGZ}; cleaning ..."
rm -rf bin/gofmt
rm -rf src/runtime/race/race_*.syso
rm -rf api test doc misc/cgo/test misc/trace
rm -rf api test doc misc/cgo/test
rm -rf pkg/tool/*_*/{addr2line,api,cgo,cover,doc,fix,nm,objdump,pack,pprof,test2json,trace,vet}
rm -rf pkg/*_*/{image,database,cmd}
rm -rf $(find . -type d -name testdata)
Expand Down
21 changes: 18 additions & 3 deletions src/bufio/bufio.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,13 +731,28 @@ func (b *Writer) WriteRune(r rune) (size int, err error) {
// If the count is less than len(s), it also returns an error explaining
// why the write is short.
func (b *Writer) WriteString(s string) (int, error) {
var sw io.StringWriter
tryStringWriter := true

nn := 0
for len(s) > b.Available() && b.err == nil {
n := copy(b.buf[b.n:], s)
b.n += n
var n int
if b.Buffered() == 0 && sw == nil && tryStringWriter {
// Check at most once whether b.wr is a StringWriter.
sw, tryStringWriter = b.wr.(io.StringWriter)
}
if b.Buffered() == 0 && tryStringWriter {
// Large write, empty buffer, and the underlying writer supports
// WriteString: forward the write to the underlying StringWriter.
// This avoids an extra copy.
n, b.err = sw.WriteString(s)
} else {
n = copy(b.buf[b.n:], s)
b.n += n
b.Flush()
}
nn += n
s = s[n:]
b.Flush()
}
if b.err != nil {
return nn, b.err
Expand Down
61 changes: 61 additions & 0 deletions src/bufio/bufio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,67 @@ func TestWriteString(t *testing.T) {
}
}

func TestWriteStringStringWriter(t *testing.T) {
const BufSize = 8
{
tw := &teststringwriter{}
b := NewWriterSize(tw, BufSize)
b.WriteString("1234")
tw.check(t, "", "")
b.WriteString("56789012") // longer than BufSize
tw.check(t, "12345678", "") // but not enough (after filling the partially-filled buffer)
b.Flush()
tw.check(t, "123456789012", "")
}
{
tw := &teststringwriter{}
b := NewWriterSize(tw, BufSize)
b.WriteString("123456789") // long string, empty buffer:
tw.check(t, "", "123456789") // use WriteString
}
{
tw := &teststringwriter{}
b := NewWriterSize(tw, BufSize)
b.WriteString("abc")
tw.check(t, "", "")
b.WriteString("123456789012345") // long string, non-empty buffer
tw.check(t, "abc12345", "6789012345") // use Write and then WriteString since the remaining part is still longer than BufSize
}
{
tw := &teststringwriter{}
b := NewWriterSize(tw, BufSize)
b.Write([]byte("abc")) // same as above, but use Write instead of WriteString
tw.check(t, "", "")
b.WriteString("123456789012345")
tw.check(t, "abc12345", "6789012345") // same as above
}
}

type teststringwriter struct {
write string
writeString string
}

func (w *teststringwriter) Write(b []byte) (int, error) {
w.write += string(b)
return len(b), nil
}

func (w *teststringwriter) WriteString(s string) (int, error) {
w.writeString += s
return len(s), nil
}

func (w *teststringwriter) check(t *testing.T, write, writeString string) {
t.Helper()
if w.write != write {
t.Errorf("write: expected %q, got %q", write, w.write)
}
if w.writeString != writeString {
t.Errorf("writeString: expected %q, got %q", writeString, w.writeString)
}
}

func TestBufferFull(t *testing.T) {
const longString = "And now, hello, world! It is the time for all good men to come to the aid of their party"
buf := NewReaderSize(strings.NewReader(longString), minReadBufferSize)
Expand Down
Loading

0 comments on commit ec7f516

Please sign in to comment.