ruby-changes:51962
From: eregon <ko1@a...>
Date: Sat, 4 Aug 2018 00:11:41 +0900 (JST)
Subject: [ruby-changes:51962] eregon:r64177 (trunk): ext/json/parser/parser.c: do not call rb_str_resize() on Time object
eregon 2018-08-04 00:11:36 +0900 (Sat, 04 Aug 2018) New Revision: 64177 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64177 Log: ext/json/parser/parser.c: do not call rb_str_resize() on Time object * See https://github.com/flori/json/issues/342 Modified files: trunk/ext/json/parser/parser.c trunk/ext/json/parser/parser.rl Index: ext/json/parser/parser.rl =================================================================== --- ext/json/parser/parser.rl (revision 64176) +++ ext/json/parser/parser.rl (revision 64177) @@ -554,7 +554,9 @@ static char *JSON_parse_string(JSON_Pars https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L554 if (json->symbolize_names && json->parsing_name) { *result = rb_str_intern(*result); } else { - rb_str_resize(*result, RSTRING_LEN(*result)); + if (RB_TYPE_P(*result, T_STRING)) { + rb_str_resize(*result, RSTRING_LEN(*result)); + } } if (cs >= JSON_string_first_final) { return p + 1; Index: ext/json/parser/parser.c =================================================================== --- ext/json/parser/parser.c (revision 64176) +++ ext/json/parser/parser.c (revision 64177) @@ -1659,7 +1659,9 @@ case 7: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1659 if (json->symbolize_names && json->parsing_name) { *result = rb_str_intern(*result); } else { - rb_str_resize(*result, RSTRING_LEN(*result)); + if (RB_TYPE_P(*result, T_STRING)) { + rb_str_resize(*result, RSTRING_LEN(*result)); + } } if (cs >= JSON_string_first_final) { return p + 1; @@ -1830,7 +1832,7 @@ static VALUE cParser_initialize(int argc https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1832 } -#line 1834 "parser.c" +#line 1836 "parser.c" enum {JSON_start = 1}; enum {JSON_first_final = 10}; enum {JSON_error = 0}; @@ -1838,7 +1840,7 @@ enum {JSON_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1840 enum {JSON_en_main = 1}; -#line 742 "parser.rl" +#line 744 "parser.rl" /* @@ -1855,16 +1857,16 @@ static VALUE cParser_parse(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1857 GET_PARSER; -#line 1859 "parser.c" +#line 1861 "parser.c" { cs = JSON_start; } -#line 758 "parser.rl" +#line 760 "parser.rl" p = json->source; pe = p + json->len; -#line 1868 "parser.c" +#line 1870 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1898,7 +1900,7 @@ st0: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1900 cs = 0; goto _out; tr2: -#line 734 "parser.rl" +#line 736 "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;} @@ -1908,7 +1910,7 @@ st10: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1910 if ( ++p == pe ) goto _test_eof10; case 10: -#line 1912 "parser.c" +#line 1914 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -1997,7 +1999,7 @@ case 9: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1999 _out: {} } -#line 761 "parser.rl" +#line 763 "parser.rl" if (cs >= JSON_first_final && p == pe) { return result; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/