[ruby/json] Categorize deprecated warning

https://github.com/ruby/json/commit/1acce7aceb
This commit is contained in:
Nobuyoshi Nakada 2024-11-06 12:51:06 +09:00 committed by Jean Boussier
parent fdc82cca83
commit 8254f6492c
4 changed files with 143 additions and 120 deletions

View File

@ -5,6 +5,7 @@ have_func("rb_enc_interned_str", "ruby.h") # RUBY_VERSION >= 3.0
have_func("rb_hash_new_capa", "ruby.h") # RUBY_VERSION >= 3.2 have_func("rb_hash_new_capa", "ruby.h") # RUBY_VERSION >= 3.2
have_func("rb_gc_mark_locations", "ruby.h") # Missing on TruffleRuby have_func("rb_gc_mark_locations", "ruby.h") # Missing on TruffleRuby
have_func("rb_hash_bulk_insert", "ruby.h") # Missing on TruffleRuby have_func("rb_hash_bulk_insert", "ruby.h") # Missing on TruffleRuby
have_func("rb_category_warn", "ruby.h") # Missing on TruffleRuby
append_cflags("-std=c99") append_cflags("-std=c99")

View File

@ -17,6 +17,17 @@ static VALUE sym_max_nesting, sym_allow_nan, sym_allow_trailing_comma, sym_symbo
static int binary_encindex; static int binary_encindex;
static int utf8_encindex; static int utf8_encindex;
#ifdef HAVE_RB_CATEGORY_WARN
# define json_deprecated(message) rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, message)
#else
# define json_deprecated(message) rb_warn(message)
#endif
static const char deprecated_create_additions_warning[] =
"JSON.load implicit support for `create_additions: true` is deprecated "
"and will be removed in 3.0, use JSON.unsafe_load or explicitly "
"pass `create_additions: true`";
#ifndef HAVE_RB_GC_MARK_LOCATIONS #ifndef HAVE_RB_GC_MARK_LOCATIONS
// For TruffleRuby // For TruffleRuby
void rb_gc_mark_locations(const VALUE *start, const VALUE *end) void rb_gc_mark_locations(const VALUE *start, const VALUE *end)
@ -438,11 +449,11 @@ static void raise_parse_error(const char *format, const char *start)
#line 464 "parser.rl" #line 475 "parser.rl"
#line 446 "parser.c" #line 457 "parser.c"
enum {JSON_object_start = 1}; enum {JSON_object_start = 1};
enum {JSON_object_first_final = 32}; enum {JSON_object_first_final = 32};
enum {JSON_object_error = 0}; enum {JSON_object_error = 0};
@ -450,7 +461,7 @@ enum {JSON_object_error = 0};
enum {JSON_object_en_main = 1}; enum {JSON_object_en_main = 1};
#line 504 "parser.rl" #line 515 "parser.rl"
#define PUSH(result) rvalue_stack_push(json->stack, result, &json->stack_handle, &json->stack) #define PUSH(result) rvalue_stack_push(json->stack, result, &json->stack_handle, &json->stack)
@ -466,14 +477,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
long stack_head = json->stack->head; long stack_head = json->stack->head;
#line 470 "parser.c" #line 481 "parser.c"
{ {
cs = JSON_object_start; cs = JSON_object_start;
} }
#line 519 "parser.rl" #line 530 "parser.rl"
#line 477 "parser.c" #line 488 "parser.c"
{ {
short _widec; short _widec;
if ( p == pe ) if ( p == pe )
@ -502,7 +513,7 @@ case 2:
goto st2; goto st2;
goto st0; goto st0;
tr2: tr2:
#line 483 "parser.rl" #line 494 "parser.rl"
{ {
char *np; char *np;
json->parsing_name = true; json->parsing_name = true;
@ -518,7 +529,7 @@ st3:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof3; goto _test_eof3;
case 3: case 3:
#line 522 "parser.c" #line 533 "parser.c"
switch( (*p) ) { switch( (*p) ) {
case 13: goto st3; case 13: goto st3;
case 32: goto st3; case 32: goto st3;
@ -585,7 +596,7 @@ case 8:
goto st8; goto st8;
goto st0; goto st0;
tr11: tr11:
#line 472 "parser.rl" #line 483 "parser.rl"
{ {
char *np = JSON_parse_value(json, p, pe, result, current_nesting); char *np = JSON_parse_value(json, p, pe, result, current_nesting);
if (np == NULL) { if (np == NULL) {
@ -599,20 +610,20 @@ st9:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof9; goto _test_eof9;
case 9: case 9:
#line 603 "parser.c" #line 614 "parser.c"
_widec = (*p); _widec = (*p);
if ( (*p) < 13 ) { if ( (*p) < 13 ) {
if ( (*p) > 9 ) { if ( (*p) > 9 ) {
if ( 10 <= (*p) && (*p) <= 10 ) { if ( 10 <= (*p) && (*p) <= 10 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) >= 9 ) { } else if ( (*p) >= 9 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) > 13 ) { } else if ( (*p) > 13 ) {
@ -620,26 +631,26 @@ case 9:
if ( 32 <= (*p) && (*p) <= 32 ) { if ( 32 <= (*p) && (*p) <= 32 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) > 44 ) { } else if ( (*p) > 44 ) {
if ( 47 <= (*p) && (*p) <= 47 ) { if ( 47 <= (*p) && (*p) <= 47 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else { } else {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else { } else {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
switch( _widec ) { switch( _widec ) {
@ -660,14 +671,14 @@ case 9:
goto st10; goto st10;
goto st0; goto st0;
tr4: tr4:
#line 494 "parser.rl" #line 505 "parser.rl"
{ p--; {p++; cs = 32; goto _out;} } { p--; {p++; cs = 32; goto _out;} }
goto st32; goto st32;
st32: st32:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof32; goto _test_eof32;
case 32: case 32:
#line 671 "parser.c" #line 682 "parser.c"
goto st0; goto st0;
st10: st10:
if ( ++p == pe ) if ( ++p == pe )
@ -769,13 +780,13 @@ case 20:
if ( 47 <= (*p) && (*p) <= 47 ) { if ( 47 <= (*p) && (*p) <= 47 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) >= 42 ) { } else if ( (*p) >= 42 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
switch( _widec ) { switch( _widec ) {
@ -794,20 +805,20 @@ case 21:
if ( (*p) <= 41 ) { if ( (*p) <= 41 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) > 42 ) { } else if ( (*p) > 42 ) {
if ( 43 <= (*p) ) if ( 43 <= (*p) )
{ _widec = (short)(128 + ((*p) - -128)); { _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else { } else {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
switch( _widec ) { switch( _widec ) {
@ -830,13 +841,13 @@ case 22:
if ( 42 <= (*p) && (*p) <= 42 ) { if ( 42 <= (*p) && (*p) <= 42 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else { } else {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) > 46 ) { } else if ( (*p) > 46 ) {
@ -844,19 +855,19 @@ case 22:
if ( 48 <= (*p) ) if ( 48 <= (*p) )
{ _widec = (short)(128 + ((*p) - -128)); { _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) >= 47 ) { } else if ( (*p) >= 47 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else { } else {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
switch( _widec ) { switch( _widec ) {
@ -880,20 +891,20 @@ case 23:
if ( (*p) <= 9 ) { if ( (*p) <= 9 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) > 10 ) { } else if ( (*p) > 10 ) {
if ( 11 <= (*p) ) if ( 11 <= (*p) )
{ _widec = (short)(128 + ((*p) - -128)); { _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else { } else {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 481 "parser.rl" #line 492 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
switch( _widec ) { switch( _widec ) {
@ -1007,7 +1018,7 @@ case 31:
_out: {} _out: {}
} }
#line 520 "parser.rl" #line 531 "parser.rl"
if (cs >= JSON_object_first_final) { if (cs >= JSON_object_first_final) {
long count = json->stack->head - stack_head; long count = json->stack->head - stack_head;
@ -1045,7 +1056,7 @@ case 31:
VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname); VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname);
if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) { if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) {
if (json->deprecated_create_additions) { if (json->deprecated_create_additions) {
rb_warn("JSON.load implicit support for `create_additions: true` is deprecated and will be removed in 3.0, use JSON.unsafe_load or explicitly pass `create_additions: true`"); json_deprecated(deprecated_create_additions_warning);
} }
*result = rb_funcall(klass, i_json_create, 1, *result); *result = rb_funcall(klass, i_json_create, 1, *result);
} }
@ -1058,7 +1069,7 @@ case 31:
} }
#line 1062 "parser.c" #line 1073 "parser.c"
enum {JSON_value_start = 1}; enum {JSON_value_start = 1};
enum {JSON_value_first_final = 29}; enum {JSON_value_first_final = 29};
enum {JSON_value_error = 0}; enum {JSON_value_error = 0};
@ -1066,7 +1077,7 @@ enum {JSON_value_error = 0};
enum {JSON_value_en_main = 1}; enum {JSON_value_en_main = 1};
#line 655 "parser.rl" #line 666 "parser.rl"
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting) static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
@ -1074,14 +1085,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
int cs = EVIL; int cs = EVIL;
#line 1078 "parser.c" #line 1089 "parser.c"
{ {
cs = JSON_value_start; cs = JSON_value_start;
} }
#line 662 "parser.rl" #line 673 "parser.rl"
#line 1085 "parser.c" #line 1096 "parser.c"
{ {
if ( p == pe ) if ( p == pe )
goto _test_eof; goto _test_eof;
@ -1115,7 +1126,7 @@ st0:
cs = 0; cs = 0;
goto _out; goto _out;
tr2: tr2:
#line 598 "parser.rl" #line 609 "parser.rl"
{ {
char *np = JSON_parse_string(json, p, pe, result); char *np = JSON_parse_string(json, p, pe, result);
if (np == NULL) { if (np == NULL) {
@ -1127,7 +1138,7 @@ tr2:
} }
goto st29; goto st29;
tr3: tr3:
#line 608 "parser.rl" #line 619 "parser.rl"
{ {
char *np; char *np;
if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) { if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
@ -1151,7 +1162,7 @@ tr3:
} }
goto st29; goto st29;
tr7: tr7:
#line 630 "parser.rl" #line 641 "parser.rl"
{ {
char *np; char *np;
np = JSON_parse_array(json, p, pe, result, current_nesting + 1); np = JSON_parse_array(json, p, pe, result, current_nesting + 1);
@ -1159,7 +1170,7 @@ tr7:
} }
goto st29; goto st29;
tr11: tr11:
#line 636 "parser.rl" #line 647 "parser.rl"
{ {
char *np; char *np;
np = JSON_parse_object(json, p, pe, result, current_nesting + 1); np = JSON_parse_object(json, p, pe, result, current_nesting + 1);
@ -1167,7 +1178,7 @@ tr11:
} }
goto st29; goto st29;
tr25: tr25:
#line 591 "parser.rl" #line 602 "parser.rl"
{ {
if (json->allow_nan) { if (json->allow_nan) {
*result = CInfinity; *result = CInfinity;
@ -1177,7 +1188,7 @@ tr25:
} }
goto st29; goto st29;
tr27: tr27:
#line 584 "parser.rl" #line 595 "parser.rl"
{ {
if (json->allow_nan) { if (json->allow_nan) {
*result = CNaN; *result = CNaN;
@ -1187,19 +1198,19 @@ tr27:
} }
goto st29; goto st29;
tr31: tr31:
#line 578 "parser.rl" #line 589 "parser.rl"
{ {
*result = Qfalse; *result = Qfalse;
} }
goto st29; goto st29;
tr34: tr34:
#line 575 "parser.rl" #line 586 "parser.rl"
{ {
*result = Qnil; *result = Qnil;
} }
goto st29; goto st29;
tr37: tr37:
#line 581 "parser.rl" #line 592 "parser.rl"
{ {
*result = Qtrue; *result = Qtrue;
} }
@ -1208,9 +1219,9 @@ st29:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof29; goto _test_eof29;
case 29: case 29:
#line 642 "parser.rl" #line 653 "parser.rl"
{ p--; {p++; cs = 29; goto _out;} } { p--; {p++; cs = 29; goto _out;} }
#line 1214 "parser.c" #line 1225 "parser.c"
switch( (*p) ) { switch( (*p) ) {
case 13: goto st29; case 13: goto st29;
case 32: goto st29; case 32: goto st29;
@ -1451,7 +1462,7 @@ case 28:
_out: {} _out: {}
} }
#line 663 "parser.rl" #line 674 "parser.rl"
if (json->freeze) { if (json->freeze) {
OBJ_FREEZE(*result); OBJ_FREEZE(*result);
@ -1466,7 +1477,7 @@ case 28:
} }
#line 1470 "parser.c" #line 1481 "parser.c"
enum {JSON_integer_start = 1}; enum {JSON_integer_start = 1};
enum {JSON_integer_first_final = 3}; enum {JSON_integer_first_final = 3};
enum {JSON_integer_error = 0}; enum {JSON_integer_error = 0};
@ -1474,7 +1485,7 @@ enum {JSON_integer_error = 0};
enum {JSON_integer_en_main = 1}; enum {JSON_integer_en_main = 1};
#line 684 "parser.rl" #line 695 "parser.rl"
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result) static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
@ -1482,15 +1493,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
int cs = EVIL; int cs = EVIL;
#line 1486 "parser.c" #line 1497 "parser.c"
{ {
cs = JSON_integer_start; cs = JSON_integer_start;
} }
#line 691 "parser.rl" #line 702 "parser.rl"
json->memo = p; json->memo = p;
#line 1494 "parser.c" #line 1505 "parser.c"
{ {
if ( p == pe ) if ( p == pe )
goto _test_eof; goto _test_eof;
@ -1524,14 +1535,14 @@ case 3:
goto st0; goto st0;
goto tr4; goto tr4;
tr4: tr4:
#line 681 "parser.rl" #line 692 "parser.rl"
{ p--; {p++; cs = 4; goto _out;} } { p--; {p++; cs = 4; goto _out;} }
goto st4; goto st4;
st4: st4:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof4; goto _test_eof4;
case 4: case 4:
#line 1535 "parser.c" #line 1546 "parser.c"
goto st0; goto st0;
st5: st5:
if ( ++p == pe ) if ( ++p == pe )
@ -1550,7 +1561,7 @@ case 5:
_out: {} _out: {}
} }
#line 693 "parser.rl" #line 704 "parser.rl"
if (cs >= JSON_integer_first_final) { if (cs >= JSON_integer_first_final) {
long len = p - json->memo; long len = p - json->memo;
@ -1565,7 +1576,7 @@ case 5:
} }
#line 1569 "parser.c" #line 1580 "parser.c"
enum {JSON_float_start = 1}; enum {JSON_float_start = 1};
enum {JSON_float_first_final = 8}; enum {JSON_float_first_final = 8};
enum {JSON_float_error = 0}; enum {JSON_float_error = 0};
@ -1573,7 +1584,7 @@ enum {JSON_float_error = 0};
enum {JSON_float_en_main = 1}; enum {JSON_float_en_main = 1};
#line 718 "parser.rl" #line 729 "parser.rl"
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result) static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
@ -1581,15 +1592,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
int cs = EVIL; int cs = EVIL;
#line 1585 "parser.c" #line 1596 "parser.c"
{ {
cs = JSON_float_start; cs = JSON_float_start;
} }
#line 725 "parser.rl" #line 736 "parser.rl"
json->memo = p; json->memo = p;
#line 1593 "parser.c" #line 1604 "parser.c"
{ {
if ( p == pe ) if ( p == pe )
goto _test_eof; goto _test_eof;
@ -1647,14 +1658,14 @@ case 8:
goto st0; goto st0;
goto tr9; goto tr9;
tr9: tr9:
#line 712 "parser.rl" #line 723 "parser.rl"
{ p--; {p++; cs = 9; goto _out;} } { p--; {p++; cs = 9; goto _out;} }
goto st9; goto st9;
st9: st9:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof9; goto _test_eof9;
case 9: case 9:
#line 1658 "parser.c" #line 1669 "parser.c"
goto st0; goto st0;
st5: st5:
if ( ++p == pe ) if ( ++p == pe )
@ -1715,7 +1726,7 @@ case 7:
_out: {} _out: {}
} }
#line 727 "parser.rl" #line 738 "parser.rl"
if (cs >= JSON_float_first_final) { if (cs >= JSON_float_first_final) {
VALUE mod = Qnil; VALUE mod = Qnil;
@ -1768,7 +1779,7 @@ case 7:
#line 1772 "parser.c" #line 1783 "parser.c"
enum {JSON_array_start = 1}; enum {JSON_array_start = 1};
enum {JSON_array_first_final = 22}; enum {JSON_array_first_final = 22};
enum {JSON_array_error = 0}; enum {JSON_array_error = 0};
@ -1776,7 +1787,7 @@ enum {JSON_array_error = 0};
enum {JSON_array_en_main = 1}; enum {JSON_array_en_main = 1};
#line 804 "parser.rl" #line 815 "parser.rl"
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting) static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
@ -1789,14 +1800,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
long stack_head = json->stack->head; long stack_head = json->stack->head;
#line 1793 "parser.c" #line 1804 "parser.c"
{ {
cs = JSON_array_start; cs = JSON_array_start;
} }
#line 816 "parser.rl" #line 827 "parser.rl"
#line 1800 "parser.c" #line 1811 "parser.c"
{ {
short _widec; short _widec;
if ( p == pe ) if ( p == pe )
@ -1836,7 +1847,7 @@ case 2:
goto st2; goto st2;
goto st0; goto st0;
tr2: tr2:
#line 784 "parser.rl" #line 795 "parser.rl"
{ {
VALUE v = Qnil; VALUE v = Qnil;
char *np = JSON_parse_value(json, p, pe, &v, current_nesting); char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
@ -1851,12 +1862,12 @@ st3:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof3; goto _test_eof3;
case 3: case 3:
#line 1855 "parser.c" #line 1866 "parser.c"
_widec = (*p); _widec = (*p);
if ( 44 <= (*p) && (*p) <= 44 ) { if ( 44 <= (*p) && (*p) <= 44 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
switch( _widec ) { switch( _widec ) {
@ -1903,14 +1914,14 @@ case 7:
goto st3; goto st3;
goto st7; goto st7;
tr4: tr4:
#line 796 "parser.rl" #line 807 "parser.rl"
{ p--; {p++; cs = 22; goto _out;} } { p--; {p++; cs = 22; goto _out;} }
goto st22; goto st22;
st22: st22:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof22; goto _test_eof22;
case 22: case 22:
#line 1914 "parser.c" #line 1925 "parser.c"
goto st0; goto st0;
st8: st8:
if ( ++p == pe ) if ( ++p == pe )
@ -1978,13 +1989,13 @@ case 13:
if ( 10 <= (*p) && (*p) <= 10 ) { if ( 10 <= (*p) && (*p) <= 10 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) >= 9 ) { } else if ( (*p) >= 9 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) > 13 ) { } else if ( (*p) > 13 ) {
@ -1992,19 +2003,19 @@ case 13:
if ( 47 <= (*p) && (*p) <= 47 ) { if ( 47 <= (*p) && (*p) <= 47 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) >= 32 ) { } else if ( (*p) >= 32 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else { } else {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
switch( _widec ) { switch( _widec ) {
@ -2043,13 +2054,13 @@ case 14:
if ( 47 <= (*p) && (*p) <= 47 ) { if ( 47 <= (*p) && (*p) <= 47 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) >= 42 ) { } else if ( (*p) >= 42 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
switch( _widec ) { switch( _widec ) {
@ -2068,20 +2079,20 @@ case 15:
if ( (*p) <= 41 ) { if ( (*p) <= 41 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) > 42 ) { } else if ( (*p) > 42 ) {
if ( 43 <= (*p) ) if ( 43 <= (*p) )
{ _widec = (short)(128 + ((*p) - -128)); { _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else { } else {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
switch( _widec ) { switch( _widec ) {
@ -2104,13 +2115,13 @@ case 16:
if ( 42 <= (*p) && (*p) <= 42 ) { if ( 42 <= (*p) && (*p) <= 42 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else { } else {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) > 46 ) { } else if ( (*p) > 46 ) {
@ -2118,19 +2129,19 @@ case 16:
if ( 48 <= (*p) ) if ( 48 <= (*p) )
{ _widec = (short)(128 + ((*p) - -128)); { _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) >= 47 ) { } else if ( (*p) >= 47 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else { } else {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
switch( _widec ) { switch( _widec ) {
@ -2154,20 +2165,20 @@ case 17:
if ( (*p) <= 9 ) { if ( (*p) <= 9 ) {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else if ( (*p) > 10 ) { } else if ( (*p) > 10 ) {
if ( 11 <= (*p) ) if ( 11 <= (*p) )
{ _widec = (short)(128 + ((*p) - -128)); { _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
} else { } else {
_widec = (short)(128 + ((*p) - -128)); _widec = (short)(128 + ((*p) - -128));
if ( if (
#line 794 "parser.rl" #line 805 "parser.rl"
json->allow_trailing_comma ) _widec += 256; json->allow_trailing_comma ) _widec += 256;
} }
switch( _widec ) { switch( _widec ) {
@ -2239,7 +2250,7 @@ case 21:
_out: {} _out: {}
} }
#line 817 "parser.rl" #line 828 "parser.rl"
if(cs >= JSON_array_first_final) { if(cs >= JSON_array_first_final) {
long count = json->stack->head - stack_head; long count = json->stack->head - stack_head;
@ -2413,7 +2424,7 @@ static VALUE json_string_unescape(JSON_Parser *json, char *string, char *stringE
} }
#line 2417 "parser.c" #line 2428 "parser.c"
enum {JSON_string_start = 1}; enum {JSON_string_start = 1};
enum {JSON_string_first_final = 8}; enum {JSON_string_first_final = 8};
enum {JSON_string_error = 0}; enum {JSON_string_error = 0};
@ -2421,7 +2432,7 @@ enum {JSON_string_error = 0};
enum {JSON_string_en_main = 1}; enum {JSON_string_en_main = 1};
#line 1008 "parser.rl" #line 1019 "parser.rl"
static int static int
@ -2442,15 +2453,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
VALUE match_string; VALUE match_string;
#line 2446 "parser.c" #line 2457 "parser.c"
{ {
cs = JSON_string_start; cs = JSON_string_start;
} }
#line 1028 "parser.rl" #line 1039 "parser.rl"
json->memo = p; json->memo = p;
#line 2454 "parser.c" #line 2465 "parser.c"
{ {
if ( p == pe ) if ( p == pe )
goto _test_eof; goto _test_eof;
@ -2475,7 +2486,7 @@ case 2:
goto st0; goto st0;
goto st2; goto st2;
tr2: tr2:
#line 995 "parser.rl" #line 1006 "parser.rl"
{ {
*result = json_string_unescape(json, json->memo + 1, p, json->parsing_name, json->parsing_name || json-> freeze, json->parsing_name && json->symbolize_names); *result = json_string_unescape(json, json->memo + 1, p, json->parsing_name, json->parsing_name || json-> freeze, json->parsing_name && json->symbolize_names);
if (NIL_P(*result)) { if (NIL_P(*result)) {
@ -2485,14 +2496,14 @@ tr2:
{p = (( p + 1))-1;} {p = (( p + 1))-1;}
} }
} }
#line 1005 "parser.rl" #line 1016 "parser.rl"
{ p--; {p++; cs = 8; goto _out;} } { p--; {p++; cs = 8; goto _out;} }
goto st8; goto st8;
st8: st8:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof8; goto _test_eof8;
case 8: case 8:
#line 2496 "parser.c" #line 2507 "parser.c"
goto st0; goto st0;
st3: st3:
if ( ++p == pe ) if ( ++p == pe )
@ -2568,7 +2579,7 @@ case 7:
_out: {} _out: {}
} }
#line 1030 "parser.rl" #line 1041 "parser.rl"
if (json->create_additions && RTEST(match_string = json->match_string)) { if (json->create_additions && RTEST(match_string = json->match_string)) {
VALUE klass; VALUE klass;
@ -2721,7 +2732,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
} }
#line 2725 "parser.c" #line 2736 "parser.c"
enum {JSON_start = 1}; enum {JSON_start = 1};
enum {JSON_first_final = 10}; enum {JSON_first_final = 10};
enum {JSON_error = 0}; enum {JSON_error = 0};
@ -2729,7 +2740,7 @@ enum {JSON_error = 0};
enum {JSON_en_main = 1}; enum {JSON_en_main = 1};
#line 1196 "parser.rl" #line 1207 "parser.rl"
/* /*
@ -2758,16 +2769,16 @@ static VALUE cParser_parse(VALUE self)
json->stack = &stack; json->stack = &stack;
#line 2762 "parser.c" #line 2773 "parser.c"
{ {
cs = JSON_start; cs = JSON_start;
} }
#line 1224 "parser.rl" #line 1235 "parser.rl"
p = json->source; p = json->source;
pe = p + json->len; pe = p + json->len;
#line 2771 "parser.c" #line 2782 "parser.c"
{ {
if ( p == pe ) if ( p == pe )
goto _test_eof; goto _test_eof;
@ -2801,7 +2812,7 @@ st0:
cs = 0; cs = 0;
goto _out; goto _out;
tr2: tr2:
#line 1188 "parser.rl" #line 1199 "parser.rl"
{ {
char *np = JSON_parse_value(json, p, pe, &result, 0); char *np = JSON_parse_value(json, p, pe, &result, 0);
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@ -2811,7 +2822,7 @@ st10:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof10; goto _test_eof10;
case 10: case 10:
#line 2815 "parser.c" #line 2826 "parser.c"
switch( (*p) ) { switch( (*p) ) {
case 13: goto st10; case 13: goto st10;
case 32: goto st10; case 32: goto st10;
@ -2900,7 +2911,7 @@ case 9:
_out: {} _out: {}
} }
#line 1227 "parser.rl" #line 1238 "parser.rl"
if (json->stack_handle) { if (json->stack_handle) {
rvalue_stack_eagerly_release(json->stack_handle); rvalue_stack_eagerly_release(json->stack_handle);
@ -2936,16 +2947,16 @@ static VALUE cParser_m_parse(VALUE klass, VALUE source, VALUE opts)
json->stack = &stack; json->stack = &stack;
#line 2940 "parser.c" #line 2951 "parser.c"
{ {
cs = JSON_start; cs = JSON_start;
} }
#line 1262 "parser.rl" #line 1273 "parser.rl"
p = json->source; p = json->source;
pe = p + json->len; pe = p + json->len;
#line 2949 "parser.c" #line 2960 "parser.c"
{ {
if ( p == pe ) if ( p == pe )
goto _test_eof; goto _test_eof;
@ -2979,7 +2990,7 @@ st0:
cs = 0; cs = 0;
goto _out; goto _out;
tr2: tr2:
#line 1188 "parser.rl" #line 1199 "parser.rl"
{ {
char *np = JSON_parse_value(json, p, pe, &result, 0); char *np = JSON_parse_value(json, p, pe, &result, 0);
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@ -2989,7 +3000,7 @@ st10:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof10; goto _test_eof10;
case 10: case 10:
#line 2993 "parser.c" #line 3004 "parser.c"
switch( (*p) ) { switch( (*p) ) {
case 13: goto st10; case 13: goto st10;
case 32: goto st10; case 32: goto st10;
@ -3078,7 +3089,7 @@ case 9:
_out: {} _out: {}
} }
#line 1265 "parser.rl" #line 1276 "parser.rl"
if (json->stack_handle) { if (json->stack_handle) {
rvalue_stack_eagerly_release(json->stack_handle); rvalue_stack_eagerly_release(json->stack_handle);

View File

@ -15,6 +15,17 @@ static VALUE sym_max_nesting, sym_allow_nan, sym_allow_trailing_comma, sym_symbo
static int binary_encindex; static int binary_encindex;
static int utf8_encindex; static int utf8_encindex;
#ifdef HAVE_RB_CATEGORY_WARN
# define json_deprecated(message) rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, message)
#else
# define json_deprecated(message) rb_warn(message)
#endif
static const char deprecated_create_additions_warning[] =
"JSON.load implicit support for `create_additions: true` is deprecated "
"and will be removed in 3.0, use JSON.unsafe_load or explicitly "
"pass `create_additions: true`";
#ifndef HAVE_RB_GC_MARK_LOCATIONS #ifndef HAVE_RB_GC_MARK_LOCATIONS
// For TruffleRuby // For TruffleRuby
void rb_gc_mark_locations(const VALUE *start, const VALUE *end) void rb_gc_mark_locations(const VALUE *start, const VALUE *end)
@ -554,7 +565,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname); VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname);
if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) { if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) {
if (json->deprecated_create_additions) { if (json->deprecated_create_additions) {
rb_warn("JSON.load implicit support for `create_additions: true` is deprecated and will be removed in 3.0, use JSON.unsafe_load or explicitly pass `create_additions: true`"); json_deprecated(deprecated_create_additions_warning);
} }
*result = rb_funcall(klass, i_json_create, 1, *result); *result = rb_funcall(klass, i_json_create, 1, *result);
} }

View File

@ -163,7 +163,7 @@ class JSONAdditionTest < Test::Unit::TestCase
end end
def test_deprecated_load_create_additions def test_deprecated_load_create_additions
assert_warning(/use JSON\.unsafe_load/) do assert_deprecated_warning(/use JSON\.unsafe_load/) do
JSON.load(JSON.dump(Time.now)) JSON.load(JSON.dump(Time.now))
end end
end end