ruby-changes:47508
From: nobu <ko1@a...>
Date: Sun, 20 Aug 2017 08:39:08 +0900 (JST)
Subject: [ruby-changes:47508] nobu:r59624 (trunk): ruby.h: fix rb_scan_args_trail_idx
nobu 2017-08-20 08:39:03 +0900 (Sun, 20 Aug 2017) New Revision: 59624 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59624 Log: ruby.h: fix rb_scan_args_trail_idx * include/ruby/ruby.h (rb_scan_args_trail_idx): fix the case both of optional and rest arguments are defined. [ruby-core:82427] [Bug #13830] * include/ruby/ruby.h (rb_scan_args_n_trail): ditto. Added directories: trunk/ext/-test-/scan_args/ Added files: trunk/ext/-test-/scan_args/extconf.rb trunk/ext/-test-/scan_args/scan_args.c trunk/test/-ext-/test_scan_args.rb Modified files: trunk/include/ruby/ruby.h Index: test/-ext-/test_scan_args.rb =================================================================== --- test/-ext-/test_scan_args.rb (nonexistent) +++ test/-ext-/test_scan_args.rb (revision 59624) @@ -0,0 +1,219 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/test_scan_args.rb#L1 +require 'test/unit' +require '-test-/scan_args' + +class TestScanArgs < Test::Unit::TestCase + def test_lead + assert_raise(ArgumentError) {Bug::ScanArgs.lead()} + assert_equal([1, "a"], Bug::ScanArgs.lead("a")) + assert_raise(ArgumentError) {Bug::ScanArgs.lead("a", "b")} + end + + def test_opt + assert_equal([0, nil], Bug::ScanArgs.opt()) + assert_equal([1, "a"], Bug::ScanArgs.opt("a")) + assert_raise(ArgumentError) {Bug::ScanArgs.opt("a", "b")} + end + + def test_lead_opt + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt()} + assert_equal([1, "a", nil], Bug::ScanArgs.lead_opt("a")) + assert_equal([2, "a", "b"], Bug::ScanArgs.lead_opt("a", "b")) + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt("a", "b", "c")} + end + + def test_var + assert_equal([0, []], Bug::ScanArgs.var()) + assert_equal([3, ["a", "b", "c"]], Bug::ScanArgs.var("a", "b", "c")) + end + + def test_lead_var + assert_raise(ArgumentError) {Bug::ScanArgs.lead_var()} + assert_equal([3, "a", ["b", "c"]], Bug::ScanArgs.lead_var("a", "b", "c")) + end + + def test_opt_var + assert_equal([0, nil, []], Bug::ScanArgs.opt_var()) + assert_equal([3, "a", ["b", "c"]], Bug::ScanArgs.opt_var("a", "b", "c")) + end + + def test_lead_opt_var + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_var()} + assert_equal([3, "a", "b", ["c"]], Bug::ScanArgs.lead_opt_var("a", "b", "c")) + end + + def test_opt_trail + assert_raise(ArgumentError) {Bug::ScanArgs.opt_trail()} + assert_equal([2, "a", "b"], Bug::ScanArgs.opt_trail("a", "b")) + assert_equal([1, nil, "a"], Bug::ScanArgs.opt_trail("a")) + assert_raise(ArgumentError) {Bug::ScanArgs.opt_trail("a", "b", "c")} + end + + def test_lead_opt_trail + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_trail()} + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_trail("a")} + assert_equal([2, "a", nil, "b"], Bug::ScanArgs.lead_opt_trail("a", "b")) + assert_equal([3, "a", "b", "c"], Bug::ScanArgs.lead_opt_trail("a", "b", "c")) + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_trail("a", "b", "c", "d")} + end + + def test_var_trail + assert_raise(ArgumentError) {Bug::ScanArgs.var_trail()} + assert_equal([1, [], "a"], Bug::ScanArgs.var_trail("a")) + assert_equal([2, ["a"], "b"], Bug::ScanArgs.var_trail("a", "b")) + end + + def test_lead_var_trail + assert_raise(ArgumentError) {Bug::ScanArgs.lead_var_trail("a")} + assert_equal([2, "a", [], "b"], Bug::ScanArgs.lead_var_trail("a", "b")) + assert_equal([3, "a", ["b"], "c"], Bug::ScanArgs.lead_var_trail("a", "b", "c")) + end + + def test_opt_var_trail + assert_raise(ArgumentError) {Bug::ScanArgs.opt_var_trail()} + assert_equal([1, nil, [], "a"], Bug::ScanArgs.opt_var_trail("a")) + assert_equal([2, "a", [], "b"], Bug::ScanArgs.opt_var_trail("a", "b")) + assert_equal([3, "a", ["b"], "c"], Bug::ScanArgs.opt_var_trail("a", "b", "c")) + end + + def test_lead_opt_var_trail + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_var_trail("a")} + assert_equal([2, "a", nil, [], "b"], Bug::ScanArgs.lead_opt_var_trail("a", "b")) + assert_equal([3, "a", "b", [], "c"], Bug::ScanArgs.lead_opt_var_trail("a", "b", "c")) + assert_equal([4, "a", "b", ["c"], "d"], Bug::ScanArgs.lead_opt_var_trail("a", "b", "c", "d")) + end + + def test_hash + assert_equal([0, nil], Bug::ScanArgs.hash()) + assert_raise(ArgumentError) {Bug::ScanArgs.hash("a")} + assert_equal([0, {a: 0}], Bug::ScanArgs.hash(a: 0)) + end + + def test_lead_hash + assert_raise(ArgumentError) {Bug::ScanArgs.lead_hash()} + assert_equal([1, "a", nil], Bug::ScanArgs.lead_hash("a")) + assert_raise(ArgumentError) {Bug::ScanArgs.lead_hash("a", "b")} + assert_equal([1, "a", {b: 1}], Bug::ScanArgs.lead_hash("a", b: 1)) + assert_equal([1, {b: 1}, nil], Bug::ScanArgs.lead_hash(b: 1)) + end + + def test_opt_hash + assert_equal([0, nil, nil], Bug::ScanArgs.opt_hash()) + assert_equal([1, "a", nil], Bug::ScanArgs.opt_hash("a")) + assert_equal([0, nil, {b: 1}], Bug::ScanArgs.opt_hash(b: 1)) + assert_equal([1, "a", {b: 1}], Bug::ScanArgs.opt_hash("a", b: 1)) + assert_raise(ArgumentError) {Bug::ScanArgs.opt_hash("a", "b")} + end + + def test_lead_opt_hash + assert_equal([1, "a", nil, nil], Bug::ScanArgs.lead_opt_hash("a")) + assert_equal([2, "a", "b", nil], Bug::ScanArgs.lead_opt_hash("a", "b")) + assert_equal([1, "a", nil, {c: 1}], Bug::ScanArgs.lead_opt_hash("a", c: 1)) + assert_equal([2, "a", "b", {c: 1}], Bug::ScanArgs.lead_opt_hash("a", "b", c: 1)) + assert_equal([1, {c: 1}, nil, nil], Bug::ScanArgs.lead_opt_hash(c: 1)) + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_hash("a", "b", "c")} + end + + def test_var_hash + assert_equal([0, [], nil], Bug::ScanArgs.var_hash()) + assert_equal([1, ["a"], nil], Bug::ScanArgs.var_hash("a")) + assert_equal([1, ["a"], {b: 1}], Bug::ScanArgs.var_hash("a", b: 1)) + assert_equal([0, [], {b: 1}], Bug::ScanArgs.var_hash(b: 1)) + end + + def test_lead_var_hash + assert_raise(ArgumentError) {Bug::ScanArgs.lead_var_hash()} + assert_equal([1, "a", [], nil], Bug::ScanArgs.lead_var_hash("a")) + assert_equal([2, "a", ["b"], nil], Bug::ScanArgs.lead_var_hash("a", "b")) + assert_equal([2, "a", ["b"], {c: 1}], Bug::ScanArgs.lead_var_hash("a", "b", c: 1)) + assert_equal([1, "a", [], {c: 1}], Bug::ScanArgs.lead_var_hash("a", c: 1)) + assert_equal([1, {c: 1}, [], nil], Bug::ScanArgs.lead_var_hash(c: 1)) + assert_equal([3, "a", ["b", "c"], nil], Bug::ScanArgs.lead_var_hash("a", "b", "c")) + end + + def test_opt_var_hash + assert_equal([0, nil, [], nil], Bug::ScanArgs.opt_var_hash()) + assert_equal([1, "a", [], nil], Bug::ScanArgs.opt_var_hash("a")) + assert_equal([2, "a", ["b"], nil], Bug::ScanArgs.opt_var_hash("a", "b")) + assert_equal([2, "a", ["b"], {c: 1}], Bug::ScanArgs.opt_var_hash("a", "b", c: 1)) + assert_equal([1, "a", [], {c: 1}], Bug::ScanArgs.opt_var_hash("a", c: 1)) + assert_equal([0, nil, [], {c: 1}], Bug::ScanArgs.opt_var_hash(c: 1)) + assert_equal([3, "a", ["b", "c"], nil], Bug::ScanArgs.opt_var_hash("a", "b", "c")) + end + + def test_lead_opt_var_hash + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_var_hash()} + assert_equal([1, "a", nil, [], nil], Bug::ScanArgs.lead_opt_var_hash("a")) + assert_equal([2, "a", "b", [], nil], Bug::ScanArgs.lead_opt_var_hash("a", "b")) + assert_equal([2, "a", "b", [], {c: 1}], Bug::ScanArgs.lead_opt_var_hash("a", "b", c: 1)) + assert_equal([1, "a", nil, [], {c: 1}], Bug::ScanArgs.lead_opt_var_hash("a", c: 1)) + assert_equal([1, {c: 1}, nil, [], nil], Bug::ScanArgs.lead_opt_var_hash(c: 1)) + assert_equal([3, "a", "b", ["c"], nil], Bug::ScanArgs.lead_opt_var_hash("a", "b", "c")) + assert_equal([3, "a", "b", ["c"], {d: 1}], Bug::ScanArgs.lead_opt_var_hash("a", "b", "c", d: 1)) + end + + def test_opt_trail_hash + assert_raise(ArgumentError) {Bug::ScanArgs.opt_trail_hash()} + assert_equal([1, nil, "a", nil], Bug::ScanArgs.opt_trail_hash("a")) + assert_equal([2, "a", "b", nil], Bug::ScanArgs.opt_trail_hash("a", "b")) + assert_equal([1, nil, "a", {c: 1}], Bug::ScanArgs.opt_trail_hash("a", c: 1)) + assert_equal([2, "a", "b", {c: 1}], Bug::ScanArgs.opt_trail_hash("a", "b", c: 1)) + assert_equal([1, nil, {c: 1}, nil], Bug::ScanArgs.opt_trail_hash(c: 1)) + assert_raise(ArgumentError) {Bug::ScanArgs.opt_trail_hash("a", "b", "c")} + end + + def test_lead_opt_trail_hash + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_trail_hash()} + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_trail_hash("a")} + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_trail_hash(c: 1)} + assert_equal([2, "a", nil, "b", nil], Bug::ScanArgs.lead_opt_trail_hash("a", "b")) + assert_equal([2, "a", nil, {c: 1}, nil], Bug::ScanArgs.lead_opt_trail_hash("a", c: 1)) + assert_equal([2, "a", nil, "b", {c: 1}], Bug::ScanArgs.lead_opt_trail_hash("a", "b", c: 1)) + assert_equal([3, "a", "b", "c", nil], Bug::ScanArgs.lead_opt_trail_hash("a", "b", "c")) + assert_equal([3, "a", "b", "c", {c: 1}], Bug::ScanArgs.lead_opt_trail_hash("a", "b", "c", c: 1)) + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_trail_hash("a", "b", "c", "d")} + end + + def test_var_trail_hash + assert_raise(ArgumentError) {Bug::ScanArgs.var_trail_hash()} + assert_equal([1, [], "a", nil], Bug::ScanArgs.var_trail_hash("a")) + assert_equal([2, ["a"], "b", nil], Bug::ScanArgs.var_trail_hash("a", "b")) + assert_equal([1, [], "a", {c: 1}], Bug::ScanArgs.var_trail_hash("a", c: 1)) + assert_equal([2, ["a"], "b", {c: 1}], Bug::ScanArgs.var_trail_hash("a", "b", c: 1)) + assert_equal([1, [], {c: 1}, nil], Bug::ScanArgs.var_trail_hash(c: 1)) + assert_equal([3, ["a", "b"], "c", nil], Bug::ScanArgs.var_trail_hash("a", "b", "c")) + assert_equal([3, ["a", "b"], "c", {c: 1}], Bug::ScanArgs.var_trail_hash("a", "b", "c", c: 1)) + end + + def test_lead_var_trail_hash + assert_raise(ArgumentError) {Bug::ScanArgs.lead_var_trail_hash()} + assert_raise(ArgumentError) {Bug::ScanArgs.lead_var_trail_hash("a")} + assert_raise(ArgumentError) {Bug::ScanArgs.lead_var_trail_hash(c: 1)} + assert_equal([2, "a", [], {c: 1}, nil], Bug::ScanArgs.lead_var_trail_hash("a", c: 1)) + assert_equal([2, "a", [], "b", nil], Bug::ScanArgs.lead_var_trail_hash("a", "b")) + assert_equal([2, "a", [], "b", {c: 1}], Bug::ScanArgs.lead_var_trail_hash("a", "b", c: 1)) + assert_equal([3, "a", ["b"], "c", nil], Bug::ScanArgs.lead_var_trail_hash("a", "b", "c")) + assert_equal([3, "a", ["b"], "c", {c: 1}], Bug::ScanArgs.lead_var_trail_hash("a", "b", "c", c: 1)) + end + + def test_opt_var_trail_hash + assert_raise(ArgumentError) {Bug::ScanArgs.opt_var_trail_hash()} + assert_equal([1, nil, [], "a", nil], Bug::ScanArgs.opt_var_trail_hash("a")) + assert_equal([1, nil, [], {c: 1}, nil], Bug::ScanArgs.opt_var_trail_hash(c: 1)) + assert_equal([1, nil, [], "a", {c: 1}], Bug::ScanArgs.opt_var_trail_hash("a", c: 1)) + assert_equal([2, "a", [], "b", nil], Bug::ScanArgs.opt_var_trail_hash("a", "b")) + assert_equal([2, "a", [], "b", {c: 1}], Bug::ScanArgs.opt_var_trail_hash("a", "b", c: 1)) + assert_equal([3, "a", ["b"], "c", nil], Bug::ScanArgs.opt_var_trail_hash("a", "b", "c")) + assert_equal([3, "a", ["b"], "c", {c: 1}], Bug::ScanArgs.opt_var_trail_hash("a", "b", "c", c: 1)) + end + + def test_lead_opt_var_trail_hash + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_var_trail_hash()} + assert_raise(ArgumentError) {Bug::ScanArgs.lead_opt_var_trail_hash("a")} + assert_equal([2, "a", nil, [], {b: 1}, nil], Bug::ScanArgs.lead_opt_var_trail_hash("a", b: 1)) + assert_equal([2, "a", nil, [], "b", nil], Bug::ScanArgs.lead_opt_var_trail_hash("a", "b")) + assert_equal([2, "a", nil, [], "b", {c: 1}], Bug::ScanArgs.lead_opt_var_trail_hash("a", "b", c: 1)) + assert_equal([3, "a", "b", [], "c", nil], Bug::ScanArgs.lead_opt_var_trail_hash("a", "b", "c")) + assert_equal([3, "a", "b", [], "c", {c: 1}], Bug::ScanArgs.lead_opt_var_trail_hash("a", "b", "c", c: 1)) + assert_equal([4, "a", "b", ["c"], "d", nil], Bug::ScanArgs.lead_opt_var_trail_hash("a", "b", "c", "d")) + end +end Property changes on: test/-ext-/test_scan_args.rb ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 59623) +++ include/ruby/ruby.h (revision 59624) @@ -2279,29 +2279,16 @@ ALWAYS_INLINE(static int rb_scan_args_tr https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2279 static inline int rb_scan_args_trail_idx(const char *fmt) { - return (rb_scan_args_lead_p(fmt) ? - (rb_scan_args_isdigit(fmt[1]) || fmt[1]=='*')+1 : - (fmt[0]=='*')); -} - -ALWAYS_INLINE(static int rb_scan_args_trail_p(const char *fmt)); -static inline int -rb_scan_args_trail_p(const char *fmt) -{ - return (rb_scan_args_lead_p(fmt) ? - (rb_scan_args_isdigit(fmt[1]) || fmt[1]=='*') && - rb_scan_args_isdigit(fmt[2]) : - fmt[0]=='*' && rb_scan_args_isdigit(fmt[1])); + const int idx = rb_scan_args_var_idx(fmt); + return idx+(fmt[idx]=='*'); } ALWAYS_INLINE(static int rb_scan_args_n_trail(const char *fmt)); static inline int rb_scan_args_n_trail(const char *fmt) { - return (rb_scan_args_lead_p(fmt) ? - ((rb_scan_args_isdigit(fmt[1]) || fmt[1]=='*') && - rb_scan_args_isdigit(fmt[2]) ? fmt[2]-'0' : 0) : - (fmt[0]=='*' && rb_scan_args_isdigit(fmt[1]) ? fmt[1]-'0' : 0)); + const int idx = rb_scan_args_trail_idx(fmt); + return (rb_scan_args_isdigit(fmt[idx]) ? fmt[idx]-'0' : 0); } ALWAYS_INLINE(static int rb_scan_args_hash_idx(const char *fmt)); Index: ext/-test-/scan_args/scan_args.c =================================================================== --- ext/-test-/scan_args/scan_args.c (nonexistent) +++ ext/-test-/scan_args/scan_args.c (revision 59624) @@ -0,0 +1,286 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/scan_args/scan_args.c#L1 +#include <ruby.h> + +#ifndef numberof +#define numberof(array) (int)(sizeof(array) / sizeof((array)[0])) +#endif + +static VALUE +scan_args_lead(int argc, VALUE *argv, VALUE self) +{ + VALUE args[2]; + int n = rb_scan_args(argc, argv, "1", args+1); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_opt(int argc, VALUE *argv, VALUE self) +{ + VALUE args[2]; + int n = rb_scan_args(argc, argv, "01", args+1); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_lead_opt(int argc, VALUE *argv, VALUE self) +{ + VALUE args[3]; + int n = rb_scan_args(argc, argv, "11", args+1, args+2); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +/* var */ +static VALUE +scan_args_var(int argc, VALUE *argv, VALUE self) +{ + VALUE args[2]; + int n = rb_scan_args(argc, argv, "*", args+1); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_lead_var(int argc, VALUE *argv, VALUE self) +{ + VALUE args[3]; + int n = rb_scan_args(argc, argv, "1*", args+1, args+2); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_opt_var(int argc, VALUE *argv, VALUE self) +{ + VALUE args[3]; + int n = rb_scan_args(argc, argv, "01*", args+1, args+2); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_lead_opt_var(int argc, VALUE *argv, VALUE self) +{ + VALUE args[4]; + int n = rb_scan_args(argc, argv, "11*", args+1, args+2, args+3); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +/* trail */ +static VALUE +scan_args_opt_trail(int argc, VALUE *argv, VALUE self) +{ + VALUE args[3]; + int n = rb_scan_args(argc, argv, "011", args+1, args+2); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_lead_opt_trail(int argc, VALUE *argv, VALUE self) +{ + VALUE args[4]; + int n = rb_scan_args(argc, argv, "111", args+1, args+2, args+3); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_var_trail(int argc, VALUE *argv, VALUE self) +{ + VALUE args[3]; + int n = rb_scan_args(argc, argv, "*1", args+1, args+2); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_lead_var_trail(int argc, VALUE *argv, VALUE self) +{ + VALUE args[4]; + int n = rb_scan_args(argc, argv, "1*1", args+1, args+2, args+3); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_opt_var_trail(int argc, VALUE *argv, VALUE self) +{ + VALUE args[4]; + int n = rb_scan_args(argc, argv, "01*1", args+1, args+2, args+3); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_lead_opt_var_trail(int argc, VALUE *argv, VALUE self) +{ + VALUE args[5]; + int n = rb_scan_args(argc, argv, "11*1", args+1, args+2, args+3, args+4); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +/* hash */ +static VALUE +scan_args_hash(int argc, VALUE *argv, VALUE self) +{ + VALUE args[2]; + int n = rb_scan_args(argc, argv, ":", args+1); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_lead_hash(int argc, VALUE *argv, VALUE self) +{ + VALUE args[3]; + int n = rb_scan_args(argc, argv, "1:", args+1, args+2); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_opt_hash(int argc, VALUE *argv, VALUE self) +{ + VALUE args[3]; + int n = rb_scan_args(argc, argv, "01:", args+1, args+2); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_lead_opt_hash(int argc, VALUE *argv, VALUE self) +{ + VALUE args[4]; + int n = rb_scan_args(argc, argv, "11:", args+1, args+2, args+3); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_var_hash(int argc, VALUE *argv, VALUE self) +{ + VALUE args[3]; + int n = rb_scan_args(argc, argv, "*:", args+1, args+2); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_lead_var_hash(int argc, VALUE *argv, VALUE self) +{ + VALUE args[4]; + int n = rb_scan_args(argc, argv, "1*:", args+1, args+2, args+3); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_opt_var_hash(int argc, VALUE *argv, VALUE self) +{ + VALUE args[4]; + int n = rb_scan_args(argc, argv, "01*:", args+1, args+2, args+3); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_lead_opt_var_hash(int argc, VALUE *argv, VALUE self) +{ + VALUE args[5]; + int n = rb_scan_args(argc, argv, "11*:", args+1, args+2, args+3, args+4); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_opt_trail_hash(int argc, VALUE *argv, VALUE self) +{ + VALUE args[4]; + int n = rb_scan_args(argc, argv, "011:", args+1, args+2, args+3); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_lead_opt_trail_hash(int argc, VALUE *argv, VALUE self) +{ + VALUE args[5]; + int n = rb_scan_args(argc, argv, "111:", args+1, args+2, args+3, args+4); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_var_trail_hash(int argc, VALUE *argv, VALUE self) +{ + VALUE args[4]; + int n = rb_scan_args(argc, argv, "*1:", args+1, args+2, args+3); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE +scan_args_lead_var_trail_hash(int argc, VALUE *argv, VALUE self) +{ + VALUE args[5]; + int n = rb_scan_args(argc, argv, "1*1:", args+1, args+2, args+3, args+4); + args[0] = INT2NUM(n); + return rb_ary_new_from_values(numberof(args), args); +} + +static VALUE (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/