Skip to content

Commit

Permalink
SCI: Remove unexpected side effect from ExecStack constructor
Browse files Browse the repository at this point in the history
The ExecStack constructor set argp[0] to argc before. This is now moved
to the caller, to make this action more explicit.
  • Loading branch information
wjp committed Jul 2, 2016
1 parent 7f12638 commit d643cb6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 7 additions & 1 deletion engines/sci/engine/vm.cpp
Expand Up @@ -239,6 +239,7 @@ ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackP
// Check if a breakpoint is set on this method
g_sci->checkExportBreakpoint(script, pubfunct);

assert(argp[0].toUint16() == argc); // The first argument is argc
ExecStack xstack(calling_obj, calling_obj, sp, argc, argp,
seg, make_reg32(seg, exportAddr), -1, -1, -1, pubfunct, -1,
s->_executionStack.size() - 1, EXEC_STACK_TYPE_CALL);
Expand Down Expand Up @@ -312,6 +313,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt
if (activeBreakpointTypes || DebugMan.isDebugChannelEnabled(kDebugLevelScripts))
debugSelectorCall(send_obj, selector, argc, argp, varp, funcp, s->_segMan, selectorType);

assert(argp[0].toUint16() == argc); // The first argument is argc
ExecStack xstack(work_obj, send_obj, curSP, argc, argp,
0xFFFF, curFP, selector, -1, -1, -1, -1,
origin, stackType);
Expand Down Expand Up @@ -386,6 +388,7 @@ static void callKernelFunc(EngineState *s, int kernelCallNr, int argc) {

// Call kernel function
if (!kernelCall.subFunctionCount) {
argv[-1] = make_reg(0, argc); // The first argument is argc
addKernelCallToExecStack(s, kernelCallNr, -1, argc, argv);
s->r_acc = kernelCall.function(s, argc, argv);

Expand Down Expand Up @@ -444,6 +447,7 @@ static void callKernelFunc(EngineState *s, int kernelCallNr, int argc) {
}
if (!kernelSubCall.function)
error("[VM] k%s: subfunction ID %d requested, but not available", kernelCall.name, subId);
argv[-1] = make_reg(0, argc); // The first argument is argc
addKernelCallToExecStack(s, kernelCallNr, subId, argc, argv);
s->r_acc = kernelSubCall.function(s, argc, argv);

Expand Down Expand Up @@ -837,8 +841,10 @@ void run_vm(EngineState *s) {

uint32 localCallOffset = s->xs->addr.pc.getOffset() + opparams[0];

int final_argc = (call_base->requireUint16()) + s->r_rest;
call_base[0] = make_reg(0, final_argc); // The first argument is argc
ExecStack xstack(s->xs->objp, s->xs->objp, s->xs->sp,
(call_base->requireUint16()) + s->r_rest, call_base,
final_argc, call_base,
s->xs->local_segment, make_reg32(s->xs->addr.pc.getSegment(), localCallOffset),
NULL_SELECTOR, -1, -1, -1, localCallOffset, s->_executionStack.size() - 1,
EXEC_STACK_TYPE_CALL);
Expand Down
1 change: 0 additions & 1 deletion engines/sci/engine/vm.h
Expand Up @@ -115,7 +115,6 @@ struct ExecStack {
fp = sp = sp_;
argc = argc_;
variables_argp = argp_;
*variables_argp = make_reg(0, argc); // The first argument is argc
if (localsSegment_ != 0xFFFF)
local_segment = localsSegment_;
else
Expand Down

0 comments on commit d643cb6

Please sign in to comment.