Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make find_exported_* functions noexcept [skip ci]
Browse files Browse the repository at this point in the history
gumb0 committed Mar 31, 2021

Verified

This commit was signed with the committer’s verified signature.
gumb0 Andrei Maiboroda
1 parent 495a0c9 commit 62e3de7
Showing 2 changed files with 21 additions and 11 deletions.
17 changes: 11 additions & 6 deletions lib/fizzy/instantiate.cpp
Original file line number Diff line number Diff line change
@@ -305,7 +305,8 @@ ExternalGlobal find_imported_global(const std::string& module, const std::string
return {it->value, module_global_type};
}

std::optional<uint32_t> find_export(const Module& module, ExternalKind kind, std::string_view name)
std::optional<uint32_t> find_export(
const Module& module, ExternalKind kind, std::string_view name) noexcept
{
const auto it = std::find_if(module.exportsec.begin(), module.exportsec.end(),
[kind, name](const auto& export_) { return export_.kind == kind && export_.name == name; });
@@ -488,12 +489,14 @@ std::vector<ExternalGlobal> resolve_imported_globals(
return external_globals;
}

std::optional<FuncIdx> find_exported_function_index(const Module& module, std::string_view name)
std::optional<FuncIdx> find_exported_function_index(
const Module& module, std::string_view name) noexcept
{
return find_export(module, ExternalKind::Function, name);
}

std::optional<ExternalFunction> find_exported_function(Instance& instance, std::string_view name)
std::optional<ExternalFunction> find_exported_function(
Instance& instance, std::string_view name) noexcept
{
const auto opt_index = find_export(*instance.module, ExternalKind::Function, name);
if (!opt_index.has_value())
@@ -504,7 +507,8 @@ std::optional<ExternalFunction> find_exported_function(Instance& instance, std::
ExecuteFunction(instance, idx), instance.module->get_function_type(idx)};
}

std::optional<ExternalGlobal> find_exported_global(Instance& instance, std::string_view name)
std::optional<ExternalGlobal> find_exported_global(
Instance& instance, std::string_view name) noexcept
{
const auto opt_index = find_export(*instance.module, ExternalKind::Global, name);
if (!opt_index.has_value())
@@ -526,7 +530,7 @@ std::optional<ExternalGlobal> find_exported_global(Instance& instance, std::stri
}
}

std::optional<ExternalTable> find_exported_table(Instance& instance, std::string_view name)
std::optional<ExternalTable> find_exported_table(Instance& instance, std::string_view name) noexcept
{
// Index returned from find_export is discarded, because there's no more than 1 table
if (!find_export(*instance.module, ExternalKind::Table, name))
@@ -535,7 +539,8 @@ std::optional<ExternalTable> find_exported_table(Instance& instance, std::string
return ExternalTable{instance.table.get(), instance.table_limits};
}

std::optional<ExternalMemory> find_exported_memory(Instance& instance, std::string_view name)
std::optional<ExternalMemory> find_exported_memory(
Instance& instance, std::string_view name) noexcept
{
// Index returned from find_export is discarded, because there's no more than 1 memory
if (!find_export(*instance.module, ExternalKind::Memory, name))
15 changes: 10 additions & 5 deletions lib/fizzy/instantiate.hpp
Original file line number Diff line number Diff line change
@@ -236,18 +236,23 @@ std::vector<ExternalGlobal> resolve_imported_globals(
const Module& module, const std::vector<ImportedGlobal>& imported_globals);

/// Find exported function index by name.
std::optional<FuncIdx> find_exported_function_index(const Module& module, std::string_view name);
std::optional<FuncIdx> find_exported_function_index(
const Module& module, std::string_view name) noexcept;

/// Find exported function by name.
std::optional<ExternalFunction> find_exported_function(Instance& instance, std::string_view name);
std::optional<ExternalFunction> find_exported_function(
Instance& instance, std::string_view name) noexcept;

/// Find exported global by name.
std::optional<ExternalGlobal> find_exported_global(Instance& instance, std::string_view name);
std::optional<ExternalGlobal> find_exported_global(
Instance& instance, std::string_view name) noexcept;

/// Find exported table by name.
std::optional<ExternalTable> find_exported_table(Instance& instance, std::string_view name);
std::optional<ExternalTable> find_exported_table(
Instance& instance, std::string_view name) noexcept;

/// Find exported memory by name.
std::optional<ExternalMemory> find_exported_memory(Instance& instance, std::string_view name);
std::optional<ExternalMemory> find_exported_memory(
Instance& instance, std::string_view name) noexcept;

} // namespace fizzy

0 comments on commit 62e3de7

Please sign in to comment.