aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/encoding
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-12-14 15:41:54 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-12-14 15:41:54 +0000
commitd5363590597572228d4e0d0ae13f3469176ceb14 (patch)
treee3de46cbc89d82ca1f49843fe2e1e670db67795e /libgo/go/encoding
parentef0d4c4d9937276c8ff818ecb0b92925d322d3bd (diff)
downloadgcc-d5363590597572228d4e0d0ae13f3469176ceb14.zip
gcc-d5363590597572228d4e0d0ae13f3469176ceb14.tar.gz
gcc-d5363590597572228d4e0d0ae13f3469176ceb14.tar.bz2
libgo: Update to weekly.2011-12-06.
From-SVN: r182338
Diffstat (limited to 'libgo/go/encoding')
-rw-r--r--libgo/go/encoding/ascii85/ascii85.go2
-rw-r--r--libgo/go/encoding/asn1/asn1_test.go6
-rw-r--r--libgo/go/encoding/asn1/common.go2
-rw-r--r--libgo/go/encoding/base32/base32.go2
-rw-r--r--libgo/go/encoding/base64/base64.go2
-rw-r--r--libgo/go/encoding/git85/git.go2
-rw-r--r--libgo/go/encoding/gob/encoder.go4
-rw-r--r--libgo/go/encoding/gob/encoder_test.go16
-rw-r--r--libgo/go/encoding/json/decode.go12
-rw-r--r--libgo/go/encoding/json/decode_test.go4
-rw-r--r--libgo/go/encoding/json/encode.go6
-rw-r--r--libgo/go/encoding/xml/marshal.go8
-rw-r--r--libgo/go/encoding/xml/marshal_test.go12
-rw-r--r--libgo/go/encoding/xml/read.go8
-rw-r--r--libgo/go/encoding/xml/xml.go4
15 files changed, 54 insertions, 36 deletions
diff --git a/libgo/go/encoding/ascii85/ascii85.go b/libgo/go/encoding/ascii85/ascii85.go
index 6f592f3..7d004b5 100644
--- a/libgo/go/encoding/ascii85/ascii85.go
+++ b/libgo/go/encoding/ascii85/ascii85.go
@@ -168,7 +168,7 @@ func (e *encoder) Close() error {
type CorruptInputError int64
func (e CorruptInputError) Error() string {
- return "illegal ascii85 data at input byte " + strconv.Itoa64(int64(e))
+ return "illegal ascii85 data at input byte " + strconv.FormatInt(int64(e), 10)
}
// Decode decodes src into dst, returning both the number
diff --git a/libgo/go/encoding/asn1/asn1_test.go b/libgo/go/encoding/asn1/asn1_test.go
index 2e6fccf..09f9413 100644
--- a/libgo/go/encoding/asn1/asn1_test.go
+++ b/libgo/go/encoding/asn1/asn1_test.go
@@ -225,19 +225,19 @@ func TestUTCTime(t *testing.T) {
ret, err := parseUTCTime([]byte(test.in))
if err != nil {
if test.ok {
- t.Errorf("#%d: parseUTCTime(%q) = error %v", i, err)
+ t.Errorf("#%d: parseUTCTime(%q) = error %v", i, test.in, err)
}
continue
}
if !test.ok {
- t.Errorf("#%d: parseUTCTime(%q) succeeded, should have failed", i)
+ t.Errorf("#%d: parseUTCTime(%q) succeeded, should have failed", i, test.in)
continue
}
const format = "Jan _2 15:04:05 -0700 2006" // ignore zone name, just offset
have := ret.Format(format)
want := test.out.Format(format)
if have != want {
- t.Errorf("#%d: parseUTCTime(%q) = %s, want %s", test.in, have, want)
+ t.Errorf("#%d: parseUTCTime(%q) = %s, want %s", i, test.in, have, want)
}
}
}
diff --git a/libgo/go/encoding/asn1/common.go b/libgo/go/encoding/asn1/common.go
index 01f4f7b..f7cb3ac 100644
--- a/libgo/go/encoding/asn1/common.go
+++ b/libgo/go/encoding/asn1/common.go
@@ -98,7 +98,7 @@ func parseFieldParameters(str string) (ret fieldParameters) {
case part == "printable":
ret.stringType = tagPrintableString
case strings.HasPrefix(part, "default:"):
- i, err := strconv.Atoi64(part[8:])
+ i, err := strconv.ParseInt(part[8:], 10, 64)
if err == nil {
ret.defaultValue = new(int64)
*ret.defaultValue = i
diff --git a/libgo/go/encoding/base32/base32.go b/libgo/go/encoding/base32/base32.go
index 494c760..c75c7c1 100644
--- a/libgo/go/encoding/base32/base32.go
+++ b/libgo/go/encoding/base32/base32.go
@@ -216,7 +216,7 @@ func (enc *Encoding) EncodedLen(n int) int { return (n + 4) / 5 * 8 }
type CorruptInputError int64
func (e CorruptInputError) Error() string {
- return "illegal base32 data at input byte " + strconv.Itoa64(int64(e))
+ return "illegal base32 data at input byte " + strconv.FormatInt(int64(e), 10)
}
// decode is like Decode but returns an additional 'end' value, which
diff --git a/libgo/go/encoding/base64/base64.go b/libgo/go/encoding/base64/base64.go
index 9451289..889b565 100644
--- a/libgo/go/encoding/base64/base64.go
+++ b/libgo/go/encoding/base64/base64.go
@@ -203,7 +203,7 @@ func (enc *Encoding) EncodedLen(n int) int { return (n + 2) / 3 * 4 }
type CorruptInputError int64
func (e CorruptInputError) Error() string {
- return "illegal base64 data at input byte " + strconv.Itoa64(int64(e))
+ return "illegal base64 data at input byte " + strconv.FormatInt(int64(e), 10)
}
// decode is like Decode but returns an additional 'end' value, which
diff --git a/libgo/go/encoding/git85/git.go b/libgo/go/encoding/git85/git.go
index b6ad6e2..d383213 100644
--- a/libgo/go/encoding/git85/git.go
+++ b/libgo/go/encoding/git85/git.go
@@ -15,7 +15,7 @@ import (
type CorruptInputError int64
func (e CorruptInputError) Error() string {
- return "illegal git85 data at input byte " + strconv.Itoa64(int64(e))
+ return "illegal git85 data at input byte " + strconv.FormatInt(int64(e), 10)
}
const encode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"
diff --git a/libgo/go/encoding/gob/encoder.go b/libgo/go/encoding/gob/encoder.go
index e4a48df..a15b5a1 100644
--- a/libgo/go/encoding/gob/encoder.go
+++ b/libgo/go/encoding/gob/encoder.go
@@ -119,7 +119,9 @@ func (enc *Encoder) sendActualType(w io.Writer, state *encoderState, ut *userTyp
switch st := actual; st.Kind() {
case reflect.Struct:
for i := 0; i < st.NumField(); i++ {
- enc.sendType(w, state, st.Field(i).Type)
+ if isExported(st.Field(i).Name) {
+ enc.sendType(w, state, st.Field(i).Type)
+ }
}
case reflect.Array, reflect.Slice:
enc.sendType(w, state, st.Elem())
diff --git a/libgo/go/encoding/gob/encoder_test.go b/libgo/go/encoding/gob/encoder_test.go
index bc5af12..5bc957b 100644
--- a/libgo/go/encoding/gob/encoder_test.go
+++ b/libgo/go/encoding/gob/encoder_test.go
@@ -662,3 +662,19 @@ func TestSequentialDecoder(t *testing.T) {
}
}
}
+
+// Should be able to have unrepresentable fields (chan, func) as long as they
+// are unexported.
+type Bug2 struct {
+ A int
+ b chan int
+}
+
+func TestUnexportedChan(t *testing.T) {
+ b := Bug2{23, make(chan int)}
+ var stream bytes.Buffer
+ enc := NewEncoder(&stream)
+ if err := enc.Encode(b); err != nil {
+ t.Fatalf("error encoding unexported channel: %s", err)
+ }
+}
diff --git a/libgo/go/encoding/json/decode.go b/libgo/go/encoding/json/decode.go
index 2ea06c5..0a70092 100644
--- a/libgo/go/encoding/json/decode.go
+++ b/libgo/go/encoding/json/decode.go
@@ -642,7 +642,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value) {
default:
d.error(&UnmarshalTypeError{"number", v.Type()})
case reflect.Interface:
- n, err := strconv.Atof64(s)
+ n, err := strconv.ParseFloat(s, 64)
if err != nil {
d.saveError(&UnmarshalTypeError{"number " + s, v.Type()})
break
@@ -650,7 +650,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value) {
v.Set(reflect.ValueOf(n))
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- n, err := strconv.Atoi64(s)
+ n, err := strconv.ParseInt(s, 10, 64)
if err != nil || v.OverflowInt(n) {
d.saveError(&UnmarshalTypeError{"number " + s, v.Type()})
break
@@ -658,7 +658,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value) {
v.SetInt(n)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- n, err := strconv.Atoui64(s)
+ n, err := strconv.ParseUint(s, 10, 64)
if err != nil || v.OverflowUint(n) {
d.saveError(&UnmarshalTypeError{"number " + s, v.Type()})
break
@@ -666,7 +666,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value) {
v.SetUint(n)
case reflect.Float32, reflect.Float64:
- n, err := strconv.AtofN(s, v.Type().Bits())
+ n, err := strconv.ParseFloat(s, v.Type().Bits())
if err != nil || v.OverflowFloat(n) {
d.saveError(&UnmarshalTypeError{"number " + s, v.Type()})
break
@@ -798,7 +798,7 @@ func (d *decodeState) literalInterface() interface{} {
if c != '-' && (c < '0' || c > '9') {
d.error(errPhase)
}
- n, err := strconv.Atof64(string(item))
+ n, err := strconv.ParseFloat(string(item), 64)
if err != nil {
d.saveError(&UnmarshalTypeError{"number " + string(item), reflect.TypeOf(0.0)})
}
@@ -813,7 +813,7 @@ func getu4(s []byte) rune {
if len(s) < 6 || s[0] != '\\' || s[1] != 'u' {
return -1
}
- r, err := strconv.Btoui64(string(s[2:6]), 16)
+ r, err := strconv.ParseUint(string(s[2:6]), 16, 64)
if err != nil {
return -1
}
diff --git a/libgo/go/encoding/json/decode_test.go b/libgo/go/encoding/json/decode_test.go
index bd4326a..bf3953e 100644
--- a/libgo/go/encoding/json/decode_test.go
+++ b/libgo/go/encoding/json/decode_test.go
@@ -345,12 +345,12 @@ var allValue = All{
"18": {Tag: "tag18"},
},
MapP: map[string]*Small{
- "19": &Small{Tag: "tag19"},
+ "19": {Tag: "tag19"},
"20": nil,
},
EmptyMap: map[string]Small{},
Slice: []Small{{Tag: "tag20"}, {Tag: "tag21"}},
- SliceP: []*Small{&Small{Tag: "tag22"}, nil, &Small{Tag: "tag23"}},
+ SliceP: []*Small{{Tag: "tag22"}, nil, {Tag: "tag23"}},
EmptySlice: []Small{},
StringSlice: []string{"str24", "str25", "str26"},
ByteSlice: []byte{27, 28, 29},
diff --git a/libgo/go/encoding/json/encode.go b/libgo/go/encoding/json/encode.go
index 14284f5..69deaf2 100644
--- a/libgo/go/encoding/json/encode.go
+++ b/libgo/go/encoding/json/encode.go
@@ -275,13 +275,13 @@ func (e *encodeState) reflectValueQuoted(v reflect.Value, quoted bool) {
}
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- writeString(e, strconv.Itoa64(v.Int()))
+ writeString(e, strconv.FormatInt(v.Int(), 10))
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- writeString(e, strconv.Uitoa64(v.Uint()))
+ writeString(e, strconv.FormatUint(v.Uint(), 10))
case reflect.Float32, reflect.Float64:
- writeString(e, strconv.FtoaN(v.Float(), 'g', -1, v.Type().Bits()))
+ writeString(e, strconv.FormatFloat(v.Float(), 'g', -1, v.Type().Bits()))
case reflect.String:
if quoted {
diff --git a/libgo/go/encoding/xml/marshal.go b/libgo/go/encoding/xml/marshal.go
index 691b70d..e94fdbc 100644
--- a/libgo/go/encoding/xml/marshal.go
+++ b/libgo/go/encoding/xml/marshal.go
@@ -173,15 +173,15 @@ func (p *printer) marshalValue(val reflect.Value, name string) error {
switch k := val.Kind(); k {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- p.WriteString(strconv.Itoa64(val.Int()))
+ p.WriteString(strconv.FormatInt(val.Int(), 10))
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- p.WriteString(strconv.Uitoa64(val.Uint()))
+ p.WriteString(strconv.FormatUint(val.Uint(), 10))
case reflect.Float32, reflect.Float64:
- p.WriteString(strconv.Ftoa64(val.Float(), 'g', -1))
+ p.WriteString(strconv.FormatFloat(val.Float(), 'g', -1, 64))
case reflect.String:
Escape(p, []byte(val.String()))
case reflect.Bool:
- p.WriteString(strconv.Btoa(val.Bool()))
+ p.WriteString(strconv.FormatBool(val.Bool()))
case reflect.Array:
// will be [...]byte
bytes := make([]byte, val.Len())
diff --git a/libgo/go/encoding/xml/marshal_test.go b/libgo/go/encoding/xml/marshal_test.go
index a6f7d2d..8040765 100644
--- a/libgo/go/encoding/xml/marshal_test.go
+++ b/libgo/go/encoding/xml/marshal_test.go
@@ -160,19 +160,19 @@ var marshalTests = []struct {
Age: 1,
Drive: ImprobabilityDrive,
Passenger: []*Passenger{
- &Passenger{
+ {
Name: []string{"Zaphod", "Beeblebrox"},
Weight: 7.25,
},
- &Passenger{
+ {
Name: []string{"Trisha", "McMillen"},
Weight: 5.5,
},
- &Passenger{
+ {
Name: []string{"Ford", "Prefect"},
Weight: 7,
},
- &Passenger{
+ {
Name: []string{"Arthur", "Dent"},
Weight: 6.75,
},
@@ -326,12 +326,12 @@ var marshalErrorTests = []struct {
"question": "What do you get when you multiply six by nine?",
"answer": "42",
},
- Err: "xml: unsupported type: map[string] string",
+ Err: "xml: unsupported type: map[string]string",
Kind: reflect.Map,
},
{
Value: map[*Ship]bool{nil: false},
- Err: "xml: unsupported type: map[*xml.Ship] bool",
+ Err: "xml: unsupported type: map[*xml.Ship]bool",
Kind: reflect.Map,
},
}
diff --git a/libgo/go/encoding/xml/read.go b/libgo/go/encoding/xml/read.go
index c6a3d75..6dd3654 100644
--- a/libgo/go/encoding/xml/read.go
+++ b/libgo/go/encoding/xml/read.go
@@ -486,19 +486,19 @@ func copyValue(dst reflect.Value, src []byte) (err error) {
// Helper functions for integer and unsigned integer conversions
var itmp int64
getInt64 := func() bool {
- itmp, err = strconv.Atoi64(string(src))
+ itmp, err = strconv.ParseInt(string(src), 10, 64)
// TODO: should check sizes
return err == nil
}
var utmp uint64
getUint64 := func() bool {
- utmp, err = strconv.Atoui64(string(src))
+ utmp, err = strconv.ParseUint(string(src), 10, 64)
// TODO: check for overflow?
return err == nil
}
var ftmp float64
getFloat64 := func() bool {
- ftmp, err = strconv.Atof64(string(src))
+ ftmp, err = strconv.ParseFloat(string(src), 64)
// TODO: check for overflow?
return err == nil
}
@@ -525,7 +525,7 @@ func copyValue(dst reflect.Value, src []byte) (err error) {
}
t.SetFloat(ftmp)
case reflect.Bool:
- value, err := strconv.Atob(strings.TrimSpace(string(src)))
+ value, err := strconv.ParseBool(strings.TrimSpace(string(src)))
if err != nil {
return err
}
diff --git a/libgo/go/encoding/xml/xml.go b/libgo/go/encoding/xml/xml.go
index d67a299..d001c40 100644
--- a/libgo/go/encoding/xml/xml.go
+++ b/libgo/go/encoding/xml/xml.go
@@ -889,9 +889,9 @@ Input:
var n uint64
var err error
if i >= 3 && s[1] == 'x' {
- n, err = strconv.Btoui64(s[2:], 16)
+ n, err = strconv.ParseUint(s[2:], 16, 64)
} else {
- n, err = strconv.Btoui64(s[1:], 10)
+ n, err = strconv.ParseUint(s[1:], 10, 64)
}
if err == nil && n <= unicode.MaxRune {
text = string(n)