Do not destruct rest arguments for __send__

Formerly, `__send__(*args)` modified `args` with `Array#shift`.
This bug affects optcarrot.

This changeset avoids the array destruction by using
`args = args[1, len-1]`.
This commit is contained in:
Yusuke Endoh
2020-05-24 01:25:03 +09:00
parent 47ea60814b
commit 6f4c585bd7
4 changed files with 15 additions and 1 deletions
+7
View File
@@ -808,6 +808,13 @@ ary_subseq(mrb_state *mrb, struct RArray *a, mrb_int beg, mrb_int len)
return mrb_obj_value(b);
}
mrb_value
mrb_ary_subseq(mrb_state *mrb, mrb_value ary, mrb_int beg, mrb_int len)
{
struct RArray *a = mrb_ary_ptr(ary);
return ary_subseq(mrb, a, beg, len);
}
static mrb_int
aget_index(mrb_state *mrb, mrb_value index)
{
+1 -1
View File
@@ -625,7 +625,7 @@ mrb_f_send(mrb_state *mrb, mrb_value self)
ci->argc--;
}
else { /* variable length arguments */
mrb_ary_shift(mrb, regs[0]);
regs[0] = mrb_ary_subseq(mrb, regs[0], 1, RARRAY_LEN(regs[0]) - 1);
}
if (MRB_METHOD_CFUNC_P(m)) {