libgo: update to go1.7rc3
Reviewed-on: https://go-review.googlesource.com/25150 From-SVN: r238662
This commit is contained in:
parent
9d04a3af4c
commit
22b955cca5
1155 changed files with 51833 additions and 16672 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Copyright 2009 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.
|
||||
|
||||
|
@ -48,18 +48,24 @@ var BigEndian bigEndian
|
|||
|
||||
type littleEndian struct{}
|
||||
|
||||
func (littleEndian) Uint16(b []byte) uint16 { return uint16(b[0]) | uint16(b[1])<<8 }
|
||||
func (littleEndian) Uint16(b []byte) uint16 {
|
||||
_ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint16(b[0]) | uint16(b[1])<<8
|
||||
}
|
||||
|
||||
func (littleEndian) PutUint16(b []byte, v uint16) {
|
||||
_ = b[1] // early bounds check to guarantee safety of writes below
|
||||
b[0] = byte(v)
|
||||
b[1] = byte(v >> 8)
|
||||
}
|
||||
|
||||
func (littleEndian) Uint32(b []byte) uint32 {
|
||||
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
|
||||
}
|
||||
|
||||
func (littleEndian) PutUint32(b []byte, v uint32) {
|
||||
_ = b[3] // early bounds check to guarantee safety of writes below
|
||||
b[0] = byte(v)
|
||||
b[1] = byte(v >> 8)
|
||||
b[2] = byte(v >> 16)
|
||||
|
@ -67,11 +73,13 @@ func (littleEndian) PutUint32(b []byte, v uint32) {
|
|||
}
|
||||
|
||||
func (littleEndian) Uint64(b []byte) uint64 {
|
||||
_ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
|
||||
uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
|
||||
}
|
||||
|
||||
func (littleEndian) PutUint64(b []byte, v uint64) {
|
||||
_ = b[7] // early bounds check to guarantee safety of writes below
|
||||
b[0] = byte(v)
|
||||
b[1] = byte(v >> 8)
|
||||
b[2] = byte(v >> 16)
|
||||
|
@ -88,18 +96,24 @@ func (littleEndian) GoString() string { return "binary.LittleEndian" }
|
|||
|
||||
type bigEndian struct{}
|
||||
|
||||
func (bigEndian) Uint16(b []byte) uint16 { return uint16(b[1]) | uint16(b[0])<<8 }
|
||||
func (bigEndian) Uint16(b []byte) uint16 {
|
||||
_ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint16(b[1]) | uint16(b[0])<<8
|
||||
}
|
||||
|
||||
func (bigEndian) PutUint16(b []byte, v uint16) {
|
||||
_ = b[1] // early bounds check to guarantee safety of writes below
|
||||
b[0] = byte(v >> 8)
|
||||
b[1] = byte(v)
|
||||
}
|
||||
|
||||
func (bigEndian) Uint32(b []byte) uint32 {
|
||||
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
|
||||
}
|
||||
|
||||
func (bigEndian) PutUint32(b []byte, v uint32) {
|
||||
_ = b[3] // early bounds check to guarantee safety of writes below
|
||||
b[0] = byte(v >> 24)
|
||||
b[1] = byte(v >> 16)
|
||||
b[2] = byte(v >> 8)
|
||||
|
@ -107,11 +121,13 @@ func (bigEndian) PutUint32(b []byte, v uint32) {
|
|||
}
|
||||
|
||||
func (bigEndian) Uint64(b []byte) uint64 {
|
||||
_ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
|
||||
return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
|
||||
uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
|
||||
}
|
||||
|
||||
func (bigEndian) PutUint64(b []byte, v uint64) {
|
||||
_ = b[7] // early bounds check to guarantee safety of writes below
|
||||
b[0] = byte(v >> 56)
|
||||
b[1] = byte(v >> 48)
|
||||
b[2] = byte(v >> 40)
|
||||
|
@ -253,7 +269,7 @@ func Write(w io.Writer, order ByteOrder, data interface{}) error {
|
|||
case *uint8:
|
||||
b[0] = *v
|
||||
case uint8:
|
||||
b[0] = byte(v)
|
||||
b[0] = v
|
||||
case []uint8:
|
||||
bs = v
|
||||
case *int16:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Copyright 2009 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.
|
||||
|
||||
|
@ -266,7 +266,7 @@ func TestBlankFields(t *testing.T) {
|
|||
}
|
||||
|
||||
// An attempt to read into a struct with an unexported field will
|
||||
// panic. This is probably not the best choice, but at this point
|
||||
// panic. This is probably not the best choice, but at this point
|
||||
// anything else would be an API change.
|
||||
|
||||
type Unexported struct {
|
||||
|
@ -339,6 +339,33 @@ func TestReadTruncated(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func testUint64SmallSliceLengthPanics() (panicked bool) {
|
||||
defer func() {
|
||||
panicked = recover() != nil
|
||||
}()
|
||||
b := [8]byte{1, 2, 3, 4, 5, 6, 7, 8}
|
||||
LittleEndian.Uint64(b[:4])
|
||||
return false
|
||||
}
|
||||
|
||||
func testPutUint64SmallSliceLengthPanics() (panicked bool) {
|
||||
defer func() {
|
||||
panicked = recover() != nil
|
||||
}()
|
||||
b := [8]byte{}
|
||||
LittleEndian.PutUint64(b[:4], 0x0102030405060708)
|
||||
return false
|
||||
}
|
||||
|
||||
func TestEarlyBoundsChecks(t *testing.T) {
|
||||
if testUint64SmallSliceLengthPanics() != true {
|
||||
t.Errorf("binary.LittleEndian.Uint64 expected to panic for small slices, but didn't")
|
||||
}
|
||||
if testPutUint64SmallSliceLengthPanics() != true {
|
||||
t.Errorf("binary.LittleEndian.PutUint64 expected to panic for small slices, but didn't")
|
||||
}
|
||||
}
|
||||
|
||||
type byteSliceReader struct {
|
||||
remain []byte
|
||||
}
|
||||
|
@ -373,8 +400,8 @@ func BenchmarkReadStruct(b *testing.B) {
|
|||
Read(bsr, BigEndian, &t)
|
||||
}
|
||||
b.StopTimer()
|
||||
if !reflect.DeepEqual(s, t) {
|
||||
b.Fatal("no match")
|
||||
if b.N > 0 && !reflect.DeepEqual(s, t) {
|
||||
b.Fatalf("struct doesn't match:\ngot %v;\nwant %v", t, s)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -405,8 +432,8 @@ func BenchmarkReadInts(b *testing.B) {
|
|||
want.Array[i] = 0
|
||||
}
|
||||
b.StopTimer()
|
||||
if !reflect.DeepEqual(ls, want) {
|
||||
panic("no match")
|
||||
if b.N > 0 && !reflect.DeepEqual(ls, want) {
|
||||
b.Fatalf("struct doesn't match:\ngot %v;\nwant %v", ls, want)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -427,7 +454,7 @@ func BenchmarkWriteInts(b *testing.B) {
|
|||
Write(w, BigEndian, s.Uint64)
|
||||
}
|
||||
b.StopTimer()
|
||||
if !bytes.Equal(buf.Bytes(), big[:30]) {
|
||||
if b.N > 0 && !bytes.Equal(buf.Bytes(), big[:30]) {
|
||||
b.Fatalf("first half doesn't match: %x %x", buf.Bytes(), big[:30])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Copyright 2011 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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue