Skip to content

Commit be1011f

Browse files
committed
capi: find_exported_function
1 parent 6fefa60 commit be1011f

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

include/fizzy/fizzy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ struct FizzyModule* fizzy_parse(const uint8_t* wasm_binary, size_t wasm_binary_s
7171
/// Should be called unless @p module was passed to fizzy_instantiate.
7272
void fizzy_free_module(struct FizzyModule* module);
7373

74+
bool fizzy_find_exported_function(
75+
const struct FizzyModule* module, const char* name, uint32_t* out_func_idx);
76+
7477
/// Instantiate a module.
7578
/// Takes ownership of module, i.e. @p module is invalidated after this call.
7679
///

lib/fizzy/capi.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ inline fizzy::Module* unwrap(FizzyModule* module) noexcept
2121
return reinterpret_cast<fizzy::Module*>(module);
2222
}
2323

24+
inline const fizzy::Module* unwrap(const FizzyModule* module) noexcept
25+
{
26+
return reinterpret_cast<const fizzy::Module*>(module);
27+
}
28+
2429
inline FizzyValue wrap(fizzy::Value value) noexcept
2530
{
2631
return fizzy::bit_cast<FizzyValue>(value);
@@ -108,6 +113,17 @@ void fizzy_free_module(FizzyModule* module)
108113
delete unwrap(module);
109114
}
110115

116+
bool fizzy_find_exported_function(
117+
const struct FizzyModule* module, const char* name, uint32_t* out_func_idx)
118+
{
119+
const auto optional_func_idx = fizzy::find_exported_function(*unwrap(module), name);
120+
if (!optional_func_idx)
121+
return false;
122+
123+
*out_func_idx = *optional_func_idx;
124+
return true;
125+
}
126+
111127
FizzyInstance* fizzy_instantiate(FizzyModule* module,
112128
const FizzyExternalFunction* imported_functions, size_t imported_functions_size)
113129
{

0 commit comments

Comments
 (0)