1
0
mirror of https://github.com/golang/go synced 2024-10-04 14:41:25 -06:00
Commit Graph

290 Commits

Author SHA1 Message Date
Ian Lance Taylor
941db1ed39 encoding/gob: consistently use unsafe.Pointer for pointer values
Fixes #5621.

R=golang-dev, cshapiro, r, fullung
CC=golang-dev
https://golang.org/cl/9988043
2013-06-04 06:20:57 -07:00
Gerasimos Dimitriadis
af48543c54 asn1: Stricter checks for DER encoded booleans
According to X.690, only 0 and 255 are allowed as values
for encoded booleans. Also added some test for parsing
booleans

R=golang-dev, agl, r
CC=golang-dev
https://golang.org/cl/9692043
2013-05-24 12:37:42 -04:00
Brad Fitzpatrick
f1583bb956 encoding/json: allocate less in NewEncoder
The *Encoder is almost always garbage. It doesn't need an
encodeState inside of it (and its bytes.Buffer), since it's
only needed locally inside of Encode.

benchmark                 old ns/op    new ns/op    delta
BenchmarkEncoderEncode         2562         2553   -0.35%

benchmark                 old bytes    new bytes    delta
BenchmarkEncoderEncode          283          102  -63.96%

R=r
CC=gobot, golang-dev
https://golang.org/cl/9365044
2013-05-14 15:50:46 -07:00
Shenghou Ma
5c20a4f260 encoding/json: document that marshaling invalid utf-8 sequence will return error
Also added docs for InvalidUTF8Error.
Fixes #5360.

R=golang-dev, adg, r
CC=golang-dev
https://golang.org/cl/8926046
2013-04-30 11:21:48 +08:00
Rob Pike
88f9ab8926 encoding/json: documentation regarding anonymous fields.
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/8545046
2013-04-11 12:46:23 -07:00
Rob Pike
5fd708c000 encoding/json: different decision on tags and shadowing
If there are no tags, the rules are the same as before.
If there is a tagged field, choose it if there is exactly one
at the top level of all fields.
More tests. The old tests were clearly inadequate, since
they all pass as is. The new tests only work with the new code.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/8617044
2013-04-10 13:05:34 -07:00
Rob Pike
357e37dc94 encoding/json: fix handling of anonymous fields
The old code was incorrect and also broken. It passed the tests by accident.
The new algorithm is:
        1) Sort the fields in order of names.
        2) For all fields with the same name, sort in increasing depth.
        3) Choose the single field with shortest depth.
If any of the fields of a given name has a tag, do the above using
tagged fields of that name only.
Fixes #5245.

R=iant
CC=golang-dev
https://golang.org/cl/8583044
2013-04-09 15:00:21 -07:00
Russ Cox
f6d0adedb6 build: remove dead code
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7877045
2013-03-22 17:28:22 -04:00
Rob Pike
f29b091110 encoding/gob: delete dead code.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7834047
2013-03-22 14:22:55 -07:00
Olivier Saingre
f74eb6dbf7 encoding/xml: rewrite invalid code points to U+FFFD in Marshal, Escape
Fixes #4235.

R=rsc, dave, r, dr.volker.dobler
CC=golang-dev
https://golang.org/cl/7438051
2013-03-13 23:26:03 -04:00
Rick Arnold
cb8aebf19d encoding/json: properly handle extra objects with fixed size arrays
If a fixed size array is passed in as the decode target and the JSON
to decode has extra array elements that are objects, then previously
the decoder would return a "data changing underfoot" error.

Fixes #3717.

R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/7490046
2013-03-13 14:53:03 -04:00
Russ Cox
bdf8bf6adc encoding/xml: predefine xml name space prefix
Also change prefix generation to use more human-friendly prefixes.

Fixes #5040.

R=golang-dev, r, bradfitz
CC=golang-dev
https://golang.org/cl/7777047
2013-03-13 14:36:42 -04:00
Russ Cox
bfe80e21e4 encoding/xml: reject > chain with non-element
Fixes #5033.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7764044
2013-03-12 16:42:25 -04:00
Russ Cox
4dd3e1e844 encoding/xml: name space bug fixes
If two fields have the same name but different explicit name spaces,
treat as non-conflicting. This allows parsing common XML formats
that have ns1:tag and ns2:tag in the same XML element.
Fixes #4691.

Allow setting the default name space for unadorned tags, by
writing to Decoder.DefaultSpace. This allows turned the job of
parsing common XML formats that have tag and ns2:tag in the
same XML element into the first case by setting DefaultSpace="ns1".
Fixes #3703.

