Skip to content

Commit

Permalink
Avoid updating regs[] from function calls; ref #3588
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Apr 8, 2017
1 parent 1fd3cc9 commit 47f1815
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;

Expand All @@ -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];
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 47f1815

Please sign in to comment.