diff options
author | Ondřej Surý <ondrej@sury.org> | 2012-03-26 16:50:58 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2012-03-26 16:50:58 +0200 |
commit | 519725bb3c075ee2462c929f5997cb068e18466a (patch) | |
tree | 5b162e8488ad147a645048c073577821b4a2bee9 /src/pkg/encoding/gob | |
parent | 842623c5dd2819d980ca9c58048d6bc6ed82475f (diff) | |
download | golang-upstream-weekly/2012.03.22.tar.gz |
Imported Upstream version 2012.03.22upstream-weekly/2012.03.22
Diffstat (limited to 'src/pkg/encoding/gob')
-rw-r--r-- | src/pkg/encoding/gob/decode.go | 3 | ||||
-rw-r--r-- | src/pkg/encoding/gob/doc.go | 2 | ||||
-rw-r--r-- | src/pkg/encoding/gob/encoder_test.go | 4 | ||||
-rw-r--r-- | src/pkg/encoding/gob/gobencdec_test.go | 19 |
4 files changed, 25 insertions, 3 deletions
diff --git a/src/pkg/encoding/gob/decode.go b/src/pkg/encoding/gob/decode.go index 0708a83c9..e32a178ab 100644 --- a/src/pkg/encoding/gob/decode.go +++ b/src/pkg/encoding/gob/decode.go @@ -707,6 +707,9 @@ func (dec *Decoder) decodeInterface(ityp reflect.Type, state *decoderState, p ui if name == "" { // Copy the representation of the nil interface value to the target. // This is horribly unsafe and special. + if indir > 0 { + p = allocate(ityp, p, 1) // All but the last level has been allocated by dec.Indirect + } *(*[2]uintptr)(unsafe.Pointer(p)) = ivalue.InterfaceData() return } diff --git a/src/pkg/encoding/gob/doc.go b/src/pkg/encoding/gob/doc.go index c9ad18e76..96885f8de 100644 --- a/src/pkg/encoding/gob/doc.go +++ b/src/pkg/encoding/gob/doc.go @@ -226,7 +226,7 @@ where * signifies zero or more repetitions and the type id of a value must be predefined or be defined before the value in the stream. See "Gobs of data" for a design discussion of the gob wire format: -http://blog.golang.org/2011/03/gobs-of-data.html +http://golang.org/doc/articles/gobs_of_data.html */ package gob diff --git a/src/pkg/encoding/gob/encoder_test.go b/src/pkg/encoding/gob/encoder_test.go index 050786dfd..c4947cbb8 100644 --- a/src/pkg/encoding/gob/encoder_test.go +++ b/src/pkg/encoding/gob/encoder_test.go @@ -694,8 +694,8 @@ type Bug3 struct { func TestGobPtrSlices(t *testing.T) { in := []*Bug3{ - &Bug3{1, nil}, - &Bug3{2, nil}, + {1, nil}, + {2, nil}, } b := new(bytes.Buffer) err := NewEncoder(b).Encode(&in) diff --git a/src/pkg/encoding/gob/gobencdec_test.go b/src/pkg/encoding/gob/gobencdec_test.go index 83644c033..45240d764 100644 --- a/src/pkg/encoding/gob/gobencdec_test.go +++ b/src/pkg/encoding/gob/gobencdec_test.go @@ -573,3 +573,22 @@ func TestGobEncodeIsZero(t *testing.T) { t.Fatalf("%v != %v", x, y) } } + +func TestGobEncodePtrError(t *testing.T) { + var err error + b := new(bytes.Buffer) + enc := NewEncoder(b) + err = enc.Encode(&err) + if err != nil { + t.Fatal("encode:", err) + } + dec := NewDecoder(b) + err2 := fmt.Errorf("foo") + err = dec.Decode(&err2) + if err != nil { + t.Fatal("decode:", err) + } + if err2 != nil { + t.Fatalf("expected nil, got %v", err2) + } +} |