]> Cypherpunks repositories - gostls13.git/commit
encoding/json: don't cache value addressability when building first encoder
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 24 Sep 2013 02:57:19 +0000 (19:57 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 24 Sep 2013 02:57:19 +0000 (19:57 -0700)
commit0f3ea75020cf7dda64805fe9aeef26be60cf16cd
tree6b45914bd37441059314ff2fffa94303d57dc6fb
parente8bbbe0886ffbd87de8ea827be5c43d8566b98d1
encoding/json: don't cache value addressability when building first encoder

newTypeEncoder (called once per type and then cached) was
looking at the first value seen of that type's addressability
and caching the encoder decision.  If the first value seen was
addressable and a future one wasn't, it would panic.

Instead, introduce a new wrapper encoder type that checks
CanAddr at runtime.

Fixes #6458

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/13839045
src/pkg/encoding/json/encode.go
src/pkg/encoding/json/encode_test.go