Permalink
Browse files

Avoid updating regs[] from function calls; ref #3588

  • Loading branch information...
matz committed Apr 6, 2017
1 parent 1fd3cc9 commit 47f181519f009e91aac06b0f8a6f529f6dfcf579
Showing with 12 additions and 7 deletions.
  1. +12 −7 src/vm.c
View
@@ -2146,7 +2146,8 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
}
#ifdef MRB_NAN_BOXING
if (isnan(mrb_float(regs[a]))) {
regs[a] = mrb_float_value(mrb, mrb_float(regs[a]));
mrb_value v = mrb_float_value(mrb, mrb_float(regs[a]));
regs[a] = v;
}
#endif
NEXT;
@@ -2299,7 +2300,8 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
CASE(OP_ARRAY) {
/* A B C R(A) := ary_new(R(B),R(B+1)..R(B+C)) */
regs[GETARG_A(i)] = mrb_ary_new_from_values(mrb, GETARG_C(i), &regs[GETARG_B(i)]);
mrb_value v = mrb_ary_new_from_values(mrb, GETARG_C(i), &regs[GETARG_B(i)]);
regs[GETARG_A(i)] = v;
ARENA_RESTORE(mrb, ai);
NEXT;
}
@@ -2333,7 +2335,8 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
}
}
else {
regs[GETARG_A(i)] = mrb_ary_ref(mrb, v, c);
v = mrb_ary_ref(mrb, v, c);
regs[GETARG_A(i)] = v;
}
NEXT;
}
@@ -2350,7 +2353,6 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
mrb_value v = regs[a];
int pre = GETARG_B(i);
int post = GETARG_C(i);
struct RArray *ary;
int len, idx;
@@ -2360,13 +2362,15 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
ary = mrb_ary_ptr(v);
len = ary->len;
if (len > pre + post) {
regs[a++] = mrb_ary_new_from_values(mrb, len - pre - post, ary->ptr+pre);
v = mrb_ary_new_from_values(mrb, len - pre - post, ary->ptr+pre);
regs[a++] = v;
while (post--) {
regs[a++] = ary->ptr[len-post-1];
}
}
else {
regs[a++] = mrb_ary_new_capa(mrb, 0);
v = mrb_ary_new_capa(mrb, 0);
regs[a++] = v;
for (idx=0; idx+pre<len; idx++) {
regs[a+idx] = ary->ptr[pre+idx];
}
@@ -2381,7 +2385,8 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
CASE(OP_STRING) {
/* A Bx R(A) := str_new(Lit(Bx)) */
regs[GETARG_A(i)] = mrb_str_dup(mrb, pool[GETARG_Bx(i)]);
mrb_value str = mrb_str_dup(mrb, pool[GETARG_Bx(i)]);
regs[GETARG_A(i)] = str;
ARENA_RESTORE(mrb, ai);
NEXT;
}

0 comments on commit 47f1815

Please sign in to comment.