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

Issue 5503078: code review 5503078: xml: major Go 1 fixup (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 9 months ago by niemeyer
Modified:
14 years, 9 months ago
Reviewers:
knieriem, agl2
CC:
cw, gustavo_niemeyer.net, kevlar, adg, rog, albert.strasheim, tux21b, rsc, golang-dev
Visibility:
Public.

Description

xml: major Go 1 fixup This CL improves the xml package in the following ways: - makes its interface match established conventions - brings Marshal and Unmarshal closer together - fixes a large number of bugs and adds tests - improves speed significantly - organizes and simplifies the code Fixes issue 2426. Fixes issue 2406. Fixes issue 1989. What follows is a detailed list of those changes. - All matching is case sensitive without special processing to the field name or xml tag in an attempt to match them. Customize the field tag as desired to match the correct XML elements. - Flags are ",flag" rather than "flag". The names "attr", "chardata", etc, may be used to name actual XML elements. - Overriding of attribute names is possible with "name,attr". - Attribute fields are marshalled properly if they have non-string types. Previously they were unmarshalled, but were ignored at marshalling time. - Comment fields tagged with ",comment" are marshalled properly, rather than being marshalled as normal fields. - The handling of the Any field has been replaced by the ",any" flag to avoid unexpected results when using the field name for other purposes, and has also been fixed to interact properly with name paths. Previously the feature would not function if any field in the type had a name path in its tag. - Embedded struct support fixed and cleaned so it works when marshalling and also when using field paths deeper than one level. - Conflict reporting on field names have been expanded to cover all fields. Previously it'd catch only conflicts of paths deeper than one level. Also interacts correctly with embedded structs now. - A trailing '>' is disallowed in xml tags. It used to be supported for removing the ambiguity between "attr" and "attr>", but the marshalling support for that was broken, and it's now unnecessary. Use "name" instead of "name>". - Fixed docs to point out that a XMLName doesn't have to be an xml.Name (e.g. a struct{} is a good fit too). The code was already working like that. - Fixed asymmetry in the precedence of XML element names between marshalling and unmarshalling. Marshal would consider the XMLName of the field type before the field tag, while unmarshalling would do the opposite. Now both respect the tag of the XMLName field first, and a nice error message is provided in case an attempt is made to name a field with its tag in a way that would conflict with the underlying type's XMLName field. - Do not marshal broken "<???>" tags when in doubt. Use the type name, and error out if that's not possible. - Do not break down unmarshalling if there's an interface{} field in a struct. - Significant speed boost due to caching of type metadata and overall allocation clean ups. The following timings reflect processing of the the atom test data: Old: BenchmarkMarshal 50000 48798 ns/op BenchmarkUnmarshal 5000 357174 ns/op New: BenchmarkMarshal 100000 19799 ns/op BenchmarkUnmarshal 10000 128525 ns/op

Patch Set 1 #

Patch Set 2 : code review 5503078: xml: major overhaul #

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

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

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

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

Total comments: 81

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

Patch Set 8 : diff -r 9321a5705307 https://go.googlecode.com/hg/ #

Patch Set 9 : diff -r 9321a5705307 https://go.googlecode.com/hg/ #

Total comments: 4

Patch Set 10 : diff -r 9321a5705307 https://go.googlecode.com/hg/ #

Total comments: 2

Patch Set 11 : diff -r 9321a5705307 https://go.googlecode.com/hg/ #

Patch Set 12 : diff -r e8bfc2f65c2b https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1047 lines, -681 lines) Patch
M src/pkg/encoding/xml/Makefile View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M src/pkg/encoding/xml/atom_test.go View 1 2 2 chunks +14 lines, -13 lines 0 comments Download
R src/pkg/encoding/xml/embed_test.go View 1 2 3 4 5 6 7 10 1 chunk +0 lines, -127 lines 0 comments Download
M src/pkg/encoding/xml/marshal.go View 1 2 3 4 5 6 7 7 chunks +161 lines, -96 lines 0 comments Download
M src/pkg/encoding/xml/marshal_test.go View 1 2 3 4 5 6 7 8 14 chunks +326 lines, -109 lines 0 comments Download
M src/pkg/encoding/xml/read.go View 1 2 3 4 5 6 7 14 chunks +135 lines, -203 lines 0 comments Download
M src/pkg/encoding/xml/read_test.go View 1 2 3 4 5 6 7 chunks +68 lines, -112 lines 0 comments Download
A src/pkg/encoding/xml/typeinfo.go View 1 2 3 4 5 6 7 8 9 10 1 chunk +321 lines, -0 lines 0 comments Download
M src/pkg/encoding/xml/xml_test.go View 1 2 3 4 5 6 2 chunks +21 lines, -21 lines 0 comments Download

