Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7719)

Issue 13839045: code review 13839045: encoding/json: don't cache value addressability when bu... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 6 months ago by bradfitz
Modified:
10 years, 6 months ago
Reviewers:
rsc
CC:
golang-dev, rsc
Visibility:
Public.

Description

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 Issue 6458

Patch Set 1 #

Patch Set 2 : diff -r fa9c4c1f250d https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r fa9c4c1f250d https://go.googlecode.com/hg/ #

Total comments: 5

Patch Set 4 : diff -r fa9c4c1f250d https://go.googlecode.com/hg/ #

Patch Set 5 : diff -r fa9c4c1f250d https://go.googlecode.com/hg/ #

Patch Set 6 : diff -r fa9c4c1f250d https://go.googlecode.com/hg/ #

Total comments: 2

Patch Set 7 : diff -r d0364d7d990d https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+90 lines, -51 lines) Patch
M src/pkg/encoding/json/encode.go View 1 2 3 4 5 6 11 chunks +66 lines, -51 lines 0 comments Download
M src/pkg/encoding/json/encode_test.go View 1 2 3 4 5 6 1 chunk +24 lines, -0 lines 0 comments Download

Messages

Total messages: 10
bradfitz
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg/
10 years, 6 months ago (2013-09-23 22:26:20 UTC) #1
rsc
https://codereview.appspot.com/13839045/diff/3001/src/pkg/encoding/json/encode.go File src/pkg/encoding/json/encode.go (right): https://codereview.appspot.com/13839045/diff/3001/src/pkg/encoding/json/encode.go#newcode361 src/pkg/encoding/json/encode.go:361: // if allowAddr is false, the encoder returned won't ...
10 years, 6 months ago (2013-09-23 22:59:05 UTC) #2
bradfitz
Hello golang-dev@googlegroups.com, rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
10 years, 6 months ago (2013-09-23 23:41:08 UTC) #3
bradfitz
https://codereview.appspot.com/13839045/diff/3001/src/pkg/encoding/json/encode.go File src/pkg/encoding/json/encode.go (right): https://codereview.appspot.com/13839045/diff/3001/src/pkg/encoding/json/encode.go#newcode361 src/pkg/encoding/json/encode.go:361: // if allowAddr is false, the encoder returned won't ...
10 years, 6 months ago (2013-09-23 23:43:27 UTC) #4
bradfitz
Hello golang-dev@googlegroups.com, rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
10 years, 6 months ago (2013-09-24 00:24:59 UTC) #5
bradfitz
PTAL Simplified newStructEncoder now too. Please pay the most attention to that part (and its ...
10 years, 6 months ago (2013-09-24 00:25:40 UTC) #6
rsc
looking more closely at the loop at 620... https://codereview.appspot.com/13839045/diff/4/src/pkg/encoding/json/encode_test.go File src/pkg/encoding/json/encode_test.go (right): https://codereview.appspot.com/13839045/diff/4/src/pkg/encoding/json/encode_test.go#newcode420 src/pkg/encoding/json/encode_test.go:420: t.Errorf("Got ...
10 years, 6 months ago (2013-09-24 02:39:59 UTC) #7
rsc
LGTM I see you figured out the vxf.IsValid thing.
10 years, 6 months ago (2013-09-24 02:42:26 UTC) #8
bradfitz
Yeah, I'm much happier with the struct encoder now, and happy to see the vx ...
10 years, 6 months ago (2013-09-24 02:53:50 UTC) #9
bradfitz
10 years, 6 months ago (2013-09-24 02:57:23 UTC) #10
*** Submitted as https://code.google.com/p/go/source/detail?r=411ac795f84e ***

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 Issue 6458

R=golang-dev, rsc
CC=golang-dev
https://codereview.appspot.com/13839045
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b