Skip to content

Commit

Permalink
Merge pull request #93 from microsoft-golang-bot/auto-merge/microsoft…
Browse files Browse the repository at this point in the history
…/main

[`microsoft/main`] Merge upstream `master`
  • Loading branch information
microsoft-golang-review-bot committed Jun 7, 2021
2 parents 2a559c4 + 6d89da6 commit 38bbfb6
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 102 deletions.
6 changes: 3 additions & 3 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 Apr 28, 2021",
"Subtitle": "Version of Jun 2, 2021",
"Path": "/ref/spec"
}-->

Expand Down Expand Up @@ -4909,7 +4909,7 @@ <h3 id="Switch_statements">Switch statements</h3>

<p>
"Switch" statements provide multi-way execution.
An expression or type specifier is compared to the "cases"
An expression or type is compared to the "cases"
inside the "switch" to determine which branch
to execute.
</p>
Expand Down Expand Up @@ -5020,7 +5020,7 @@ <h4 id="Type_switches">Type switches</h4>
A type switch compares types rather than values. It is otherwise similar
to an expression switch. It is marked by a special switch expression that
has the form of a <a href="#Type_assertions">type assertion</a>
using the reserved word <code>type</code> rather than an actual type:
using the keyword <code>type</code> rather than an actual type:
</p>