Use name space attributes when decoding.
Attach name space to attributes when encoding.
Could be done with fewer annotations, but semantically correct as is.
Fixes #3526.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7227056
2013-03-12 11:46:12 -04:00
Philip K. Warren
b4237b5997 encoding/base32, encoding/base64: fix issues with decoder whitespace handling
Adds a new reader to filter newlines, which fixes errors seen in the
decoder chunking code. Found additional issues with whitespace handling
after the first padding character.
Fixes #4779.

R=minux.ma, rsc, bradfitz
CC=golang-dev
https://golang.org/cl/7311069
2013-03-12 01:50:10 -04:00
Russ Cox
019754ed40 encoding/xml: fix spurious "no semicolon" in error
Noticed while doing other XML investigations.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7550045
2013-03-12 00:29:36 -04:00
Russ Cox
aa81eb5901 encoding/xml: allow embedded non-structs
The old code just assumed that the only thing
you can embed is a struct. Not true.

Fixes #3803.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7743043
2013-03-11 23:58:20 -04:00
Nigel Tao
96e0c0c764 encoding/base32, encoding/base64: a small stack-space optimization.
R=dsymonds, dave
CC=golang-dev
https://golang.org/cl/7568045
2013-03-12 11:24:24 +11:00
Nigel Tao
79d06d7286 encoding/base32: don't panic when decoding "AAAA==".
Edit encoding/base64's internals and tests to match encoding/base32.

Properly handling line breaks in padding is left for another CL.

R=dsymonds
CC=golang-dev
https://golang.org/cl/7693044
2013-03-12 11:07:36 +11:00
Brad Fitzpatrick
e15c0ac693 all: remove now-unnecessary unreachable panics
Take advantage of the new terminating statement rule.

R=golang-dev, r, gri
CC=golang-dev
https://golang.org/cl/7712044
2013-03-11 14:16:55 -07:00
Albert Strasheim
0a71a5b029 all: Skip AllocsPerRun tests if GOMAXPROCS>1.
Fixes #4974.

R=rsc, bradfitz, r
CC=golang-dev
https://golang.org/cl/7545043
2013-03-06 15:52:32 -08:00
Russ Cox
349cc74867 encoding/gob: fix copyright
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7423046
2013-02-28 13:30:59 -08:00
Rob Pike
707ab1347f all: fix some vet-found printf errors
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7393059
2013-02-25 12:43:03 -08:00
Olivier Saingre
afde71cfbd encoding/xml: make sure Encoder.Encode reports Write errors.
Fixes #4112.

R=remyoudompheng, daniel.morsing, dave, rsc
CC=golang-dev
https://golang.org/cl/7085053
2013-02-20 14:41:23 -08:00
Russ Cox
2b9787c2f3 encoding/binary: make type error more specific
Right now it says 'invalid type S' for a struct type S.
Instead, say which type inside the struct is the problem.

Fixes #4825.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7301102
2013-02-15 13:12:28 -05:00
Russ Cox
30359a55c2 encoding/json: document and test use of unicode.ReplacementChar
Fixes #4783.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7314099
2013-02-14 14:56:01 -05:00
Russ Cox
d340a89d9c encoding/json: roll back Unmarshal optimization + test
The second attempt at the Unmarshal optimization allowed
panics to get out of the json package. Add test for that bug
and remove the optimization.

Let's stop trying to optimize Unmarshal.

Fixes #4784.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7300108
2013-02-14 14:46:15 -05:00
Shenghou Ma
83da2014a8 encoding/xml: fix htmlAutoClose and its generating script
Thanks Mitică for reporting this.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7308081
2013-02-13 02:27:42 +08:00
Shivakumar GN
848d10f06c xml: omit newline at beginning of MarshalIndent output
(Still valid XML.)

Fixes #3354.

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/7288047
2013-02-03 11:21:07 -05:00
Kyle Lemons
9bfd3c3937 testing: add AllocsPerRun
This CL also replaces similar loops in other stdlib
package tests with calls to AllocsPerRun.

Fixes #4461.

R=minux.ma, rsc
CC=golang-dev
https://golang.org/cl/7002055
2013-02-02 22:52:29 -05:00
Russ Cox
31fafa5081 encoding/base64: fix test for ReadFull change
R=golang-dev
CC=golang-dev
https://golang.org/cl/7249045
2013-01-31 14:42:56 -08:00
Russ Cox
956cd0059c encoding/json: document case-insensitive Unmarshal key matching
Fixes #4664.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7237060
2013-01-31 07:49:23 -08:00
Rick Arnold
eea0f19990 encoding/json: improve performance of Unmarshal on primitive types
Attempt 2. The first fix was much faster but ignored syntax errors.