Messages

Total messages: 50
niemeyer
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg/
14 years, 9 months ago (2011-12-29 05:49:00 UTC) #1
cw
Wow, this is heroic and really great to see. A quick glance over this right ...
14 years, 9 months ago (2011-12-29 06:10:30 UTC) #2
niemeyer
http://codereview.appspot.com/5503078/diff/2009/src/pkg/encoding/xml/atom_test.go File src/pkg/encoding/xml/atom_test.go (right): http://codereview.appspot.com/5503078/diff/2009/src/pkg/encoding/xml/atom_test.go#newcode28 src/pkg/encoding/xml/atom_test.go:28: `<title>Example Feed</title>` + > why the case change here? ...
14 years, 9 months ago (2011-12-29 06:19:47 UTC) #3
cw
LGMT After fixing some local bugs am now using this without any noticeable problems.
14 years, 9 months ago (2011-12-29 23:04:28 UTC) #4
gustavo_niemeyer.net
> LGMT > > After fixing some local bugs am now using this without any ...
14 years, 9 months ago (2011-12-29 23:26:31 UTC) #5
kevlar
Ah, you are my hero. Though I'd like this even better if it also fixed ...
14 years, 9 months ago (2011-12-29 23:35:57 UTC) #6
niemeyer
> Though I'd like this even better if it also fixed 2626 ;-). I've looked ...
14 years, 9 months ago (2011-12-30 00:48:00 UTC) #7
kevlar
LGTM Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' I had ...
14 years, 9 months ago (2011-12-30 01:06:44 UTC) #8
niemeyer
> LGTM Cheers! > Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* ...
14 years, 9 months ago (2011-12-30 01:23:42 UTC) #9
adg
I really like the improvements to the API in this CL. It's way better. Thanks ...
14 years, 9 months ago (2012-01-02 23:35:36 UTC) #10
rog
this looks just marvellous, thanks Gustavo. nice to see someone was hacking when i was ...
14 years, 9 months ago (2012-01-03 13:53:58 UTC) #11
albert.strasheim
Hello On 2011/12/29 05:49:00, niemeyer wrote: > Hello mailto:golang-dev@googlegroups.com, > > I'd like you to ...
14 years, 9 months ago (2012-01-04 12:23:05 UTC) #12
niemeyer
I'm on holiday and a bit slow this week, but I'll work on the reviews ...
14 years, 9 months ago (2012-01-06 17:26:59 UTC) #13
niemeyer
Thanks for the reviews. The code is ready for another look. http://codereview.appspot.com/5503078/diff/2009/src/pkg/encoding/xml/marshal.go File src/pkg/encoding/xml/marshal.go (right): ...
14 years, 9 months ago (2012-01-08 20:56:56 UTC) #14
rog
http://codereview.appspot.com/5503078/diff/2009/src/pkg/encoding/xml/typeinfo.go File src/pkg/encoding/xml/typeinfo.go (right): http://codereview.appspot.com/5503078/diff/2009/src/pkg/encoding/xml/typeinfo.go#newcode93 src/pkg/encoding/xml/typeinfo.go:93: // Add the field in case it doesn't conflict. ...
14 years, 9 months ago (2012-01-08 22:47:47 UTC) #15
adg
LGTM
14 years, 9 months ago (2012-01-08 23:25:15 UTC) #16
adg
http://codereview.appspot.com/5503078/diff/2009/src/pkg/encoding/xml/read.go File src/pkg/encoding/xml/read.go (right): http://codereview.appspot.com/5503078/diff/2009/src/pkg/encoding/xml/read.go#newcode132 src/pkg/encoding/xml/read.go:132: // the XML element name is not a prefix ...
14 years, 9 months ago (2012-01-08 23:25:31 UTC) #17
niemeyer
http://codereview.appspot.com/5503078/diff/2009/src/pkg/encoding/xml/typeinfo.go File src/pkg/encoding/xml/typeinfo.go (right): http://codereview.appspot.com/5503078/diff/2009/src/pkg/encoding/xml/typeinfo.go#newcode93 src/pkg/encoding/xml/typeinfo.go:93: // Add the field in case it doesn't conflict. ...
14 years, 9 months ago (2012-01-08 23:33:55 UTC) #18
albert.strasheim
Hello On 2012/01/08 20:56:56, niemeyer wrote: > Thanks for the reviews. > > The code ...
14 years, 9 months ago (2012-01-09 04:49:57 UTC) #19
cw
> There's still some comments that refer to a non-existant MarshalIndent > function. I checked ...
14 years, 9 months ago (2012-01-09 05:08:07 UTC) #20
cw
(follow up from earlier, this time with a specific detail) http://codereview.appspot.com/5503078/diff/12012/src/pkg/encoding/xml/read.go File src/pkg/encoding/xml/read.go (left): http://codereview.appspot.com/5503078/diff/12012/src/pkg/encoding/xml/read.go#oldcode178 ...
14 years, 9 months ago (2012-01-09 17:57:05 UTC) #21
gustavo_niemeyer.net
> TagpathError type removed (...) > TagPathError is still used here though Sorry, the last ...
14 years, 9 months ago (2012-01-09 21:46:09 UTC) #22
cw
LGTM
14 years, 9 months ago (2012-01-09 22:38:50 UTC) #23
tux21b
I have just tested the new package a bit and encountered a problem: type Problem ...
14 years, 9 months ago (2012-01-12 15:11:54 UTC) #24
gustavo_niemeyer.net
> I have just tested the new package a bit and encountered a problem: > ...
14 years, 9 months ago (2012-01-12 15:44:15 UTC) #25
rsc
LGTM Thanks very much.
14 years, 9 months ago (2012-01-12 19:47:50 UTC) #26
niemeyer
*** Submitted as http://code.google.com/p/go/source/detail?r=70e914beb409 *** xml: major Go 1 fixup This CL improves the xml ...
14 years, 9 months ago (2012-01-13 10:05:26 UTC) #27
knieriem
Perhaps read.go needs to be slightly adjusted: It still says, matching between XML element names ...
14 years, 9 months ago (2012-01-13 20:23:04 UTC) #28
cw
> -// to exported (upper case) fields. Unmarshal uses a case-insensitive > -// comparison to ...
14 years, 9 months ago (2012-01-13 20:30:07 UTC) #29
rsc
There is not supposed to be any case changes anymore. It's just ==, like in ...
14 years, 9 months ago (2012-01-13 21:11:29 UTC) #30
agl2
On Fri, Jan 13, 2012 at 4:11 PM, Russ Cox <rsc@golang.org> wrote: > There is ...
14 years, 9 months ago (2012-01-14 16:53:22 UTC) #31
gustavo_niemeyer.net
> The documentation still says: > > "Unmarshal uses a case-insensitive comparison to match XML ...
14 years, 9 months ago (2012-01-14 17:06:50 UTC) #32
agl2
On Sat, Jan 14, 2012 at 12:06 PM, Gustavo Niemeyer <gustavo@niemeyer.net> wrote: > Yeah, sorry ...
14 years, 9 months ago (2012-01-14 21:10:04 UTC) #33
agl2
On Sat, Jan 14, 2012 at 4:10 PM, Adam Langley <agl@google.com> wrote: > Cool, no ...
14 years, 9 months ago (2012-01-14 21:10:59 UTC) #34
gustavo_niemeyer.net
> I would have expected the following program to set out.Bar.Local to > "bar", while ...
14 years, 9 months ago (2012-01-15 08:37:39 UTC) #35
agl2
On Sun, Jan 15, 2012 at 3:37 AM, Gustavo Niemeyer <gustavo@niemeyer.net> wrote: > If your ...
14 years, 9 months ago (2012-01-15 18:32:24 UTC) #36
rsc
Let's just fill in the xml.Name always. There's no reason _not_ to fill it in. ...
14 years, 9 months ago (2012-01-15 18:36:48 UTC) #37
rsc
On Sun, Jan 15, 2012 at 13:32, Adam Langley <agl@google.com> wrote: > Yes, it was ...
14 years, 9 months ago (2012-01-15 18:41:53 UTC) #38
agl2
On Sun, Jan 15, 2012 at 1:41 PM, Russ Cox <rsc@golang.org> wrote: > Sorry, crossed ...
14 years, 9 months ago (2012-01-15 18:46:54 UTC) #39
rsc
On Sun, Jan 15, 2012 at 13:46, Adam Langley <agl@google.com> wrote: > It appear that, ...
14 years, 9 months ago (2012-01-15 18:49:14 UTC) #40
gustavo_niemeyer.net
> Interesting, thanks. > We should make x.Bar != nil (for []byte) work too. Sounds ...
14 years, 9 months ago (2012-01-15 20:04:39 UTC) #41
gustavo_niemeyer.net
> Let's just fill in the xml.Name always. > There's no reason _not_ to fill ...
14 years, 9 months ago (2012-01-15 20:05:25 UTC) #42
rsc
On Sun, Jan 15, 2012 at 15:05, Gustavo Niemeyer <gustavo@niemeyer.net> wrote: > The point is ...
14 years, 9 months ago (2012-01-15 20:25:29 UTC) #43
gustavo_niemeyer.net
> That's different. If there's another way for Adam to get what > he wants, ...
14 years, 9 months ago (2012-01-15 21:47:03 UTC) #44
rsc
On Sun, Jan 15, 2012 at 13:32, Adam Langley <agl@google.com> wrote: > Yes, it was ...
14 years, 9 months ago (2012-01-16 20:10:49 UTC) #45
gustavo_niemeyer.net
On Mon, Jan 16, 2012 at 18:10, Russ Cox <rsc@golang.org> wrote: > On Sun, Jan ...
14 years, 9 months ago (2012-01-16 20:18:07 UTC) #46
rsc
On Mon, Jan 16, 2012 at 15:17, Gustavo Niemeyer <gustavo@niemeyer.net> wrote: >> FWIW, *struct{} should ...
14 years, 9 months ago (2012-01-16 20:35:28 UTC) #47
gustavo_niemeyer.net
>> That's a curious way to spell "bool". > > bool means that the xml ...
14 years, 9 months ago (2012-01-16 20:49:02 UTC) #48
rsc
On Mon, Jan 16, 2012 at 15:48, Gustavo Niemeyer <gustavo@niemeyer.net> wrote: > Yes, I understand ...
14 years, 9 months ago (2012-01-16 20:52:16 UTC) #49
gustavo_niemeyer.net
14 years, 9 months ago (2012-01-16 22:05:11 UTC) #50
> Are you suggesting an API change?  I wasn't.

I already did, and was pondering out loud since I'm not sure the use
case guarantees it. Anyway, I'll focus on the growing to-do.

-- 
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/plus
http://niemeyer.net/twitter
http://niemeyer.net/blog

-- I'm not absolutely sure of anything.
Sign in to reply to this message.

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