<pre>
Expand Down
3 changes: 2 additions & 1 deletion misc/cgo/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func check(t *testing.T, file string) {
if len(frags) == 1 {
continue
}
re, err := regexp.Compile(string(frags[1]))
frag := fmt.Sprintf(":%d:.*%s", i+1, frags[1])
re, err := regexp.Compile(frag)
if err != nil {
t.Errorf("Invalid regexp after `ERROR HERE: `: %#q", frags[1])
continue
Expand Down
12 changes: 6 additions & 6 deletions misc/cgo/errors/testdata/err2.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ func main() {
C.foop = x // ERROR HERE

// issue 13129: used to output error about C.unsignedshort with CC=clang
var x C.ushort
x = int(0) // ERROR HERE: C\.ushort
var x1 C.ushort
x1 = int(0) // ERROR HERE: C\.ushort

// issue 13423
_ = C.fopen() // ERROR HERE

// issue 13467
var x rune = '✈'
var _ rune = C.transform(x) // ERROR HERE: C\.int
var x2 rune = '✈'
var _ rune = C.transform(x2) // ERROR HERE: C\.int

// issue 13635: used to output error about C.unsignedchar.
// This test tests all such types.
Expand Down Expand Up @@ -91,10 +91,10 @@ func main() {

// issue 26745
_ = func(i int) int {
return C.i + 1 // ERROR HERE: :13
return C.i + 1 // ERROR HERE: 14
}
_ = func(i int) {
C.fi(i) // ERROR HERE: :6
C.fi(i) // ERROR HERE: 7
}

C.fi = C.fi // ERROR HERE
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/abi/abiutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (config *ABIConfig) ABIAnalyze(t *types.Type, setNname bool) *ABIParamResul
// parameterUpdateMu protects the Offset field of function/method parameters (a subset of structure Fields)
var parameterUpdateMu sync.Mutex

// FieldOffsetOf returns a concurency-safe version of f.Offset
// FieldOffsetOf returns a concurrency-safe version of f.Offset
func FieldOffsetOf(f *types.Field) int64 {
parameterUpdateMu.Lock()
defer parameterUpdateMu.Unlock()
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/elliptic/elliptic.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func initP384() {
// Multiple invocations of this function will return the same value, so it can
// be used for equality checks and switch statements.
//
// The cryptographic operations are implemented using constant-time algorithms.
// ScalarMult and ScalarBaseMult are implemented using constant-time algorithms.
func P256() Curve {
initonce.Do(initAll)
return p256
Expand All @@ -479,7 +479,7 @@ func P384() Curve {
// Multiple invocations of this function will return the same value, so it can
// be used for equality checks and switch statements.
//
// The cryptographic operations do not use constant-time algorithms.
// The cryptographic operations are implemented using constant-time algorithms.
func P521() Curve {
initonce.Do(initAll)
return p521
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/tls/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ type Config struct {
// protocol will be one from this list, and the connection will fail
// if there is no mutually supported protocol. If NextProtos is empty
// or the peer doesn't support ALPN, the connection will succeed and
// ConnectionState.NegotiatedProtocol will be empty."
// ConnectionState.NegotiatedProtocol will be empty.
NextProtos []string

// ServerName is used to verify the hostname on the returned
Expand Down
4 changes: 2 additions & 2 deletions src/fmt/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
When printing a struct, fmt cannot and therefore does not invoke
formatting methods such as Error or String on unexported fields.
Explicit argument indexes:
Explicit argument indexes
In Printf, Sprintf, and Fprintf, the default behavior is for each
formatting verb to format successive arguments passed in the call.
Expand All @@ -211,7 +211,7 @@
fmt.Sprintf("%d %d %#[1]x %#x", 16, 17)
will yield "16 17 0x10 0x11".
Format errors:
Format errors
If an invalid argument is given for a verb, such as providing
a string to %d, the generated string will contain a
Expand Down
11 changes: 4 additions & 7 deletions src/go/internal/gcimporter/gcimporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,14 @@ func Import(fset *token.FileSet, packages map[string]*types.Package, path, srcDi
err = fmt.Errorf("import %q: old textual export format no longer supported (recompile library)", path)

case "$$B\n":
var data []byte
data, err = io.ReadAll(buf)
if err != nil {
break
}
var exportFormat byte
exportFormat, err = buf.ReadByte()

// The indexed export format starts with an 'i'; the older
// binary export format starts with a 'c', 'd', or 'v'
// (from "version"). Select appropriate importer.
if len(data) > 0 && data[0] == 'i' {
_, pkg, err = iImportData(fset, packages, data[1:], id)
if err == nil && exportFormat == 'i' {
pkg, err = iImportData(fset, packages, buf, id)
} else {
err = fmt.Errorf("import %q: old binary export format no longer supported (recompile library)", path)
}
Expand Down
21 changes: 11 additions & 10 deletions src/go/internal/gcimporter/iimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package gcimporter

import (
"bufio"
"bytes"
"encoding/binary"
"fmt"
Expand All @@ -20,7 +21,7 @@ import (
)

type intReader struct {
*bytes.Reader
*bufio.Reader
path string
}

Expand Down Expand Up @@ -61,7 +62,7 @@ const (
// and returns the number of bytes consumed and a reference to the package.
// If the export data version is not recognized or the format is otherwise
// compromised, an error is returned.
func iImportData(fset *token.FileSet, imports map[string]*types.Package, data []byte, path string) (_ int, pkg *types.Package, err error) {
func iImportData(fset *token.FileSet, imports map[string]*types.Package, dataReader *bufio.Reader, path string) (pkg *types.Package, err error) {
const currentVersion = 1
version := int64(-1)
defer func() {
Expand All @@ -74,7 +75,7 @@ func iImportData(fset *token.FileSet, imports map[string]*types.Package, data []
}
}()

r := &intReader{bytes.NewReader(data), path}
r := &intReader{dataReader, path}

version = int64(r.uint64())
switch version {
Expand All @@ -86,10 +87,12 @@ func iImportData(fset *token.FileSet, imports map[string]*types.Package, data []
sLen := int64(r.uint64())
dLen := int64(r.uint64())

whence, _ := r.Seek(0, io.SeekCurrent)
stringData := data[whence : whence+sLen]
declData := data[whence+sLen : whence+sLen+dLen]
r.Seek(sLen+dLen, io.SeekCurrent)
data := make([]byte, sLen+dLen)
if _, err := io.ReadFull(r, data); err != nil {
errorf("cannot read %d bytes of stringData and declData: %s", len(data), err)
}
stringData := data[:sLen]
declData := data[sLen:]

p := iimporter{
ipath: path,
Expand Down Expand Up @@ -165,9 +168,7 @@ func iImportData(fset *token.FileSet, imports map[string]*types.Package, data []

// package was imported completely and without errors
localpkg.MarkComplete()

consumed, _ := r.Seek(0, io.SeekCurrent)
return int(consumed), localpkg, nil
return localpkg, nil
}

type iimporter struct {
Expand Down
40 changes: 10 additions & 30 deletions src/net/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,37 +577,17 @@ func (w *response) ReadFrom(src io.Reader) (n int64, err error) {
return io.CopyBuffer(writerOnly{w}, src, buf)
}

// sendfile path:

// Do not start actually writing response until src is readable.
// If body length is <= sniffLen, sendfile/splice path will do
// little anyway. This small read also satisfies sniffing the
// body in case Content-Type is missing.
nr, er := src.Read(buf[:sniffLen])
atEOF := errors.Is(er, io.EOF)
n += int64(nr)

if nr > 0 {
// Write the small amount read normally.
nw, ew := w.Write(buf[:nr])
if ew != nil {
err = ew
} else if nr != nw {
err = io.ErrShortWrite
// Copy the first sniffLen bytes before switching to ReadFrom.
// This ensures we don't start writing the response before the
// source is available (see golang.org/issue/5660) and provides
// enough bytes to perform Content-Type sniffing when required.
if !w.cw.wroteHeader {
n0, err := io.CopyBuffer(writerOnly{w}, io.LimitReader(src, sniffLen), buf)
n += n0
if err != nil || n0 < sniffLen {
return n, err
}
}
if err == nil && er != nil && !atEOF {
err = er
}

// Do not send StatusOK in the error case where nothing has been written.
if err == nil && !w.wroteHeader {
w.WriteHeader(StatusOK) // nr == 0, no error (or EOF)
}

if err != nil || atEOF {
return n, err
}

w.w.Flush() // get rid of any previous writes
w.cw.flush() // make sure Header is written; flush data to rwc
Expand All @@ -620,7 +600,7 @@ func (w *response) ReadFrom(src io.Reader) (n int64, err error) {
return n, err
}

n0, err := io.Copy(writerOnly{w}, src)
n0, err := io.CopyBuffer(writerOnly{w}, src, buf)
n += n0
return n, err
}
Expand Down

0 comments on commit 38bbfb6

Please sign in to comment.