libgo: Update to weekly 2011-11-09.
From-SVN: r182073
This commit is contained in:
parent
374280238f
commit
9c63abc9a1
386 changed files with 4963 additions and 2370 deletions
|
@ -18,7 +18,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"template"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"cmath"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/cmplx"
|
||||
)
|
||||
|
||||
type Test struct{
|
||||
f, g complex128
|
||||
out complex128
|
||||
type Test struct {
|
||||
f, g complex128
|
||||
out complex128
|
||||
}
|
||||
|
||||
var nan = math.NaN()
|
||||
|
@ -25,9 +25,9 @@ var negzero = math.Copysign(0, -1)
|
|||
|
||||
func calike(a, b complex128) bool {
|
||||
switch {
|
||||
case cmath.IsInf(a) && cmath.IsInf(b):
|
||||
case cmplx.IsInf(a) && cmplx.IsInf(b):
|
||||
return true
|
||||
case cmath.IsNaN(a) && cmath.IsNaN(b):
|
||||
case cmplx.IsNaN(a) && cmplx.IsNaN(b):
|
||||
return true
|
||||
}
|
||||
return a == b
|
||||
|
@ -36,7 +36,7 @@ func calike(a, b complex128) bool {
|
|||
func main() {
|
||||
bad := false
|
||||
for _, t := range tests {
|
||||
x := t.f/t.g
|
||||
x := t.f / t.g
|
||||
if !calike(x, t.out) {
|
||||
if !bad {
|
||||
fmt.Printf("BUG\n")
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"http"
|
||||
"io/ioutil" // GCCGO_ERROR "imported and not used"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
package main
|
||||
|
||||
import "rand"
|
||||
import "math/rand"
|
||||
|
||||
const Count = 1e5
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
package main
|
||||
|
||||
import "rand"
|
||||
import "math/rand"
|
||||
|
||||
const Count = 1e5
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"rand"
|
||||
"math/rand"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
|
|
@ -9,28 +9,29 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"utf8"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe\U0010FFFFx"
|
||||
expect := []int{ 0, 0123, 0, 0xFFFD, 0xFFFD, 0x123, 0xbabe, 0xbabe, 0x10FFFF, 'x' }
|
||||
expect := []rune{0, 0123, 0, 0xFFFD, 0xFFFD, 0x123, 0xbabe, 0xbabe, 0x10FFFF, 'x'}
|
||||
offset := 0
|
||||
var i, c int
|
||||
var i int
|
||||
var c rune
|
||||
ok := true
|
||||
cnum := 0
|
||||
for i, c = range s {
|
||||
rune, size := utf8.DecodeRuneInString(s[i:len(s)]) // check it another way
|
||||
r, size := utf8.DecodeRuneInString(s[i:len(s)]) // check it another way
|
||||
if i != offset {
|
||||
fmt.Printf("unexpected offset %d not %d\n", i, offset)
|
||||
ok = false
|
||||
}
|
||||
if rune != expect[cnum] {
|
||||
fmt.Printf("unexpected rune %d from DecodeRuneInString: %x not %x\n", i, rune, expect[cnum])
|
||||
if r != expect[cnum] {
|
||||
fmt.Printf("unexpected rune %d from DecodeRuneInString: %x not %x\n", i, r, expect[cnum])
|
||||
ok = false
|
||||
}
|
||||
if c != expect[cnum] {
|
||||
fmt.Printf("unexpected rune %d from range: %x not %x\n", i, rune, expect[cnum])
|
||||
fmt.Printf("unexpected rune %d from range: %x not %x\n", i, r, expect[cnum])
|
||||
ok = false
|
||||
}
|
||||
offset += size
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
package main
|
||||
|
||||
import "utf8"
|
||||
import "unicode/utf8"
|
||||
|
||||
func main() {
|
||||
var chars [6] int
|
||||
var chars [6]rune
|
||||
chars[0] = 'a'
|
||||
chars[1] = 'b'
|
||||
chars[2] = 'c'
|
||||
|
@ -21,16 +21,22 @@ func main() {
|
|||
s += string(chars[i])
|
||||
}
|
||||
var l = len(s)
|
||||
for w, i, j := 0,0,0; i < l; i += w {
|
||||
var r int
|
||||
for w, i, j := 0, 0, 0; i < l; i += w {
|
||||
var r rune
|
||||
r, w = utf8.DecodeRuneInString(s[i:len(s)])
|
||||
if w == 0 { panic("zero width in string") }
|
||||
if r != chars[j] { panic("wrong value from string") }
|
||||
if w == 0 {
|
||||
panic("zero width in string")
|
||||
}
|
||||
if r != chars[j] {
|
||||
panic("wrong value from string")
|
||||
}
|
||||
j++
|
||||
}
|
||||
// encoded as bytes: 'a' 'b' 'c' e6 97 a5 e6 9c ac e8 aa 9e
|
||||
const L = 12
|
||||
if L != l { panic("wrong length constructing array") }
|
||||
if L != l {
|
||||
panic("wrong length constructing array")
|
||||
}
|
||||
a := make([]byte, L)
|
||||
a[0] = 'a'
|
||||
a[1] = 'b'
|
||||
|
@ -44,11 +50,15 @@ func main() {
|
|||
a[9] = 0xe8
|
||||
a[10] = 0xaa
|
||||
a[11] = 0x9e
|
||||
for w, i, j := 0,0,0; i < L; i += w {
|
||||
var r int
|
||||
for w, i, j := 0, 0, 0; i < L; i += w {
|
||||
var r rune
|
||||
r, w = utf8.DecodeRune(a[i:L])
|
||||
if w == 0 { panic("zero width in bytes") }
|
||||
if r != chars[j] { panic("wrong value from bytes") }
|
||||
if w == 0 {
|
||||
panic("zero width in bytes")
|
||||
}
|
||||
if r != chars[j] {
|
||||
panic("wrong value from bytes")
|
||||
}
|
||||
j++
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
780c85032b17
|
||||
2f4482b89a6b
|
||||
|
||||
The first line of this file holds the Mercurial revision number of the
|
||||
last merge done from the master library sources.
|
||||
|
|
1163
libgo/Makefile.am
1163
libgo/Makefile.am
File diff suppressed because it is too large
Load diff
1586
libgo/Makefile.in
1586
libgo/Makefile.in
File diff suppressed because it is too large
Load diff
|
@ -29,7 +29,7 @@ var (
|
|||
// tr := tar.NewReader(r)
|
||||
// for {
|
||||
// hdr, err := tr.Next()
|
||||
// if err == os.EOF {
|
||||
// if err == io.EOF {
|
||||
// // end of tar archive
|
||||
// break
|
||||
// }
|
||||
|
@ -200,7 +200,7 @@ func (tr *Reader) readHeader() *Header {
|
|||
}
|
||||
|
||||
// Read reads from the current entry in the tar archive.
|
||||
// It returns 0, os.EOF when it reaches the end of that entry,
|
||||
// It returns 0, io.EOF when it reaches the end of that entry,
|
||||
// until Next is called to advance to the next entry.
|
||||
func (tr *Reader) Read(b []byte) (n int, err error) {
|
||||
if tr.nb == 0 {
|
||||
|
|
|
@ -7,10 +7,10 @@ package zip
|
|||
import (
|
||||
"bufio"
|
||||
"compress/flate"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"hash"
|
||||
"hash/crc32"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -60,6 +60,7 @@ func OpenReader(name string) (*ReadCloser, error) {
|
|||
f.Close()
|
||||
return nil, err
|
||||
}
|
||||
r.f = f
|
||||
return r, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,11 @@ func readTestZip(t *testing.T, zt ZipTest) {
|
|||
if err == FormatError {
|
||||
return
|
||||
}
|
||||
defer z.Close()
|
||||
defer func() {
|
||||
if err := z.Close(); err != nil {
|
||||
t.Errorf("error %q when closing zip file", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// bail here if no Files expected to be tested
|
||||
// (there may actually be files in the zip, but we don't care)
|
||||
|
|
|
@ -7,7 +7,7 @@ package zip
|
|||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"rand"
|
||||
"math/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"bytes"
|
||||
"io"
|
||||
"strconv"
|
||||
"utf8"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -135,7 +135,7 @@ func (b *Reader) Peek(n int) ([]byte, error) {
|
|||
// It returns the number of bytes read into p.
|
||||
// It calls Read at most once on the underlying Reader,
|
||||
// hence n may be less than len(p).
|
||||
// At EOF, the count will be zero and err will be os.EOF.
|
||||
// At EOF, the count will be zero and err will be io.EOF.
|
||||
func (b *Reader) Read(p []byte) (n int, err error) {
|
||||
n = len(p)
|
||||
if n == 0 {
|
||||
|
@ -246,7 +246,7 @@ func (b *Reader) Buffered() int { return b.w - b.r }
|
|||
// returning a slice pointing at the bytes in the buffer.
|
||||
// The bytes stop being valid at the next read call.
|
||||
// If ReadSlice encounters an error before finding a delimiter,
|
||||
// it returns all the data in the buffer and the error itself (often os.EOF).
|
||||
// it returns all the data in the buffer and the error itself (often io.EOF).
|
||||
// ReadSlice fails with error ErrBufferFull if the buffer fills without a delim.
|
||||
// Because the data returned from ReadSlice will be overwritten
|
||||
// by the next I/O operation, most clients should use
|
||||
|
@ -312,6 +312,9 @@ func (b *Reader) ReadLine() (line []byte, isPrefix bool, err error) {
|
|||
}
|
||||
|
||||
if len(line) == 0 {
|
||||
if err != nil {
|
||||
line = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
err = nil
|
||||
|
@ -329,7 +332,7 @@ func (b *Reader) ReadLine() (line []byte, isPrefix bool, err error) {
|
|||
// ReadBytes reads until the first occurrence of delim in the input,
|
||||
// returning a slice containing the data up to and including the delimiter.
|
||||
// If ReadBytes encounters an error before finding a delimiter,
|
||||
// it returns the data read before the error and the error itself (often os.EOF).
|
||||
// it returns the data read before the error and the error itself (often io.EOF).
|
||||
// ReadBytes returns err != nil if and only if the returned data does not end in
|
||||
// delim.
|
||||
func (b *Reader) ReadBytes(delim byte) (line []byte, err error) {
|
||||
|
@ -376,7 +379,7 @@ func (b *Reader) ReadBytes(delim byte) (line []byte, err error) {
|
|||
// ReadString reads until the first occurrence of delim in the input,
|
||||
// returning a string containing the data up to and including the delimiter.
|
||||
// If ReadString encounters an error before finding a delimiter,
|
||||
// it returns the data read before the error and the error itself (often os.EOF).
|
||||
// it returns the data read before the error and the error itself (often io.EOF).
|
||||
// ReadString returns err != nil if and only if the returned data does not end in
|
||||
// delim.
|
||||
func (b *Reader) ReadString(delim byte) (line string, err error) {
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
"testing/iotest"
|
||||
"utf8"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Reads from a reader and rot13s the result.
|
||||
|
@ -698,6 +698,17 @@ func TestLinesAfterRead(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestReadLineNonNilLineOrError(t *testing.T) {
|
||||
r := NewReader(strings.NewReader("line 1\n"))
|
||||
for i := 0; i < 2; i++ {
|
||||
l, _, err := r.ReadLine()
|
||||
if l != nil && err != nil {
|
||||
t.Fatalf("on line %d/2; ReadLine=%#v, %v; want non-nil line or Error, but not both",
|
||||
i+1, l, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type readLineResult struct {
|
||||
line []byte
|
||||
isPrefix bool
|
||||
|
|
|
@ -3,13 +3,89 @@
|
|||
// license that can be found in the LICENSE file.
|
||||
|
||||
/*
|
||||
Package builtin provides documentation for Go's built-in functions.
|
||||
The functions documented here are not actually in package builtin
|
||||
Package builtin provides documentation for Go's predeclared identifiers.
|
||||
The items documented here are not actually in package builtin
|
||||
but their descriptions here allow godoc to present documentation
|
||||
for the language's special functions.
|
||||
for the language's special identifiers.
|
||||
*/
|
||||
package builtin
|
||||
|
||||
// bool is the set of boolean values, true and false.
|
||||
type bool bool
|
||||
|
||||
// uint8 is the set of all unsigned 8-bit integers.
|
||||
// Range: 0 through 255.
|
||||
type uint8 uint8
|
||||
|
||||
// uint16 is the set of all unsigned 16-bit integers.
|
||||
// Range: 0 through 65535.
|
||||
type uint16 uint16
|
||||
|
||||
// uint32 is the set of all unsigned 32-bit integers.
|
||||
// Range: 0 through 4294967295.
|
||||
type uint32 uint32
|
||||
|
||||
// uint64 is the set of all unsigned 64-bit integers.
|
||||
// Range: 0 through 18446744073709551615.
|
||||
type uint64 uint64
|
||||
|
||||
// int8 is the set of all signed 8-bit integers.
|
||||
// Range: -128 through 127.
|
||||
type int8 int8
|
||||
|
||||
// int16 is the set of all signed 16-bit integers.
|
||||
// Range: -32768 through 32767.
|
||||
type int16 int16
|
||||
|
||||
// int32 is the set of all signed 32-bit integers.
|
||||
// Range: -2147483648 through 2147483647.
|
||||
type int32 int32
|
||||
|
||||
// int64 is the set of all signed 64-bit integers.
|
||||
// Range: -9223372036854775808 through 9223372036854775807.
|
||||
type int64 int64
|
||||
|
||||
// float32 is the set of all IEEE-754 32-bit floating-point numbers.
|
||||
type float32 float32
|
||||
|
||||
// float64 is the set of all IEEE-754 64-bit floating-point numbers.
|
||||
type float64 float64
|
||||
|
||||
// complex64 is the set of all complex numbers with float32 real and
|
||||
// imaginary parts.
|
||||
type complex64 complex64
|
||||
|
||||
// complex128 is the set of all complex numbers with float64 real and
|
||||
// imaginary parts.
|
||||
type complex128 complex128
|
||||
|
||||
// string is the set of all strings of 8-bit bytes, conventionally but not
|
||||
// necessarily representing UTF-8-encoded text. A string may be empty, but
|
||||
// not nil. Values of string type are immutable.
|
||||
type string string
|
||||
|
||||
// int is a signed integer type that is at least 32 bits in size. It is a
|
||||
// distinct type, however, and not an alias for, say, int32.
|
||||
type int int
|
||||
|
||||
// uint is an unsigned integer type that is at least 32 bits in size. It is a
|
||||
// distinct type, however, and not an alias for, say, uint32.
|
||||
type uint uint
|
||||
|
||||
// uintptr is an integer type that is large enough to hold the bit pattern of
|
||||
// any pointer.
|
||||
type uintptr uintptr
|
||||
|
||||
// byte is an alias for uint8 and is equivalent to uint8 in all ways. It is
|
||||
// used, by convention, to distinguish byte values from 8-bit unsigned
|
||||
// integer values.
|
||||
type byte byte
|
||||
|
||||
// rune is an alias for int and is equivalent to int in all ways. It is
|
||||
// used, by convention, to distinguish character values from integer values.
|
||||
// In a future version of Go, it will change to an alias of int32.
|
||||
type rune rune
|
||||
|
||||
// Type is here for the purposes of documentation only. It is a stand-in
|
||||
// for any Go type, but represents the same type for any given function
|
||||
// invocation.
|
||||
|
@ -21,11 +97,11 @@ type IntegerType int
|
|||
|
||||
// FloatType is here for the purposes of documentation only. It is a stand-in
|
||||
// for either float type: float32 or float64.
|
||||
type FloatType int
|
||||
type FloatType float32
|
||||
|
||||
// ComplexType is here for the purposes of documentation only. It is a
|
||||
// stand-in for either complex type: complex64 or complex128.
|
||||
type ComplexType int
|
||||
type ComplexType complex64
|
||||
|
||||
// The append built-in function appends elements to the end of a slice. If
|
||||
// it has sufficient capacity, the destination is resliced to accommodate the
|
||||
|
@ -133,3 +209,9 @@ func panic(v interface{})
|
|||
// nil. Thus the return value from recover reports whether the goroutine is
|
||||
// panicking.
|
||||
func recover() interface{}
|
||||
|
||||
// The error built-in interface type is the conventional interface for
|
||||
// representing an error condition, with the nil value representing no error.
|
||||
type error interface {
|
||||
Error() string
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ package bytes
|
|||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"utf8"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// A Buffer is a variable-sized buffer of bytes with Read and Write methods.
|
||||
|
@ -117,7 +117,7 @@ const MinRead = 512
|
|||
|
||||
// ReadFrom reads data from r until EOF and appends it to the buffer.
|
||||
// The return value n is the number of bytes read.
|
||||
// Any error except os.EOF encountered during the read
|
||||
// Any error except io.EOF encountered during the read
|
||||
// is also returned.
|
||||
func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
b.lastRead = opInvalid
|
||||
|
@ -200,7 +200,7 @@ func (b *Buffer) WriteRune(r rune) (n int, err error) {
|
|||
|
||||
// Read reads the next len(p) bytes from the buffer or until the buffer
|
||||
// is drained. The return value n is the number of bytes read. If the
|
||||
// buffer has no data to return, err is os.EOF even if len(p) is zero;
|
||||
// buffer has no data to return, err is io.EOF even if len(p) is zero;
|
||||
// otherwise it is nil.
|
||||
func (b *Buffer) Read(p []byte) (n int, err error) {
|
||||
b.lastRead = opInvalid
|
||||
|
@ -236,7 +236,7 @@ func (b *Buffer) Next(n int) []byte {
|
|||
}
|
||||
|
||||
// ReadByte reads and returns the next byte from the buffer.
|
||||
// If no byte is available, it returns error os.EOF.
|
||||
// If no byte is available, it returns error io.EOF.
|
||||
func (b *Buffer) ReadByte() (c byte, err error) {
|
||||
b.lastRead = opInvalid
|
||||
if b.off >= len(b.buf) {
|
||||
|
@ -252,7 +252,7 @@ func (b *Buffer) ReadByte() (c byte, err error) {
|
|||
|
||||
// ReadRune reads and returns the next UTF-8-encoded
|
||||
// Unicode code point from the buffer.
|
||||
// If no bytes are available, the error returned is os.EOF.
|
||||
// If no bytes are available, the error returned is io.EOF.
|
||||
// If the bytes are an erroneous UTF-8 encoding, it
|
||||
// consumes one byte and returns U+FFFD, 1.
|
||||
func (b *Buffer) ReadRune() (r rune, size int, err error) {
|
||||
|
@ -307,7 +307,7 @@ func (b *Buffer) UnreadByte() error {
|
|||
// ReadBytes reads until the first occurrence of delim in the input,
|
||||
// returning a slice containing the data up to and including the delimiter.
|
||||
// If ReadBytes encounters an error before finding a delimiter,
|
||||
// it returns the data read before the error and the error itself (often os.EOF).
|
||||
// it returns the data read before the error and the error itself (often io.EOF).
|
||||
// ReadBytes returns err != nil if and only if the returned data does not end in
|
||||
// delim.
|
||||
func (b *Buffer) ReadBytes(delim byte) (line []byte, err error) {
|
||||
|
@ -326,7 +326,7 @@ func (b *Buffer) ReadBytes(delim byte) (line []byte, err error) {
|
|||
// ReadString reads until the first occurrence of delim in the input,
|
||||
// returning a string containing the data up to and including the delimiter.
|
||||
// If ReadString encounters an error before finding a delimiter,
|
||||
// it returns the data read before the error and the error itself (often os.EOF).
|
||||
// it returns the data read before the error and the error itself (often io.EOF).
|
||||
// ReadString returns err != nil if and only if the returned data does not end
|
||||
// in delim.
|
||||
func (b *Buffer) ReadString(delim byte) (line string, err error) {
|
||||
|
|
|
@ -7,9 +7,9 @@ package bytes_test
|
|||
import (
|
||||
. "bytes"
|
||||
"io"
|
||||
"rand"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"utf8"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const N = 10000 // make this bigger for a larger (and slower) test
|
||||
|
|
|
@ -8,7 +8,7 @@ package bytes
|
|||
|
||||
import (
|
||||
"unicode"
|
||||
"utf8"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Compare returns an integer comparing the two byte arrays lexicographically.
|
||||
|
@ -88,6 +88,11 @@ func Count(s, sep []byte) int {
|
|||
return n
|
||||
}
|
||||
|
||||
// Contains returns whether subslice is within b.
|
||||
func Contains(b, subslice []byte) bool {
|
||||
return Index(b, subslice) != -1
|
||||
}
|
||||
|
||||
// Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
|
||||
func Index(s, sep []byte) int {
|
||||
n := len(sep)
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
"unicode"
|
||||
"utf8"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func eq(a, b []string) bool {
|
||||
|
|
|
@ -37,7 +37,7 @@ func newBitReader(r io.Reader) bitReader {
|
|||
|
||||
// ReadBits64 reads the given number of bits and returns them in the
|
||||
// least-significant part of a uint64. In the event of an error, it returns 0
|
||||
// and the error can be obtained by calling Error().
|
||||
// and the error can be obtained by calling Err().
|
||||
func (br *bitReader) ReadBits64(bits uint) (n uint64) {
|
||||
for bits > br.bits {
|
||||
b, err := br.r.ReadByte()
|
||||
|
@ -82,6 +82,6 @@ func (br *bitReader) ReadBit() bool {
|
|||
return n != 0
|
||||
}
|
||||
|
||||
func (br *bitReader) Error() error {
|
||||
func (br *bitReader) Err() error {
|
||||
return br.err
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ func (bz2 *reader) Read(buf []byte) (n int, err error) {
|
|||
|
||||
if !bz2.setupDone {
|
||||
err = bz2.setup()
|
||||
brErr := bz2.br.Error()
|
||||
brErr := bz2.br.Err()
|
||||
if brErr != nil {
|
||||
err = brErr
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ func (bz2 *reader) Read(buf []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
n, err = bz2.read(buf)
|
||||
brErr := bz2.br.Error()
|
||||
brErr := bz2.br.Err()
|
||||
if brErr != nil {
|
||||
err = brErr
|
||||
}
|
||||
|
|
1
libgo/go/compress/zlib/testdata/e.txt
vendored
1
libgo/go/compress/zlib/testdata/e.txt
vendored
File diff suppressed because one or more lines are too long
1
libgo/go/compress/zlib/testdata/pi.txt
vendored
1
libgo/go/compress/zlib/testdata/pi.txt
vendored
File diff suppressed because one or more lines are too long
|
@ -11,14 +11,17 @@ import "sort"
|
|||
|
||||
// Any type that implements heap.Interface may be used as a
|
||||
// min-heap with the following invariants (established after
|
||||
// Init has been called):
|
||||
// Init has been called or if the data is empty or sorted):
|
||||
//
|
||||
// !h.Less(j, i) for 0 <= i < h.Len() and j = 2*i+1 or 2*i+2 and j < h.Len()
|
||||
//
|
||||
// Note that Push and Pop in this interface are for package heap's
|
||||
// implementation to call. To add and remove things from the heap,
|
||||
// use heap.Push and heap.Pop.
|
||||
type Interface interface {
|
||||
sort.Interface
|
||||
Push(x interface{})
|
||||
Pop() interface{}
|
||||
Push(x interface{}) // add x as element Len()
|
||||
Pop() interface{} // remove and return element Len() - 1.
|
||||
}
|
||||
|
||||
// A heap must be initialized before any of the heap operations
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
package heap_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
. "container/heap"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type myHeap []int
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
package dsa
|
||||
|
||||
import (
|
||||
"big"
|
||||
"errors"
|
||||
"io"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// Parameters represents the domain parameters for a key. These parameters can
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
package dsa
|
||||
|
||||
import (
|
||||
"big"
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ package ecdsa
|
|||
// http://www.secg.org/download/aid-780/sec1-v2.pdf
|
||||
|
||||
import (
|
||||
"big"
|
||||
"crypto/elliptic"
|
||||
"io"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// PublicKey represents an ECDSA public key.
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
package ecdsa
|
||||
|
||||
import (
|
||||
"big"
|
||||
"crypto/elliptic"
|
||||
"crypto/sha1"
|
||||
"crypto/rand"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ package elliptic
|
|||
// reverse the transform than to operate in affine coordinates.
|
||||
|
||||
import (
|
||||
"big"
|
||||
"io"
|
||||
"math/big"
|
||||
"sync"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
package elliptic
|
||||
|
||||
import (
|
||||
"big"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
package hmac
|
||||
|
||||
import (
|
||||
"hash"
|
||||
"fmt"
|
||||
"hash"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
package ocsp
|
||||
|
||||
import (
|
||||
"asn1"
|
||||
"crypto"
|
||||
"crypto/rsa"
|
||||
_ "crypto/sha1"
|
||||
"crypto/x509"
|
||||
"crypto/x509/pkix"
|
||||
"encoding/asn1"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ func (r *openpgpReader) Read(p []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
// Decode reads a PGP armored block from the given Reader. It will ignore
|
||||
// leading garbage. If it doesn't find a block, it will return nil, os.EOF. The
|
||||
// leading garbage. If it doesn't find a block, it will return nil, io.EOF. The
|
||||
// given Reader is not usable after calling this function: an arbitrary amount
|
||||
// of data may have been read past the end of the block.
|
||||
func Decode(in io.Reader) (p *Block, err error) {
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
package elgamal
|
||||
|
||||
import (
|
||||
"big"
|
||||
"crypto/rand"
|
||||
"crypto/subtle"
|
||||
"errors"
|
||||
"io"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// PublicKey represents an ElGamal public key.
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
package elgamal
|
||||
|
||||
import (
|
||||
"big"
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
package packet
|
||||
|
||||
import (
|
||||
"big"
|
||||
"crypto/openpgp/elgamal"
|
||||
error_ "crypto/openpgp/error"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"math/big"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
package packet
|
||||
|
||||
import (
|
||||
"big"
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
package packet
|
||||
|
||||
import (
|
||||
"big"
|
||||
"crypto/aes"
|
||||
"crypto/cast5"
|
||||
"crypto/cipher"
|
||||
error_ "crypto/openpgp/error"
|
||||
"io"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// readFull is the same as io.ReadFull except that reading zero bytes returns
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package packet
|
||||
|
||||
import (
|
||||
"big"
|
||||
"bytes"
|
||||
"crypto/cipher"
|
||||
"crypto/dsa"
|
||||
|
@ -16,6 +15,7 @@ import (
|
|||
"crypto/sha1"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package packet
|
||||
|
||||
import (
|
||||
"big"
|
||||
"crypto/dsa"
|
||||
"crypto/openpgp/elgamal"
|
||||
error_ "crypto/openpgp/error"
|
||||
|
@ -15,6 +14,7 @@ import (
|
|||
"fmt"
|
||||
"hash"
|
||||
"io"
|
||||
"math/big"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ package s2k
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"crypto/rand"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
)
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
package rand
|
||||
|
||||
import (
|
||||
"big"
|
||||
"io"
|
||||
"math/big"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
package rsa
|
||||
|
||||
import (
|
||||
"big"
|
||||
"crypto"
|
||||
"crypto/subtle"
|
||||
"errors"
|
||||
"io"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// This file implements encryption and decryption using PKCS#1 v1.5 padding.
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package rsa
|
||||
|
||||
import (
|
||||
"big"
|
||||
"bytes"
|
||||
"crypto"
|
||||
"crypto/rand"
|
||||
|
@ -13,6 +12,7 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"math/big"
|
||||
"testing"
|
||||
"testing/quick"
|
||||
)
|
||||
|
|
|
@ -8,12 +8,12 @@ package rsa
|
|||
// TODO(agl): Add support for PSS padding.
|
||||
|
||||
import (
|
||||
"big"
|
||||
"crypto/rand"
|
||||
"crypto/subtle"
|
||||
"errors"
|
||||
"hash"
|
||||
"io"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
var bigZero = big.NewInt(0)
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
package rsa
|
||||
|
||||
import (
|
||||
"big"
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"crypto/sha1"
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
|
@ -471,7 +471,7 @@ Again:
|
|||
// RFC suggests that EOF without an alertCloseNotify is
|
||||
// an error, but popular web sites seem to do this,
|
||||
// so we can't make it an error.
|
||||
// if err == os.EOF {
|
||||
// if err == io.EOF {
|
||||
// err = io.ErrUnexpectedEOF
|
||||
// }
|
||||
if e, ok := err.(net.Error); !ok || !e.Temporary() {
|
||||
|
|
|
@ -8,14 +8,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"big"
|
||||
"crypto/x509/pkix"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"crypto/x509/pkix"
|
||||
"encoding/pem"
|
||||
"flag"
|
||||
"log"
|
||||
"math/big"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
package tls
|
||||
|
||||
import (
|
||||
"rand"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
"testing/quick"
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
package tls
|
||||
|
||||
import (
|
||||
"big"
|
||||
"bytes"
|
||||
"crypto/rsa"
|
||||
"encoding/hex"
|
||||
"flag"
|
||||
"io"
|
||||
"math/big"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package tls
|
||||
|
||||
import (
|
||||
"big"
|
||||
"crypto"
|
||||
"crypto/elliptic"
|
||||
"crypto/md5"
|
||||
|
@ -14,6 +13,7 @@ import (
|
|||
"crypto/x509"
|
||||
"errors"
|
||||
"io"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// rsaKeyAgreement implements the standard TLS key agreement where the client
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
package x509
|
||||
|
||||
import (
|
||||
"asn1"
|
||||
"big"
|
||||
"errors"
|
||||
"crypto/rsa"
|
||||
"encoding/asn1"
|
||||
"errors"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// pkcs1PrivateKey is a structure which mirrors the PKCS#1 ASN.1 for an RSA private key.
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
package pkix
|
||||
|
||||
import (
|
||||
"asn1"
|
||||
"big"
|
||||
"encoding/asn1"
|
||||
"math/big"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
|
@ -6,17 +6,17 @@
|
|||
package x509
|
||||
|
||||
import (
|
||||
"asn1"
|
||||
"big"
|
||||
"bytes"
|
||||
"crypto"
|
||||
"crypto/dsa"
|
||||
"crypto/rsa"
|
||||
"crypto/sha1"
|
||||
"crypto/x509/pkix"
|
||||
"encoding/asn1"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"io"
|
||||
"math/big"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
package x509
|
||||
|
||||
import (
|
||||
"asn1"
|
||||
"big"
|
||||
"bytes"
|
||||
"crypto/dsa"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509/pkix"
|
||||
"encoding/asn1"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/pem"
|
||||
"math/big"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
|
|
@ -7,8 +7,8 @@ package gosym
|
|||
import (
|
||||
"debug/elf"
|
||||
"os"
|
||||
"testing"
|
||||
"syscall"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func dotest() bool {
|
||||
|
|
|
@ -20,8 +20,8 @@ package asn1
|
|||
// everything by any means.
|
||||
|
||||
import (
|
||||
"big"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
|
@ -5,10 +5,10 @@
|
|||
package asn1
|
||||
|
||||
import (
|
||||
"big"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
|
@ -9,8 +9,8 @@ package binary
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"io"
|
||||
"math"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ package binary
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"bytes"
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"io"
|
||||
"strings"
|
||||
"unicode"
|
||||
"utf8"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// A Writer writes records to a CSV encoded file.
|
687
libgo/go/encoding/gob/debug.go
Normal file
687
libgo/go/encoding/gob/debug.go
Normal file
|
@ -0,0 +1,687 @@
|
|||
package gob
|
||||
|
||||
// This file is not normally included in the gob package. Used only for debugging the package itself.
|
||||
// Add debug.go to the files listed in the Makefile to add Debug to the gob package.
|
||||
// Except for reading uints, it is an implementation of a reader that is independent of
|
||||
// the one implemented by Decoder.
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var dumpBytes = false // If true, print the remaining bytes in the input buffer at each item.
|
||||
|
||||
// Init installs the debugging facility. If this file is not compiled in the
|
||||
// package, the tests in codec_test.go are no-ops.
|
||||
func init() {
|
||||
debugFunc = Debug
|
||||
}
|
||||
|
||||
var (
|
||||
blanks = bytes.Repeat([]byte{' '}, 3*10)
|
||||
empty = []byte(": <empty>\n")
|
||||
tabs = strings.Repeat("\t", 100)
|
||||
)
|
||||
|
||||
// tab indents itself when printed.
|
||||
type tab int
|
||||
|
||||
func (t tab) String() string {
|
||||
n := int(t)
|
||||
if n > len(tabs) {
|
||||
n = len(tabs)
|
||||
}
|
||||
return tabs[0:n]
|
||||
}
|
||||
|
||||
func (t tab) print() {
|
||||
fmt.Fprint(os.Stderr, t)
|
||||
}
|
||||
|
||||
// A peekReader wraps an io.Reader, allowing one to peek ahead to see
|
||||
// what's coming without stealing the data from the client of the Reader.
|
||||
type peekReader struct {
|
||||
r io.Reader
|
||||
data []byte // read-ahead data
|
||||
}
|
||||
|
||||
// newPeekReader returns a peekReader that wraps r.
|
||||
func newPeekReader(r io.Reader) *peekReader {
|
||||
return &peekReader{r: r}
|
||||
}
|
||||
|
||||
// Read is the usual method. It will first take data that has been read ahead.
|
||||
func (p *peekReader) Read(b []byte) (n int, err error) {
|
||||
if len(p.data) == 0 {
|
||||
return p.r.Read(b)
|
||||
}
|
||||
// Satisfy what's possible from the read-ahead data.
|
||||
n = copy(b, p.data)
|
||||
// Move data down to beginning of slice, to avoid endless growth
|
||||
copy(p.data, p.data[n:])
|
||||
p.data = p.data[:len(p.data)-n]
|
||||
return
|
||||
}
|
||||
|
||||
// peek returns as many bytes as possible from the unread
|
||||
// portion of the stream, up to the length of b.
|
||||
func (p *peekReader) peek(b []byte) (n int, err error) {
|
||||
if len(p.data) > 0 {
|
||||
n = copy(b, p.data)
|
||||
if n == len(b) {
|
||||
return
|
||||
}
|
||||
b = b[n:]
|
||||
}
|
||||
if len(b) == 0 {
|
||||
return
|
||||
}
|
||||
m, e := io.ReadFull(p.r, b)
|
||||
if m > 0 {
|
||||
p.data = append(p.data, b[:m]...)
|
||||
}
|
||||
n += m
|
||||
if e == io.ErrUnexpectedEOF {
|
||||
// That means m > 0 but we reached EOF. If we got data
|
||||
// we won't complain about not being able to peek enough.
|
||||
if n > 0 {
|
||||
e = nil
|
||||
} else {
|
||||
e = io.EOF
|
||||
}
|
||||
}
|
||||
return n, e
|
||||
}
|
||||
|
||||
type debugger struct {
|
||||
mutex sync.Mutex
|
||||
remain int // the number of bytes known to remain in the input
|
||||
remainingKnown bool // the value of 'remain' is valid
|
||||
r *peekReader
|
||||
wireType map[typeId]*wireType
|
||||
tmp []byte // scratch space for decoding uints.
|
||||
}
|
||||
|
||||
// dump prints the next nBytes of the input.
|
||||
// It arranges to print the output aligned from call to
|
||||
// call, to make it easy to see what has been consumed.
|
||||
func (deb *debugger) dump(format string, args ...interface{}) {
|
||||
if !dumpBytes {
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, format+" ", args...)
|
||||
if !deb.remainingKnown {
|
||||
return
|
||||
}
|
||||
if deb.remain < 0 {
|
||||
fmt.Fprintf(os.Stderr, "remaining byte count is negative! %d\n", deb.remain)
|
||||
return
|
||||
}
|
||||
data := make([]byte, deb.remain)
|
||||
n, _ := deb.r.peek(data)
|
||||
if n == 0 {
|
||||
os.Stderr.Write(empty)
|
||||
return
|
||||
}
|
||||
b := new(bytes.Buffer)
|
||||
fmt.Fprintf(b, "[%d]{\n", deb.remain)
|
||||
// Blanks until first byte
|
||||
lineLength := 0
|
||||
if n := len(data); n%10 != 0 {
|
||||
lineLength = 10 - n%10
|
||||
fmt.Fprintf(b, "\t%s", blanks[:lineLength*3])
|
||||
}
|
||||
// 10 bytes per line
|
||||
for len(data) > 0 {
|
||||
if lineLength == 0 {
|
||||
fmt.Fprint(b, "\t")
|
||||
}
|
||||
m := 10 - lineLength
|
||||
lineLength = 0
|
||||
if m > len(data) {
|
||||
m = len(data)
|
||||
}
|
||||
fmt.Fprintf(b, "% x\n", data[:m])
|
||||
data = data[m:]
|
||||
}
|
||||
fmt.Fprint(b, "}\n")
|
||||
os.Stderr.Write(b.Bytes())
|
||||
}
|
||||
|
||||
// Debug prints a human-readable representation of the gob data read from r.
|
||||
// It is a no-op unless debugging was enabled when the package was built.
|
||||
func Debug(r io.Reader) {
|
||||
err := debug(r)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "gob debug: %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
// debug implements Debug, but catches panics and returns
|
||||
// them as errors to be printed by Debug.
|
||||
func debug(r io.Reader) (err error) {
|
||||
defer catchError(&err)
|
||||
fmt.Fprintln(os.Stderr, "Start of debugging")
|
||||
deb := &debugger{
|
||||
r: newPeekReader(r),
|
||||
wireType: make(map[typeId]*wireType),
|
||||
tmp: make([]byte, 16),
|
||||
}
|
||||
if b, ok := r.(*bytes.Buffer); ok {
|
||||
deb.remain = b.Len()
|
||||
deb.remainingKnown = true
|
||||
}
|
||||
deb.gobStream()
|
||||
return
|
||||
}
|
||||
|
||||
// note that we've consumed some bytes
|
||||
func (deb *debugger) consumed(n int) {
|
||||
if deb.remainingKnown {
|
||||
deb.remain -= n
|
||||
}
|
||||
}
|
||||
|
||||
// int64 decodes and returns the next integer, which must be present.
|
||||
// Don't call this if you could be at EOF.
|
||||
func (deb *debugger) int64() int64 {
|
||||
return toInt(deb.uint64())
|
||||
}
|
||||
|
||||
// uint64 returns and decodes the next unsigned integer, which must be present.
|
||||
// Don't call this if you could be at EOF.
|
||||
// TODO: handle errors better.
|
||||
func (deb *debugger) uint64() uint64 {
|
||||
n, w, err := decodeUintReader(deb.r, deb.tmp)
|
||||
if err != nil {
|
||||
errorf("debug: read error: %s", err)
|
||||
}
|
||||
deb.consumed(w)
|
||||
return n
|
||||
}
|
||||
|
||||
// GobStream:
|
||||
// DelimitedMessage* (until EOF)
|
||||
func (deb *debugger) gobStream() {
|
||||
// Make sure we're single-threaded through here.
|
||||
deb.mutex.Lock()
|
||||
defer deb.mutex.Unlock()
|
||||
|
||||
for deb.delimitedMessage(0) {
|
||||
}
|
||||
}
|
||||
|
||||
// DelimitedMessage:
|
||||
// uint(lengthOfMessage) Message
|
||||
func (deb *debugger) delimitedMessage(indent tab) bool {
|
||||
for {
|
||||
n := deb.loadBlock(true)
|
||||
if n < 0 {
|
||||
return false
|
||||
}
|
||||
deb.dump("Delimited message of length %d", n)
|
||||
deb.message(indent)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// loadBlock preps us to read a message
|
||||
// of the length specified next in the input. It returns
|
||||
// the length of the block. The argument tells whether
|
||||
// an EOF is acceptable now. If it is and one is found,
|
||||
// the return value is negative.
|
||||
func (deb *debugger) loadBlock(eofOK bool) int {
|
||||
n64, w, err := decodeUintReader(deb.r, deb.tmp) // deb.uint64 will error at EOF
|
||||
if err != nil {
|
||||
if eofOK && err == io.EOF {
|
||||
return -1
|
||||
}
|
||||
errorf("debug: unexpected error: %s", err)
|
||||
}
|
||||
deb.consumed(w)
|
||||
n := int(n64)
|
||||
if n < 0 {
|
||||
errorf("huge value for message length: %d", n64)
|
||||
}
|
||||
return int(n)
|
||||
}
|
||||
|
||||
// Message:
|
||||
// TypeSequence TypedValue
|
||||
// TypeSequence
|
||||
// (TypeDefinition DelimitedTypeDefinition*)?
|
||||
// DelimitedTypeDefinition:
|
||||
// uint(lengthOfTypeDefinition) TypeDefinition
|
||||
// TypedValue:
|
||||
// int(typeId) Value
|
||||
func (deb *debugger) message(indent tab) bool {
|
||||
for {
|
||||
// Convert the uint64 to a signed integer typeId
|
||||
uid := deb.int64()
|
||||
id := typeId(uid)
|
||||
deb.dump("type id=%d", id)
|
||||
if id < 0 {
|
||||
deb.typeDefinition(indent, -id)
|
||||
n := deb.loadBlock(false)
|
||||
deb.dump("Message of length %d", n)
|
||||
continue
|
||||
} else {
|
||||
deb.value(indent, id)
|
||||
break
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Helper methods to make it easy to scan a type descriptor.
|
||||
|
||||
// common returns the CommonType at the input point.
|
||||
func (deb *debugger) common() CommonType {
|
||||
fieldNum := -1
|
||||
name := ""
|
||||
id := typeId(0)
|
||||
for {
|
||||
delta := deb.delta(-1)
|
||||
if delta == 0 {
|
||||
break
|
||||
}
|
||||
fieldNum += delta
|
||||
switch fieldNum {
|
||||
case 0:
|
||||
name = deb.string()
|
||||
case 1:
|
||||
// Id typeId
|
||||
id = deb.typeId()
|
||||
default:
|
||||
errorf("corrupted CommonType")
|
||||
}
|
||||
}
|
||||
return CommonType{name, id}
|
||||
}
|
||||
|
||||
// uint returns the unsigned int at the input point, as a uint (not uint64).
|
||||
func (deb *debugger) uint() uint {
|
||||
return uint(deb.uint64())
|
||||
}
|
||||
|
||||
// int returns the signed int at the input point, as an int (not int64).
|
||||
func (deb *debugger) int() int {
|
||||
return int(deb.int64())
|
||||
}
|
||||
|
||||
// typeId returns the type id at the input point.
|
||||
func (deb *debugger) typeId() typeId {
|
||||
return typeId(deb.int64())
|
||||
}
|
||||
|
||||
// string returns the string at the input point.
|
||||
func (deb *debugger) string() string {
|
||||
x := int(deb.uint64())
|
||||
b := make([]byte, x)
|
||||
nb, _ := deb.r.Read(b)
|
||||
if nb != x {
|
||||
errorf("corrupted type")
|
||||
}
|
||||
deb.consumed(nb)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// delta returns the field delta at the input point. The expect argument,
|
||||
// if non-negative, identifies what the value should be.
|
||||
func (deb *debugger) delta(expect int) int {
|
||||
delta := int(deb.uint64())
|
||||
if delta < 0 || (expect >= 0 && delta != expect) {
|
||||
errorf("decode: corrupted type: delta %d expected %d", delta, expect)
|
||||
}
|
||||
return delta
|
||||
}
|
||||
|
||||
// TypeDefinition:
|
||||
// [int(-typeId) (already read)] encodingOfWireType
|
||||
func (deb *debugger) typeDefinition(indent tab, id typeId) {
|
||||
deb.dump("type definition for id %d", id)
|
||||
// Encoding is of a wireType. Decode the structure as usual
|
||||
fieldNum := -1
|
||||
wire := new(wireType)
|
||||
// A wireType defines a single field.
|
||||
delta := deb.delta(-1)
|
||||
fieldNum += delta
|
||||
switch fieldNum {
|
||||
case 0: // array type, one field of {{Common}, elem, length}
|
||||
// Field number 0 is CommonType
|
||||
deb.delta(1)
|
||||
com := deb.common()
|
||||
// Field number 1 is type Id of elem
|
||||
deb.delta(1)
|
||||
id := deb.typeId()
|
||||
// Field number 3 is length
|
||||
deb.delta(1)
|
||||
length := deb.int()
|
||||
wire.ArrayT = &arrayType{com, id, length}
|
||||
|
||||
case 1: // slice type, one field of {{Common}, elem}
|
||||
// Field number 0 is CommonType
|
||||
deb.delta(1)
|
||||
com := deb.common()
|
||||
// Field number 1 is type Id of elem
|
||||
deb.delta(1)
|
||||
id := deb.typeId()
|
||||
wire.SliceT = &sliceType{com, id}
|
||||
|
||||
case 2: // struct type, one field of {{Common}, []fieldType}
|
||||
// Field number 0 is CommonType
|
||||
deb.delta(1)
|
||||
com := deb.common()
|
||||
// Field number 1 is slice of FieldType
|
||||
deb.delta(1)
|
||||
numField := int(deb.uint())
|
||||
field := make([]*fieldType, numField)
|
||||
for i := 0; i < numField; i++ {
|
||||
field[i] = new(fieldType)
|
||||
deb.delta(1) // field 0 of fieldType: name
|
||||
field[i].Name = deb.string()
|
||||
deb.delta(1) // field 1 of fieldType: id
|
||||
field[i].Id = deb.typeId()
|
||||
deb.delta(0) // end of fieldType
|
||||
}
|
||||
wire.StructT = &structType{com, field}
|
||||
|
||||
case 3: // map type, one field of {{Common}, key, elem}
|
||||
// Field number 0 is CommonType
|
||||
deb.delta(1)
|
||||
com := deb.common()
|
||||
// Field number 1 is type Id of key
|
||||
deb.delta(1)
|
||||
keyId := deb.typeId()
|
||||
// Field number 2 is type Id of elem
|
||||
deb.delta(1)
|
||||
elemId := deb.typeId()
|
||||
wire.MapT = &mapType{com, keyId, elemId}
|
||||
case 4: // GobEncoder type, one field of {{Common}}
|
||||
// Field number 0 is CommonType
|
||||
deb.delta(1)
|
||||
com := deb.common()
|
||||
wire.GobEncoderT = &gobEncoderType{com}
|
||||
default:
|
||||
errorf("bad field in type %d", fieldNum)
|
||||
}
|
||||
deb.printWireType(indent, wire)
|
||||
deb.delta(0) // end inner type (arrayType, etc.)
|
||||
deb.delta(0) // end wireType
|
||||
// Remember we've seen this type.
|
||||
deb.wireType[id] = wire
|
||||
}
|
||||
|
||||
// Value:
|
||||
// SingletonValue | StructValue
|
||||
func (deb *debugger) value(indent tab, id typeId) {
|
||||
wire, ok := deb.wireType[id]
|
||||
if ok && wire.StructT != nil {
|
||||
deb.structValue(indent, id)
|
||||
} else {
|
||||
deb.singletonValue(indent, id)
|
||||
}
|
||||
}
|
||||
|
||||
// SingletonValue:
|
||||
// uint(0) FieldValue
|
||||
func (deb *debugger) singletonValue(indent tab, id typeId) {
|
||||
deb.dump("Singleton value")
|
||||
// is it a builtin type?
|
||||
wire := deb.wireType[id]
|
||||
_, ok := builtinIdToType[id]
|
||||
if !ok && wire == nil {
|
||||
errorf("type id %d not defined", id)
|
||||
}
|
||||
m := deb.uint64()
|
||||
if m != 0 {
|
||||
errorf("expected zero; got %d", m)
|
||||
}
|
||||
deb.fieldValue(indent, id)
|
||||
}
|
||||
|
||||
// InterfaceValue:
|
||||
// NilInterfaceValue | NonNilInterfaceValue
|
||||
func (deb *debugger) interfaceValue(indent tab) {
|
||||
deb.dump("Start of interface value")
|
||||
if nameLen := deb.uint64(); nameLen == 0 {
|
||||
deb.nilInterfaceValue(indent)
|
||||
} else {
|
||||
deb.nonNilInterfaceValue(indent, int(nameLen))
|
||||
}
|
||||
}
|
||||
|
||||
// NilInterfaceValue:
|
||||
// uint(0) [already read]
|
||||
func (deb *debugger) nilInterfaceValue(indent tab) int {
|
||||
fmt.Fprintf(os.Stderr, "%snil interface\n", indent)
|
||||
return 0
|
||||
}
|
||||
|
||||
// NonNilInterfaceValue:
|
||||
// ConcreteTypeName TypeSequence InterfaceContents
|
||||
// ConcreteTypeName:
|
||||
// uint(lengthOfName) [already read=n] name
|
||||
// InterfaceContents:
|
||||
// int(concreteTypeId) DelimitedValue
|
||||
// DelimitedValue:
|
||||
// uint(length) Value
|
||||
func (deb *debugger) nonNilInterfaceValue(indent tab, nameLen int) {
|
||||
// ConcreteTypeName
|
||||
b := make([]byte, nameLen)
|
||||
deb.r.Read(b) // TODO: CHECK THESE READS!!
|
||||
deb.consumed(nameLen)
|
||||
name := string(b)
|
||||
|
||||
for {
|
||||
id := deb.typeId()
|
||||
if id < 0 {
|
||||
deb.typeDefinition(indent, -id)
|
||||
n := deb.loadBlock(false)
|
||||
deb.dump("Nested message of length %d", n)
|
||||
} else {
|
||||
// DelimitedValue
|
||||
x := deb.uint64() // in case we want to ignore the value; we don't.
|
||||
fmt.Fprintf(os.Stderr, "%sinterface value, type %q id=%d; valueLength %d\n", indent, name, id, x)
|
||||
deb.value(indent, id)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// printCommonType prints a common type; used by printWireType.
|
||||
func (deb *debugger) printCommonType(indent tab, kind string, common *CommonType) {
|
||||
indent.print()
|
||||
fmt.Fprintf(os.Stderr, "%s %q id=%d\n", kind, common.Name, common.Id)
|
||||
}
|
||||
|
||||
// printWireType prints the contents of a wireType.
|
||||
func (deb *debugger) printWireType(indent tab, wire *wireType) {
|
||||
fmt.Fprintf(os.Stderr, "%stype definition {\n", indent)
|
||||
indent++
|
||||
switch {
|
||||
case wire.ArrayT != nil:
|
||||
deb.printCommonType(indent, "array", &wire.ArrayT.CommonType)
|
||||
fmt.Fprintf(os.Stderr, "%slen %d\n", indent+1, wire.ArrayT.Len)
|
||||
fmt.Fprintf(os.Stderr, "%selemid %d\n", indent+1, wire.ArrayT.Elem)
|
||||
case wire.MapT != nil:
|
||||
deb.printCommonType(indent, "map", &wire.MapT.CommonType)
|
||||
fmt.Fprintf(os.Stderr, "%skey id=%d\n", indent+1, wire.MapT.Key)
|
||||
fmt.Fprintf(os.Stderr, "%selem id=%d\n", indent+1, wire.MapT.Elem)
|
||||
case wire.SliceT != nil:
|
||||
deb.printCommonType(indent, "slice", &wire.SliceT.CommonType)
|
||||
fmt.Fprintf(os.Stderr, "%selem id=%d\n", indent+1, wire.SliceT.Elem)
|
||||
case wire.StructT != nil:
|
||||
deb.printCommonType(indent, "struct", &wire.StructT.CommonType)
|
||||
for i, field := range wire.StructT.Field {
|
||||
fmt.Fprintf(os.Stderr, "%sfield %d:\t%s\tid=%d\n", indent+1, i, field.Name, field.Id)
|
||||
}
|
||||
case wire.GobEncoderT != nil:
|
||||
deb.printCommonType(indent, "GobEncoder", &wire.GobEncoderT.CommonType)
|
||||
}
|
||||
indent--
|
||||
fmt.Fprintf(os.Stderr, "%s}\n", indent)
|
||||
}
|
||||
|
||||
// fieldValue prints a value of any type, such as a struct field.
|
||||
// FieldValue:
|
||||
// builtinValue | ArrayValue | MapValue | SliceValue | StructValue | InterfaceValue
|
||||
func (deb *debugger) fieldValue(indent tab, id typeId) {
|
||||
_, ok := builtinIdToType[id]
|
||||
if ok {
|
||||
if id == tInterface {
|
||||
deb.interfaceValue(indent)
|
||||
} else {
|
||||
deb.printBuiltin(indent, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
wire, ok := deb.wireType[id]
|
||||
if !ok {
|
||||
errorf("type id %d not defined", id)
|
||||
}
|
||||
switch {
|
||||
case wire.ArrayT != nil:
|
||||
deb.arrayValue(indent, wire)
|
||||
case wire.MapT != nil:
|
||||
deb.mapValue(indent, wire)
|
||||
case wire.SliceT != nil:
|
||||
deb.sliceValue(indent, wire)
|
||||
case wire.StructT != nil:
|
||||
deb.structValue(indent, id)
|
||||
case wire.GobEncoderT != nil:
|
||||
deb.gobEncoderValue(indent, id)
|
||||
default:
|
||||
panic("bad wire type for field")
|
||||
}
|
||||
}
|
||||
|
||||
// printBuiltin prints a value not of a fundamental type, that is,
|
||||
// one whose type is known to gobs at bootstrap time.
|
||||
func (deb *debugger) printBuiltin(indent tab, id typeId) {
|
||||
switch id {
|
||||
case tBool:
|
||||
x := deb.int64()
|
||||
if x == 0 {
|
||||
fmt.Fprintf(os.Stderr, "%sfalse\n", indent)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%strue\n", indent)
|
||||
}
|
||||
case tInt:
|
||||
x := deb.int64()
|
||||
fmt.Fprintf(os.Stderr, "%s%d\n", indent, x)
|
||||
case tUint:
|
||||
x := deb.int64()
|
||||
fmt.Fprintf(os.Stderr, "%s%d\n", indent, x)
|
||||
case tFloat:
|
||||
x := deb.uint64()
|
||||
fmt.Fprintf(os.Stderr, "%s%g\n", indent, floatFromBits(x))
|
||||
case tComplex:
|
||||
r := deb.uint64()
|
||||
i := deb.uint64()
|
||||
fmt.Fprintf(os.Stderr, "%s%g+%gi\n", indent, floatFromBits(r), floatFromBits(i))
|
||||
case tBytes:
|
||||
x := int(deb.uint64())
|
||||
b := make([]byte, x)
|
||||
deb.r.Read(b)
|
||||
deb.consumed(x)
|
||||
fmt.Fprintf(os.Stderr, "%s{% x}=%q\n", indent, b, b)
|
||||
case tString:
|
||||
x := int(deb.uint64())
|
||||
b := make([]byte, x)
|
||||
deb.r.Read(b)
|
||||
deb.consumed(x)
|
||||
fmt.Fprintf(os.Stderr, "%s%q\n", indent, b)
|
||||
default:
|
||||
panic("unknown builtin")
|
||||
}
|
||||
}
|
||||
|
||||
// ArrayValue:
|
||||
// uint(n) FieldValue*n
|
||||
func (deb *debugger) arrayValue(indent tab, wire *wireType) {
|
||||
elemId := wire.ArrayT.Elem
|
||||
u := deb.uint64()
|
||||
length := int(u)
|
||||
for i := 0; i < length; i++ {
|
||||
deb.fieldValue(indent, elemId)
|
||||
}
|
||||
if length != wire.ArrayT.Len {
|
||||
fmt.Fprintf(os.Stderr, "%s(wrong length for array: %d should be %d)\n", indent, length, wire.ArrayT.Len)
|
||||
}
|
||||
}
|
||||
|
||||
// MapValue:
|
||||
// uint(n) (FieldValue FieldValue)*n [n (key, value) pairs]
|
||||
func (deb *debugger) mapValue(indent tab, wire *wireType) {
|
||||
keyId := wire.MapT.Key
|
||||
elemId := wire.MapT.Elem
|
||||
u := deb.uint64()
|
||||
length := int(u)
|
||||
for i := 0; i < length; i++ {
|
||||
deb.fieldValue(indent+1, keyId)
|
||||
deb.fieldValue(indent+1, elemId)
|
||||
}
|
||||
}
|
||||
|
||||
// SliceValue:
|
||||
// uint(n) (n FieldValue)
|
||||
func (deb *debugger) sliceValue(indent tab, wire *wireType) {
|
||||
elemId := wire.SliceT.Elem
|
||||
u := deb.uint64()
|
||||
length := int(u)
|
||||
deb.dump("Start of slice of length %d", length)
|
||||
|
||||
for i := 0; i < length; i++ {
|
||||
deb.fieldValue(indent, elemId)
|
||||
}
|
||||
}
|
||||
|
||||
// StructValue:
|
||||
// (uint(fieldDelta) FieldValue)*
|
||||
func (deb *debugger) structValue(indent tab, id typeId) {
|
||||
deb.dump("Start of struct value of %q id=%d\n<<\n", id.name(), id)
|
||||
fmt.Fprintf(os.Stderr, "%s%s struct {\n", indent, id.name())
|
||||
wire, ok := deb.wireType[id]
|
||||
if !ok {
|
||||
errorf("type id %d not defined", id)
|
||||
}
|
||||
strct := wire.StructT
|
||||
fieldNum := -1
|
||||
indent++
|
||||
for {
|
||||
delta := deb.uint64()
|
||||
if delta == 0 { // struct terminator is zero delta fieldnum
|
||||
break
|
||||
}
|
||||
fieldNum += int(delta)
|
||||
if fieldNum < 0 || fieldNum >= len(strct.Field) {
|
||||
deb.dump("field number out of range: prevField=%d delta=%d", fieldNum-int(delta), delta)
|
||||
break
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "%sfield %d:\t%s\n", indent, fieldNum, wire.StructT.Field[fieldNum].Name)
|
||||
deb.fieldValue(indent+1, strct.Field[fieldNum].Id)
|
||||
}
|
||||
indent--
|
||||
fmt.Fprintf(os.Stderr, "%s} // end %s struct\n", indent, id.name())
|
||||
deb.dump(">> End of struct value of type %d %q", id, id.name())
|
||||
}
|
||||
|
||||
// GobEncoderValue:
|
||||
// uint(n) byte*n
|
||||
func (deb *debugger) gobEncoderValue(indent tab, id typeId) {
|
||||
len := deb.uint64()
|
||||
deb.dump("GobEncoder value of %q id=%d, length %d\n", id.name(), id, len)
|
||||
fmt.Fprintf(os.Stderr, "%s%s (implements GobEncoder)\n", indent, id.name())
|
||||
data := make([]byte, len)
|
||||
_, err := deb.r.Read(data)
|
||||
if err != nil {
|
||||
errorf("gobEncoder data read: %s", err)
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "%s[% .2x]\n", indent+1, data)
|
||||
}
|
22
libgo/go/encoding/gob/dump.go
Normal file
22
libgo/go/encoding/gob/dump.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
// Need to compile package gob with debug.go to build this program.
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
file := os.Stdin
|
||||
if len(os.Args) > 1 {
|
||||
file, err = os.Open(os.Args[1])
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "dump: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
gob.Debug(file)
|
||||
}
|
|
@ -11,7 +11,7 @@ import (
|
|||
"reflect"
|
||||
"sync"
|
||||
"unicode"
|
||||
"utf8"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// userTypeInfo stores the information associated with a type the user has handed
|
||||
|
@ -703,18 +703,19 @@ func RegisterName(name string, value interface{}) {
|
|||
// reserved for nil
|
||||
panic("attempt to register empty name")
|
||||
}
|
||||
base := userType(reflect.TypeOf(value)).base
|
||||
// Check for incompatible duplicates.
|
||||
if t, ok := nameToConcreteType[name]; ok && t != base {
|
||||
panic("gob: registering duplicate types for " + name)
|
||||
ut := userType(reflect.TypeOf(value))
|
||||
// Check for incompatible duplicates. The name must refer to the
|
||||
// same user type, and vice versa.
|
||||
if t, ok := nameToConcreteType[name]; ok && t != ut.user {
|
||||
panic(fmt.Sprintf("gob: registering duplicate types for %q: %s != %s", name, t, ut.user))
|
||||
}
|
||||
if n, ok := concreteTypeToName[base]; ok && n != name {
|
||||
panic("gob: registering duplicate names for " + base.String())
|
||||
if n, ok := concreteTypeToName[ut.base]; ok && n != name {
|
||||
panic(fmt.Sprintf("gob: registering duplicate names for %s: %q != %q", ut.user, n, name))
|
||||
}
|
||||
// Store the name and type provided by the user....
|
||||
nameToConcreteType[name] = reflect.TypeOf(value)
|
||||
// but the flattened type in the type table, since that's what decode needs.
|
||||
concreteTypeToName[base] = name
|
||||
concreteTypeToName[ut.base] = name
|
||||
}
|
||||
|
||||
// Register records a type, identified by a value for that type, under its
|
|
@ -151,3 +151,11 @@ func TestStructType(t *testing.T) {
|
|||
t.Errorf("struct printed as %q; expected %q", str, expected)
|
||||
}
|
||||
}
|
||||
|
||||
// Should be OK to register the same type multiple times, as long as they're
|
||||
// at the same level of indirection.
|
||||
func TestRegistration(t *testing.T) {
|
||||
type T struct{ a int }
|
||||
Register(new(T))
|
||||
Register(new(T))
|
||||
}
|
|
@ -15,8 +15,8 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
"utf16"
|
||||
"utf8"
|
||||
"unicode/utf16"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Unmarshal parses the JSON-encoded data and stores the result
|
|
@ -17,7 +17,7 @@ import (
|
|||
"sort"
|
||||
"strconv"
|
||||
"unicode"
|
||||
"utf8"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Marshal returns the JSON encoding of v.
|
|
@ -7,7 +7,7 @@ package json
|
|||
import (
|
||||
"bytes"
|
||||
"math"
|
||||
"rand"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
@ -147,7 +147,7 @@ var indentErrorTests = []indentErrorTest{
|
|||
{`{"X": "foo" "Y": "bar"}`, &SyntaxError{"invalid character '\"' after object key:value pair", 13}},
|
||||
}
|
||||
|
||||
func TestIdentErrors(t *testing.T) {
|
||||
func TestIndentErrors(t *testing.T) {
|
||||
for i, tt := range indentErrorTests {
|
||||
slice := make([]uint8, 0)
|
||||
buf := bytes.NewBuffer(slice)
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue