From 519725bb3c075ee2462c929f5997cb068e18466a Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Mon, 26 Mar 2012 16:50:58 +0200 Subject: Imported Upstream version 2012.03.22 --- src/pkg/encoding/gob/decode.go | 3 +++ src/pkg/encoding/gob/doc.go | 2 +- src/pkg/encoding/gob/encoder_test.go | 4 ++-- src/pkg/encoding/gob/gobencdec_test.go | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) (limited to 'src/pkg/encoding/gob') 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) + } +} -- cgit v1.2.3