fix OP_APOST bug for no pre arg cases; fix #2810

parent 9ef4bbb1
...@@ -2125,33 +2125,28 @@ RETRY_TRY_BLOCK: ...@@ -2125,33 +2125,28 @@ RETRY_TRY_BLOCK:
int pre = GETARG_B(i); int pre = GETARG_B(i);
int post = GETARG_C(i); int post = GETARG_C(i);
struct RArray *ary;
int len, idx;
if (!mrb_array_p(v)) { if (!mrb_array_p(v)) {
regs[a++] = mrb_ary_new_capa(mrb, 0); v = mrb_ary_new_from_values(mrb, 1, &regs[a]);
}
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);
while (post--) { while (post--) {
SET_NIL_VALUE(regs[a]); regs[a++] = ary->ptr[len-post-1];
a++;
} }
} }
else { else {
struct RArray *ary = mrb_ary_ptr(v); regs[a++] = mrb_ary_new_capa(mrb, 0);
int len = ary->len; for (idx=0; idx+pre<len; idx++) {
int idx; regs[a+idx] = ary->ptr[pre+idx];
if (len > pre + post) {
regs[a++] = mrb_ary_new_from_values(mrb, len - pre - post, ary->ptr+pre);
while (post--) {
regs[a++] = ary->ptr[len-post-1];
}
} }
else { while (idx < post) {
regs[a++] = mrb_ary_new_capa(mrb, 0); SET_NIL_VALUE(regs[a+idx]);
for (idx=0; idx+pre<len; idx++) { idx++;
regs[a+idx] = ary->ptr[pre+idx];
}
while (idx < post) {
SET_NIL_VALUE(regs[a+idx]);
idx++;
}
} }
} }
ARENA_RESTORE(mrb, ai); ARENA_RESTORE(mrb, ai);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment