[ruamoko] Preserve the stack in obj_msg_sendv

obj_msg_sendv needs to push the parameters onto the stack for Ruamoko
progs, but this causes problems because PR_CallFunction winds up
recording the wrong stack pointer for progs functions, and nothing
restores the stack for builtins. The handling is basically the same as
for the return pointer.
This commit is contained in:
Bill Currie 2022-02-04 22:09:38 +09:00
parent b6a8a93cc3
commit cdc3c9822d

View file

@ -1430,6 +1430,11 @@ rua_obj_msg_sendv (progs_t *pr)
// replace them
count -= 2;
params += 2 * pr->pr_param_size;
pr_ptr_t saved_stack = 0;
int sendv_depth = pr->pr_depth;
if (pr->globals.stack) {
saved_stack = *pr->globals.stack;
}
PR_RESET_PARAMS (pr);
P_POINTER (pr, 0) = obj;
P_POINTER (pr, 1) = sel;
@ -1437,7 +1442,15 @@ rua_obj_msg_sendv (progs_t *pr)
memcpy (&P_INT (pr, 2), params,
count * sizeof (pr_type_t) * pr->pr_param_size);
}
PR_CallFunction (pr, imp, pr->pr_return);
if (PR_CallFunction (pr, imp, pr->pr_return)) {
// the call is to a progs function so a frame was pushed, ensure
// the stack pointer is restored on return
// if there's no stack, then the following is effectively a noop
pr->pr_stack[sendv_depth].stack_ptr = saved_stack;
} else if (pr->globals.stack) {
// the call was to a builtin, restore the stack
*pr->globals.stack = saved_stack;
}
}
static void