Revert "vm.c (cipush): small refactoring"

This reverts commit d6e23f3cdc.
Caused some memory crashes.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-12-03 16:47:29 +09:00
parent 94a4b95b5d
commit 4a99f28ec3
+10 -7
View File
@@ -335,17 +335,20 @@ cipush(mrb_state *mrb, mrb_int push_stacks, uint8_t cci, struct RClass *target_c
const struct RProc *proc, struct RProc *blk, mrb_sym mid, uint16_t argc)
{
struct mrb_context *c = mrb->c;
mrb_callinfo *ci = ++c->ci;
mrb_callinfo *ci = c->ci + 1;
if (ci == c->ciend) {
ptrdiff_t diff = ci - c->cibase;
if (ci < c->ciend) {
c->ci = ci;
}
else {
ptrdiff_t size = ci - c->cibase;
if (diff >= MRB_CALL_LEVEL_MAX) {
if (size >= MRB_CALL_LEVEL_MAX) {
mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err));
}
c->cibase = (mrb_callinfo*)mrb_realloc(mrb, c->cibase, sizeof(mrb_callinfo)*diff*2);
c->ci = ci = c->cibase + diff;
c->ciend = c->cibase + diff * 2;
c->cibase = (mrb_callinfo*)mrb_realloc(mrb, c->cibase, sizeof(mrb_callinfo)*size*2);
c->ci = ci = c->cibase + size;
c->ciend = c->cibase + size * 2;
}
ci->mid = mid;
CI_PROC_SET(ci, proc);