benchmark                      old ns/op    new ns/op    delta
BenchmarkCodeEncoder            74993543     72982390   -2.68%
BenchmarkCodeMarshal            77811181     75610637   -2.83%
BenchmarkCodeDecoder           213337123    190144982  -10.87%
BenchmarkCodeUnmarshal         212180972    190394852  -10.27%
BenchmarkCodeUnmarshalReuse    202113428    182106660   -9.90%
BenchmarkUnmarshalString            1343          919  -31.57%
BenchmarkUnmarshalFloat64           1149          908  -20.97%
BenchmarkUnmarshalInt64              967          778  -19.54%
BenchmarkSkipValue              28851581     28414125   -1.52%

benchmark                       old MB/s     new MB/s  speedup
BenchmarkCodeEncoder               25.88        26.59    1.03x
BenchmarkCodeMarshal               24.94        25.66    1.03x
BenchmarkCodeDecoder                9.10        10.21    1.12x
BenchmarkCodeUnmarshal              9.15        10.19    1.11x
BenchmarkSkipValue                 69.05        70.11    1.02x

Fixes #3949.

R=rsc
CC=golang-dev
https://golang.org/cl/7231058
2013-01-30 17:53:48 -08:00
Andrey Mirtchovski
e579395905 encoding/json: properly unmarshal empty arrays.
The JSON unmarshaller failed to allocate an array when there
are no values for the input causing the `[]` unmarshalled
to []interface{} to generate []interface{}(nil) rather than
[]interface{}{}. This wasn't caught in the tests because Decode()
works correctly and because jsonBig never generated zero-sized
arrays. The modification to scanner_test.go quickly triggers
the error:

without the change to decoder.go, but with the change to scanner_test.go:

$ go test
--- FAIL: TestUnmarshalMarshal (0.10 seconds)
decode_test.go:446:		Marshal jsonBig
scanner_test.go:206:	diverge at 70: «03c1OL6$":null},{"[=» vs «03c1OL6$":[]},{"[=^\»
FAIL
exit status 1
FAIL	encoding/json	0.266s

Also added a simple regression to decode_test.go.

R=adg, dave, rsc
CC=golang-dev
https://golang.org/cl/7196050
2013-01-30 09:10:32 -08:00
Russ Cox
ee90874826 encoding/xml: add (*Encoder).Indent
Exposing this on the Encoder allows streaming generation of indented XML.

R=golang-dev, rogpeppe
CC=golang-dev
https://golang.org/cl/7221075
2013-01-30 07:57:20 -08:00
Russ Cox
ad37081b67 encoding/json: add test for Unmarshal of malformed data
Roll back CL making primitive type unmarshal faster,
because it broke the Unmarshal of malformed data.

Add benchmarks for unmarshal of primitive types.

Update #3949.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7228061
2013-01-29 13:34:18 -08:00
Brad Fitzpatrick
91e99c1345 encoding/json: add Decoder.Buffered accessor to get overread data
Otherwise it's impossible to know how much data from the
json.Decoder's underlying Reader was actually consumed.

The old fix from golang.org/issue/1955 just added docs. This
provides an actual mechanism.

Update #1955

R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/7181053
2013-01-28 16:31:46 -08:00
Vega Garcia Luis Alfonso
cf1f542420 xml: differentiate between float32 and float64 for marshalSimple
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7235045
2013-01-28 12:54:27 -05:00
Vega Garcia Luis Alfonso
14bd52db3f xml: Support fields not of type []byte when marshaling ",chardata"
Fixes #4506.

R=rsc, remyoudompheng
CC=golang-dev
https://golang.org/cl/7106045
2013-01-22 22:13:40 -05:00
Rick Arnold
6e3f3af4e0 encoding/json: ignore unexported fields in Unmarshal
Go 1.0 behavior was to create an UnmarshalFieldError when a json value name matched an unexported field name. This error will no longer be created and the field will be skipped instead.

Fixes #4660.

R=adg, rsc, bradfitz
CC=golang-dev
https://golang.org/cl/7139049
2013-01-22 17:49:07 -05:00
Russ Cox
9114279c66 encoding/xml: simplify copyValue
Delete various complications left over from an earlier reflect API.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7124063
2013-01-22 17:05:45 -05:00
Kamil Kisiel
4730a226ca encoding/xml: fix decoding of attributes in to pointer fields.
Fixes #3719.

R=anacrolix, rsc
CC=golang-dev
https://golang.org/cl/7131052
2013-01-18 17:07:34 -05:00
Rémy Oudompheng
406ca3c2f1 encoding/json: fix panics on type mismatches.
Fixes #4222.
Fixes #4628.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7100049
2013-01-14 08:44:16 +01:00
Alex Brainman
06af0ea3f3 encoding/gob: fix broken test (fix build)
R=golang-dev, kevlar
CC=adg, golang-dev
https://golang.org/cl/7093056
2013-01-14 17:03:19 +11:00
Kyle Lemons
bc1152a32e encoding/gob: handle encoding of different indirects of GobEncoder
Fixes #4647.

R=r, golang-dev
CC=golang-dev
https://golang.org/cl/7085051
2013-01-14 16:07:11 +11:00
Rick Arnold
60abc6b577 encoding/json: improve performance of Unmarshal on primitive types
Skip most of the scanning and parsing logic for simple (non-object/array) JSON values.

benchmark                   old ns/op    new ns/op    delta
BenchmarkUnmarshalInt             948          436  -54.01%
BenchmarkUnmarshalUint            930          427  -54.09%
BenchmarkUnmarshalString         1407          715  -49.18%
BenchmarkUnmarshalFloat          1114          536  -51.89%
BenchmarkUnmarshalBool            759          266  -64.95%
BenchmarkUnmarshalStruct         8165         8181   +0.20%

No significant effects on the go1 benchmarks:

benchmark                 old ns/op    new ns/op    delta
BenchmarkBinaryTree17    9647362752   9596196417   -0.53%
BenchmarkFannkuch11      5623613048   5518694872   -1.87%
BenchmarkGobDecode         32944041     33165434   +0.67%
BenchmarkGobEncode         21237482     21080554   -0.74%
BenchmarkGzip             750955920    749861980   -0.15%
BenchmarkGunzip           197369742    197886192   +0.26%
BenchmarkJSONEncode        79274091     78891137   -0.48%
BenchmarkJSONDecode       180257802    175280358   -2.76%
BenchmarkMandelbrot200      7396666      7388266   -0.11%
BenchmarkParse             11446460     11386550   -0.52%
BenchmarkRevcomp         1605152523   1599512029   -0.35%
BenchmarkTemplate         204538247    207765574   +1.58%

benchmark                  old MB/s     new MB/s  speedup
BenchmarkGobDecode            23.30        23.14    0.99x
BenchmarkGobEncode            36.14        36.41    1.01x
BenchmarkGzip                 25.84        25.88    1.00x
BenchmarkGunzip               98.32        98.06    1.00x
BenchmarkJSONEncode           24.48        24.60    1.00x
BenchmarkJSONDecode           10.76        11.07    1.03x
BenchmarkParse                 5.06         5.09    1.01x
BenchmarkRevcomp             158.34       158.90    1.00x
BenchmarkTemplate              9.49         9.34    0.98x

Fixes #3949.

R=golang-dev, dave, bradfitz, timo
CC=golang-dev
https://golang.org/cl/7068043
2013-01-10 17:58:45 -08:00
Matthew Dempsky
46811d27ce src: Use bytes.Equal instead of bytes.Compare where possible.
bytes.Equal is simpler to read and should also be faster because
of short-circuiting and assembly implementations.

Change generated automatically using:
  gofmt -r 'bytes.Compare(a, b) == 0 -> bytes.Equal(a, b)'
  gofmt -r 'bytes.Compare(a, b) != 0 -> !bytes.Equal(a, b)'

R=golang-dev, dave, adg, rsc
CC=golang-dev
https://golang.org/cl/7038051
2013-01-07 10:03:49 +11:00
Caleb Spare
396c957a32 encoding/json: documented that ,string applies only to string and numeric fields.
Fixes #4437.

R=golang-dev, adg
CC=golang-dev, rsc
https://golang.org/cl/7064045
2013-01-07 09:44:35 +11:00
Thomas Kappler
cdec0850f8 encoding/json: don't panic marshaling anonymous non-struct field
Add a check for this case and don't try to follow the anonymous
type's non-existent fields.

Fixes #4474.

R=rsc
CC=golang-dev
https://golang.org/cl/6945065
2013-01-02 17:39:41 -05:00
Ryan Slade
a4600126d9 encoding/json: encode map key is of string kind, decode only of string type
Allows encoding and decoding of maps with key of string kind, not just string type.
Fixes #3519.

R=rsc, dave
CC=golang-dev
https://golang.org/cl/6943047
2012-12-30 15:40:42 +11:00