Skip to content

Commit 3ccac17

Browse files
chfastaxic
authored andcommitted
Pass only number of args to invoke_function()
1 parent 90bd063 commit 3ccac17

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/fizzy/execute.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,9 @@ void branch(const Code& code, OperandStack& stack, const uint8_t*& pc, uint32_t
510510
stack.drop(stack_drop);
511511
}
512512

513-
inline bool invoke_function(const FuncType& func_type, uint32_t func_idx, Instance& instance,
513+
inline bool invoke_function(size_t num_args, uint32_t func_idx, Instance& instance,
514514
OperandStack& stack, ExecutionContext& ctx) noexcept
515515
{
516-
const auto num_args = func_type.inputs.size();
517516
assert(stack.size() >= num_args);
518517
const auto call_args = stack.rend() - num_args;
519518

@@ -525,7 +524,6 @@ inline bool invoke_function(const FuncType& func_type, uint32_t func_idx, Instan
525524
stack.drop(num_args);
526525

527526
// NOTE: validation ensures there is at most 1 output value
528-
assert(func_type.outputs.size() == (ret.has_value ? 1 : 0));
529527
// Push back the result
530528
if (ret.has_value)
531529
stack.push(ret.value);
@@ -629,9 +627,10 @@ ExecutionResult execute(
629627
case Instr::call:
630628
{
631629
const auto called_func_idx = read<uint32_t>(pc);
632-
const auto& called_func_type = instance.module->get_function_type(called_func_idx);
630+
const auto called_func_num_args =
631+
instance.module->get_function_type(called_func_idx).inputs.size();
633632

634-
if (!invoke_function(called_func_type, called_func_idx, instance, stack, ctx))
633+
if (!invoke_function(called_func_num_args, called_func_idx, instance, stack, ctx))
635634
goto trap;
636635
break;
637636
}
@@ -657,8 +656,8 @@ ExecutionResult execute(
657656
if (expected_type != actual_type)
658657
goto trap;
659658

660-
if (!invoke_function(
661-
actual_type, called_func.func_idx, *called_func.instance, stack, ctx))
659+
if (!invoke_function(actual_type.inputs.size(), called_func.func_idx,
660+
*called_func.instance, stack, ctx))
662661
goto trap;
663662
break;
664663
}

0 commit comments

Comments
 (0)