Skip to content

Commit 7a8e1de

Browse files
committed
Return nullptr for trap in execute_internal()
1 parent f23929a commit 7a8e1de

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

lib/fizzy/execute.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ inline bool invoke_function(const FuncType& func_type, uint32_t func_idx, Instan
483483

484484
const auto ret = execute_internal(instance, func_idx, stack.rend(), depth + 1);
485485
// Bubble up traps
486-
if (ret.trapped)
486+
if (ret == nullptr)
487487
return false;
488488

489489
stack.drop(num_args - num_outputs);
@@ -492,13 +492,13 @@ inline bool invoke_function(const FuncType& func_type, uint32_t func_idx, Instan
492492

493493
} // namespace
494494

495-
ExecutionResult execute_internal(Instance& instance, FuncIdx func_idx, Value* args_end, int depth)
495+
Value* execute_internal(Instance& instance, FuncIdx func_idx, Value* args_end, int depth)
496496
{
497497
assert(args_end != nullptr);
498498

499499
assert(depth >= 0);
500500
if (depth > CallStackLimit)
501-
return Trap;
501+
return nullptr;
502502

503503
const auto& func_type = instance.module->get_function_type(func_idx);
504504

@@ -508,9 +508,12 @@ ExecutionResult execute_internal(Instance& instance, FuncIdx func_idx, Value* ar
508508
if (func_idx < instance.imported_functions.size())
509509
{
510510
const auto res = instance.imported_functions[func_idx].function(instance, args, depth);
511+
if (res.trapped)
512+
return nullptr;
513+
511514
if (res.has_value)
512515
args[0] = res.value;
513-
return res;
516+
return args;
514517
}
515518

516519
const auto& code = instance.module->get_code(func_idx);
@@ -1538,9 +1541,9 @@ ExecutionResult execute_internal(Instance& instance, FuncIdx func_idx, Value* ar
15381541
if (stack.size() != 0 && args != nullptr)
15391542
args[0] = stack.top();
15401543

1541-
return Void;
1544+
return args;
15421545

15431546
trap:
1544-
return Trap;
1547+
return nullptr;
15451548
}
15461549
} // namespace fizzy

lib/fizzy/execute.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ constexpr ExecutionResult Void{true};
3737
constexpr ExecutionResult Trap{false};
3838

3939
/// The "unsafe" internal execute function.
40-
ExecutionResult execute_internal(Instance& instance, FuncIdx func_idx, Value* args, int depth);
40+
Value* execute_internal(Instance& instance, FuncIdx func_idx, Value* args, int depth);
4141

4242
// Execute a function on an instance.
4343
inline ExecutionResult execute(
@@ -56,8 +56,8 @@ inline ExecutionResult execute(
5656
auto* args_end = p_args + num_args;
5757
const auto res = execute_internal(instance, func_idx, args_end, depth);
5858

59-
if (res.trapped)
60-
return res;
59+
if (res == nullptr)
60+
return Trap;
6161

6262
if (num_outputs == 1)
6363
{

0 commit comments

Comments
 (0)