diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2016-04-24 02:08:30 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2016-04-24 02:53:38 +0900 |
commit | e7fe550e6e0b9d963908406ccc46a374789c92b6 (patch) | |
tree | 64525ed16a26bf6e12660696f2d48b9d9bf90e90 /ext/json/ext/parser/parser.c | |
parent | d5a77c8af98d9be4df53cecc4d876a23d7688f74 (diff) | |
download | json-e7fe550e6e0b9d963908406ccc46a374789c92b6.tar.gz |
Optional hash in rb_scan_args
Use ':' in rb_scan_args to get optional hash, which available
since ruby 2.1.
Diffstat (limited to 'ext/json/ext/parser/parser.c')
-rw-r--r-- | ext/json/ext/parser/parser.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index 94543d2..9360247 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -1712,12 +1712,18 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) if (json->Vsource) { rb_raise(rb_eTypeError, "already initialized instance"); } +#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH + rb_scan_args(argc, argv, "1:", &source, &opts); +#else rb_scan_args(argc, argv, "11", &source, &opts); +#endif if (!NIL_P(opts)) { +#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash"); if (NIL_P(opts)) { rb_raise(rb_eArgError, "opts needs to be like a hash"); } else { +#endif VALUE tmp = ID2SYM(i_max_nesting); if (option_given_p(opts, tmp)) { VALUE max_nesting = rb_hash_aref(opts, tmp); @@ -1778,7 +1784,9 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } else { json->match_string = Qnil; } +#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH } +#endif } else { json->max_nesting = 100; json->allow_nan = 0; @@ -1797,7 +1805,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } -#line 1801 "parser.c" +#line 1809 "parser.c" enum {JSON_start = 1}; enum {JSON_first_final = 10}; enum {JSON_error = 0}; @@ -1805,7 +1813,7 @@ enum {JSON_error = 0}; enum {JSON_en_main = 1}; -#line 709 "parser.rl" +#line 717 "parser.rl" /* @@ -1822,16 +1830,16 @@ static VALUE cParser_parse(VALUE self) GET_PARSER; -#line 1826 "parser.c" +#line 1834 "parser.c" { cs = JSON_start; } -#line 725 "parser.rl" +#line 733 "parser.rl" p = json->source; pe = p + json->len; -#line 1835 "parser.c" +#line 1843 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1865,7 +1873,7 @@ st0: cs = 0; goto _out; tr2: -#line 701 "parser.rl" +#line 709 "parser.rl" { char *np = JSON_parse_value(json, p, pe, &result); if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} @@ -1875,7 +1883,7 @@ st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 1879 "parser.c" +#line 1887 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -1964,7 +1972,7 @@ case 9: _out: {} } -#line 728 "parser.rl" +#line 736 "parser.rl" if (cs >= JSON_first_final && p == pe) { return result; |