Skip to content

Commit

Permalink
Rename ExecutionContext::{Guard -> LocalContext}
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Apr 1, 2021
1 parent ce4e30a commit 3932f52
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/fizzy/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ ExecutionResult execute(
const auto& code = instance.module->get_code(func_idx);
auto* const memory = instance.memory.get();

const auto ctx_guard = ctx.increment_call_depth();
const auto local_ctx = ctx.increment_call_depth();

OperandStack stack(args, func_type.inputs.size(), code.local_count,
static_cast<size_t>(code.max_stack_height));
Expand Down
22 changes: 11 additions & 11 deletions lib/fizzy/execution_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ namespace fizzy
/// Users may decide how to allocate the execution context, but some good defaults are available.
class ExecutionContext
{
/// Call depth increment guard.
/// Call local execution context.
/// It will automatically decrement the call depth to the original value
/// when going out of scope.
class [[nodiscard]] Guard
class [[nodiscard]] LocalContext
{
ExecutionContext& m_execution_context; ///< Reference to the guarded execution context.
ExecutionContext& m_shared_ctx; ///< Reference to the shared execution context.

public:
Guard(const Guard&) = delete;
Guard& operator=(const Guard&) = delete;
LocalContext(const LocalContext&) = delete;
LocalContext& operator=(const LocalContext&) = delete;

explicit Guard(ExecutionContext& ctx) noexcept : m_execution_context{ctx}
explicit LocalContext(ExecutionContext& ctx) noexcept : m_shared_ctx{ctx}
{
++m_execution_context.depth;
++m_shared_ctx.depth;
}

~Guard() noexcept { --m_execution_context.depth; }
~LocalContext() noexcept { --m_shared_ctx.depth; }
};

public:
int depth = 0; ///< Current call depth.

/// Increments the call depth and returns the guard object which decrements
/// the call depth back to the original value when going out of scope.
Guard increment_call_depth() noexcept { return Guard{*this}; }
/// Increments the call depth and returns the local call context which
/// decrements the call depth back to the original value when going out of scope.
LocalContext increment_call_depth() noexcept { return LocalContext{*this}; }
};
} // namespace fizzy
8 changes: 4 additions & 4 deletions test/unittests/execute_call_depth_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ TEST(execute_call_depth, call_host_function_calling_wasm_function_inclusive)
constexpr auto host_f = [](std::any&, Instance& instance, const Value*,
ExecutionContext& ctx) noexcept {
recorded_depth = ctx.depth;
const auto ctx_guard = ctx.increment_call_depth();
const auto local_ctx = ctx.increment_call_depth();
return fizzy::execute(instance, 2 /* $leaf */, {}, ctx);
};

Expand Down Expand Up @@ -304,7 +304,7 @@ TEST(execute_call_depth, call_host_function_calling_another_wasm_module)
ExecutionContext& ctx) noexcept {
recorded_depth = ctx.depth;
auto instance = *std::any_cast<Instance*>(&host_context);
const auto ctx_guard = ctx.increment_call_depth();
const auto local_ctx = ctx.increment_call_depth();
return fizzy::execute(*instance, 0, {}, ctx);
};

Expand Down Expand Up @@ -466,7 +466,7 @@ TEST(execute_call_depth, execute_host_function_within_wasm_recursion_limit)
constexpr auto host_f = [](std::any&, Instance& instance, const Value*,
ExecutionContext& ctx) noexcept {
max_recorded_wasm_recursion_depth = std::max(max_recorded_wasm_recursion_depth, ctx.depth);
const auto ctx_guard = ctx.increment_call_depth();
const auto local_ctx = ctx.increment_call_depth();
return fizzy::execute(instance, 0, {}, ctx);
};

Expand Down Expand Up @@ -537,7 +537,7 @@ TEST(execute_call, call_host_function_calling_wasm_interleaved_infinite_recursio
ExecutionContext& ctx) noexcept {
EXPECT_LT(ctx.depth, DepthLimit);
++counter;
const auto ctx_guard = ctx.increment_call_depth();
const auto local_ctx = ctx.increment_call_depth();
return fizzy::execute(instance, 1, {}, ctx);
};

Expand Down

0 comments on commit 3932f52

Please sign in to comment.