ruby-changes:54922
From: hsbt <ko1@a...>
Date: Sat, 23 Feb 2019 12:44:04 +0900 (JST)
Subject: [ruby-changes:54922] hsbt:r67127 (trunk): Merge json-2.2.0 from flori/json.
hsbt 2019-02-23 12:43:58 +0900 (Sat, 23 Feb 2019) New Revision: 67127 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67127 Log: Merge json-2.2.0 from flori/json. https://github.com/flori/json/releases/tag/v2.2.0 Added files: trunk/ext/json/lib/json/add/set.rb Modified files: trunk/ext/json/generator/generator.c trunk/ext/json/json.gemspec trunk/ext/json/lib/json/add/ostruct.rb trunk/ext/json/lib/json/version.rb trunk/ext/json/parser/parser.c trunk/test/json/json_addition_test.rb trunk/test/json/test_helper.rb Index: ext/json/generator/generator.c =================================================================== --- ext/json/generator/generator.c (revision 67126) +++ ext/json/generator/generator.c (revision 67127) @@ -1267,7 +1267,7 @@ static VALUE cState_allow_nan_p(VALUE se https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L1267 /* * call-seq: ascii_only? * - * Returns true, if NaN, Infinity, and -Infinity should be generated, otherwise + * Returns true, if only ASCII characters should be generated. Otherwise * returns false. */ static VALUE cState_ascii_only_p(VALUE self) Index: ext/json/lib/json/version.rb =================================================================== --- ext/json/lib/json/version.rb (revision 67126) +++ ext/json/lib/json/version.rb (revision 67127) @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/version.rb#L1 # frozen_string_literal: false module JSON # JSON version - VERSION = '2.1.0' + VERSION = '2.2.0' VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc: VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc: VERSION_MINOR = VERSION_ARRAY[1] # :nodoc: Index: ext/json/lib/json/add/ostruct.rb =================================================================== --- ext/json/lib/json/add/ostruct.rb (revision 67126) +++ ext/json/lib/json/add/ostruct.rb (revision 67127) @@ -23,7 +23,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/add/ostruct.rb#L23 } end - # Stores class name (OpenStruct) with this struct's values <tt>v</tt> as a + # Stores class name (OpenStruct) with this struct's values <tt>t</tt> as a # JSON string. def to_json(*args) as_json.to_json(*args) Index: ext/json/lib/json/add/set.rb =================================================================== --- ext/json/lib/json/add/set.rb (nonexistent) +++ ext/json/lib/json/add/set.rb (revision 67127) @@ -0,0 +1,29 @@ https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/add/set.rb#L1 +unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED + require 'json' +end +defined?(::Set) or require 'set' + +class Set + # Import a JSON Marshalled object. + # + # method used for JSON marshalling support. + def self.json_create(object) + new object['a'] + end + + # Marshal the object to JSON. + # + # method used for JSON marshalling support. + def as_json(*) + { + JSON.create_id => self.class.name, + 'a' => to_a, + } + end + + # return the JSON value + def to_json(*args) + as_json.to_json(*args) + end +end + Index: ext/json/json.gemspec =================================================================== Binary files ext/json/json.gemspec (revision 67126) and ext/json/json.gemspec (revision 67127) differ Index: ext/json/parser/parser.c =================================================================== --- ext/json/parser/parser.c (revision 67126) +++ ext/json/parser/parser.c (revision 67127) @@ -100,11 +100,11 @@ static ID i_json_creatable_p, i_json_cre https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L100 i_leftshift, i_new, i_BigDecimal; -#line 125 "parser.rl" +#line 126 "parser.rl" -#line 107 "parser.c" +#line 108 "parser.c" enum {JSON_object_start = 1}; enum {JSON_object_first_final = 27}; enum {JSON_object_error = 0}; @@ -112,7 +112,7 @@ enum {JSON_object_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L112 enum {JSON_object_en_main = 1}; -#line 166 "parser.rl" +#line 167 "parser.rl" static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting) @@ -128,14 +128,14 @@ static char *JSON_parse_object(JSON_Pars https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L128 *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class); -#line 131 "parser.c" +#line 132 "parser.c" { cs = JSON_object_start; } -#line 181 "parser.rl" +#line 182 "parser.rl" -#line 138 "parser.c" +#line 139 "parser.c" { if ( p == pe ) goto _test_eof; @@ -163,7 +163,7 @@ case 2: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L163 goto st2; goto st0; tr2: -#line 148 "parser.rl" +#line 149 "parser.rl" { char *np; json->parsing_name = 1; @@ -176,7 +176,7 @@ st3: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L176 if ( ++p == pe ) goto _test_eof3; case 3: -#line 179 "parser.c" +#line 180 "parser.c" switch( (*p) ) { case 13: goto st3; case 32: goto st3; @@ -243,7 +243,7 @@ case 8: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L243 goto st8; goto st0; tr11: -#line 133 "parser.rl" +#line 134 "parser.rl" { VALUE v = Qnil; char *np = JSON_parse_value(json, p, pe, &v, current_nesting); @@ -263,7 +263,7 @@ st9: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L263 if ( ++p == pe ) goto _test_eof9; case 9: -#line 266 "parser.c" +#line 267 "parser.c" switch( (*p) ) { case 13: goto st9; case 32: goto st9; @@ -352,14 +352,14 @@ case 18: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L352 goto st9; goto st18; tr4: -#line 156 "parser.rl" +#line 157 "parser.rl" { p--; {p++; cs = 27; goto _out;} } goto st27; st27: if ( ++p == pe ) goto _test_eof27; case 27: -#line 362 "parser.c" +#line 363 "parser.c" goto st0; st19: if ( ++p == pe ) @@ -457,7 +457,7 @@ case 26: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L457 _out: {} } -#line 182 "parser.rl" +#line 183 "parser.rl" if (cs >= JSON_object_first_final) { if (json->create_additions) { @@ -482,7 +482,7 @@ case 26: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L482 -#line 485 "parser.c" +#line 486 "parser.c" enum {JSON_value_start = 1}; enum {JSON_value_first_final = 29}; enum {JSON_value_error = 0}; @@ -490,7 +490,7 @@ enum {JSON_value_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L490 enum {JSON_value_en_main = 1}; -#line 282 "parser.rl" +#line 283 "parser.rl" static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting) @@ -498,14 +498,14 @@ static char *JSON_parse_value(JSON_Parse https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L498 int cs = EVIL; -#line 501 "parser.c" +#line 502 "parser.c" { cs = JSON_value_start; } -#line 289 "parser.rl" +#line 290 "parser.rl" -#line 508 "parser.c" +#line 509 "parser.c" { if ( p == pe ) goto _test_eof; @@ -539,14 +539,14 @@ st0: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L539 cs = 0; goto _out; tr2: -#line 234 "parser.rl" +#line 235 "parser.rl" { char *np = JSON_parse_string(json, p, pe, result); if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;} } goto st29; tr3: -#line 239 "parser.rl" +#line 240 "parser.rl" { char *np; if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) { @@ -566,7 +566,7 @@ tr3: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L566 } goto st29; tr7: -#line 257 "parser.rl" +#line 258 "parser.rl" { char *np; np = JSON_parse_array(json, p, pe, result, current_nesting + 1); @@ -574,7 +574,7 @@ tr7: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L574 } goto st29; tr11: -#line 263 "parser.rl" +#line 264 "parser.rl" { char *np; np = JSON_parse_object(json, p, pe, result, current_nesting + 1); @@ -582,7 +582,7 @@ tr11: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L582 } goto st29; tr25: -#line 227 "parser.rl" +#line 228 "parser.rl" { if (json->allow_nan) { *result = CInfinity; @@ -592,7 +592,7 @@ tr25: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L592 } goto st29; tr27: -#line 220 "parser.rl" +#line 221 "parser.rl" { if (json->allow_nan) { *result = CNaN; @@ -602,19 +602,19 @@ tr27: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L602 } goto st29; tr31: -#line 214 "parser.rl" +#line 215 "parser.rl" { *result = Qfalse; } goto st29; tr34: -#line 211 "parser.rl" +#line 212 "parser.rl" { *result = Qnil; } goto st29; tr37: -#line 217 "parser.rl" +#line 218 "parser.rl" { *result = Qtrue; } @@ -623,9 +623,9 @@ st29: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L623 if ( ++p == pe ) goto _test_eof29; case 29: -#line 269 "parser.rl" +#line 270 "parser.rl" { p--; {p++; cs = 29; goto _out;} } -#line 628 "parser.c" +#line 629 "parser.c" switch( (*p) ) { case 13: goto st29; case 32: goto st29; @@ -866,7 +866,7 @@ case 28: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L866 _out: {} } -#line 290 "parser.rl" +#line 291 "parser.rl" if (cs >= JSON_value_first_final) { return p; @@ -876,7 +876,7 @@ case 28: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L876 } -#line 879 "parser.c" +#line 880 "parser.c" enum {JSON_integer_start = 1}; enum {JSON_integer_first_final = 3}; enum {JSON_integer_error = 0}; @@ -884,7 +884,7 @@ enum {JSON_integer_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L884 enum {JSON_integer_en_main = 1}; -#line 306 "parser.rl" +#line 307 "parser.rl" static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -892,15 +892,15 @@ static char *JSON_parse_integer(JSON_Par https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L892 int cs = EVIL; -#line 895 "parser.c" +#line 896 "parser.c" { cs = JSON_integer_start; } -#line 313 "parser.rl" +#line 314 "parser.rl" json->memo = p; -#line 903 "parser.c" +#line 904 "parser.c" { if ( p == pe ) goto _test_eof; @@ -934,14 +934,14 @@ case 3: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L934 goto st0; goto tr4; tr4: -#line 303 "parser.rl" +#line 304 "parser.rl" { p--; {p++; cs = 4; goto _out;} } goto st4; st4: if ( ++p == pe ) goto _test_eof4; case 4: -#line 944 "parser.c" +#line 945 "parser.c" goto st0; st5: if ( ++p == pe ) @@ -960,7 +960,7 @@ case 5: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L960 _out: {} } -#line 315 "parser.rl" +#line 316 "parser.rl" if (cs >= JSON_integer_first_final) { long len = p - json->memo; @@ -975,7 +975,7 @@ case 5: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L975 } -#line 978 "parser.c" +#line 979 "parser.c" enum {JSON_float_start = 1}; enum {JSON_float_first_final = 8}; enum {JSON_float_error = 0}; @@ -983,7 +983,7 @@ enum {JSON_float_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L983 enum {JSON_float_en_main = 1}; -#line 340 "parser.rl" +#line 341 "parser.rl" static int is_bigdecimal_class(VALUE obj) @@ -1004,15 +1004,15 @@ static char *JSON_parse_float(JSON_Parse https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1004 int cs = EVIL; -#line 994 "parser.c" +#line 1008 "parser.c" { cs = JSON_float_start; } -#line 347 "parser.rl" +#line 361 "parser.rl" json->memo = p; -#line 1002 "parser.c" +#line 1016 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1070,14 +1070,14 @@ case 8: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1070 goto st0; goto tr9; tr9: -#line 334 "parser.rl" +#line 335 "parser.rl" { p--; {p++; cs = 9; goto _out;} } goto st9; st9: if ( ++p == pe ) goto _test_eof9; case 9: -#line 1067 "parser.c" +#line 1081 "parser.c" goto st0; st5: if ( ++p == pe ) @@ -1138,7 +1138,7 @@ case 7: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1138 _out: {} } -#line 349 "parser.rl" +#line 363 "parser.rl" if (cs >= JSON_float_first_final) { long len = p - json->memo; @@ -1164,7 +1164,7 @@ case 7: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1164 -#line 1150 "parser.c" +#line 1168 "parser.c" enum {JSON_array_start = 1}; enum {JSON_array_first_final = 17}; enum {JSON_array_error = 0}; @@ -1172,7 +1172,7 @@ enum {JSON_array_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1172 enum {JSON_array_en_main = 1}; -#line 398 "parser.rl" +#line 416 "parser.rl" static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting) @@ -1186,14 +1186,14 @@ static char *JSON_parse_array(JSON_Parse https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1186 *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class); -#line 1172 "parser.c" +#line 1190 "parser.c" { cs = JSON_array_start; } -#line 411 "parser.rl" +#line 429 "parser.rl" -#line 1179 "parser.c" +#line 1197 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1232,7 +1232,7 @@ case 2: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1232 goto st2; goto st0; tr2: -#line 375 "parser.rl" +#line 393 "parser.rl" { VALUE v = Qnil; char *np = JSON_parse_value(json, p, pe, &v, current_nesting); @@ -1252,7 +1252,7 @@ st3: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1252 if ( ++p == pe ) goto _test_eof3; case 3: -#line 1238 "parser.c" +#line 1256 "parser.c" switch( (*p) ) { case 13: goto st3; case 32: goto st3; @@ -1352,14 +1352,14 @@ case 12: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1352 goto st3; goto st12; tr4: -#line 390 "parser.rl" +#line 408 "parser.rl" { p--; {p++; cs = 17; goto _out;} } goto st17; st17: if ( ++p == pe ) goto _test_eof17; case 17: -#line 1345 "parser.c" +#line 1363 "parser.c" goto st0; st13: if ( ++p == pe ) @@ -1415,7 +1415,7 @@ case 16: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1415 _out: {} } -#line 412 "parser.rl" +#line 430 "parser.rl" if(cs >= JSON_array_first_final) { return p + 1; @@ -1504,7 +1504,7 @@ static VALUE json_string_unescape(VALUE https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1504 } -#line 1490 "parser.c" +#line 1508 "parser.c" enum {JSON_string_start = 1}; enum {JSON_string_first_final = 8}; enum {JSON_string_error = 0}; @@ -1512,7 +1512,7 @@ enum {JSON_string_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1512 enum {JSON_string_en_main = 1}; -#line 519 "parser.rl" +#line 537 "parser.rl" static int @@ -1534,15 +1534,15 @@ static char *JSON_parse_string(JSON_Pars https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1534 *result = rb_str_buf_new(0); -#line 1520 "parser.c" +#line 1538 "parser.c" { cs = JSON_string_start; } -#line 540 "parser.rl" +#line 558 "parser.rl" json->memo = p; -#line 1528 "parser.c" +#line 1546 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1567,7 +1567,7 @@ case 2: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1567 goto st0; goto st2; tr2: -#line 505 "parser.rl" +#line 523 "parser.rl" { *result = json_string_unescape(*result, json->memo + 1, p); if (NIL_P(*result)) { @@ -1578,14 +1578,14 @@ tr2: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1578 {p = (( p + 1))-1;} } } -#line 516 "parser.rl" +#line 534 "parser.rl" { p--; {p++; cs = 8; goto _out;} } goto st8; st8: if ( ++p == pe ) goto _test_eof8; case 8: -#line 1571 "parser.c" +#line 1589 "parser.c" goto st0; st3: if ( ++p == pe ) @@ -1661,7 +1661,7 @@ case 7: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1661 _out: {} } -#line 542 "parser.rl" +#line 560 "parser.rl" if (json->create_additions && RTEST(match_string = json->match_string)) { VALUE klass; @@ -1850,7 +1850,7 @@ static VALUE cParser_initialize(int argc https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1850 } -#line 1836 "parser.c" +#line 1854 "parser.c" enum {JSON_start = 1}; enum {JSON_first_final = 10}; enum {JSON_error = 0}; @@ -1858,7 +1858,7 @@ enum {JSON_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1858 enum {JSON_en_main = 1}; -#line 744 "parser.rl" +#line 762 "parser.rl" /* @@ -1875,16 +1875,16 @@ static VALUE cParser_parse(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1875 GET_PARSER; -#line 1861 "parser.c" +#line 1879 "parser.c" { cs = JSON_start; } -#line 760 "parser.rl" +#line 778 "parser.rl" p = json->source; pe = p + json->len; -#line 1870 "parser.c" +#line 1888 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1918,7 +1918,7 @@ st0: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1918 cs = 0; goto _out; tr2: -#line 736 "parser.rl" +#line 754 "parser.rl" { char *np = JSON_parse_value(json, p, pe, &result, 0); if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} @@ -1928,7 +1928,7 @@ st10: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1928 if ( ++p == pe ) goto _test_eof10; case 10: -#line 1914 "parser.c" +#line 1932 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -2017,7 +2017,7 @@ case 9: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L2017 _out: {} } -#line 763 "parser.rl" +#line 781 "parser.rl" if (cs >= JSON_first_final && p == pe) { return result; Index: test/json/test_helper.rb =================================================================== --- test/json/test_helper.rb (revision 67126) +++ test/json/test_helper.rb (revision 67127) @@ -15,7 +15,3 @@ begin https://github.com/ruby/ruby/blob/trunk/test/json/test_helper.rb#L15 require 'byebug' rescue LoadError end -if ENV['START_SIMPLECOV'].to_i == 1 - require 'simplecov' - SimpleCov.start -end Index: test/json/json_addition_test.rb =================================================================== --- test/json/json_addition_test.rb (revision 67126) +++ test/json/json_addition_test.rb (revision 67127) @@ -5,6 +5,7 @@ require 'json/add/complex' https://github.com/ruby/ruby/blob/trunk/test/json/json_addition_test.rb#L5 require 'json/add/rational' require 'json/add/bigdecimal' require 'json/add/ostruct' +require 'json/add/set' require 'date' class JSONAdditionTest < Test::Unit::TestCase @@ -190,4 +191,13 @@ class JSONAdditionTest < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/json/json_addition_test.rb#L191 o.foo = { 'bar' => true } assert_equal o, parse(JSON(o), :create_additions => true) end + + def test_set + s = Set.new([:a, :b, :c, :a]) + assert_equal s, JSON.parse(JSON(s), :create_additions => true) + ss = SortedSet.new([:d, :b, :a, :c]) + ss_again = JSON.parse(JSON(ss), :create_additions => true) + assert_kind_of ss.class, ss_again + assert_equal ss, ss_again + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/