Skip to content

Commit f714cad

Browse files
committed
capi: Get function type from module
1 parent f500580 commit f714cad

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

include/fizzy/fizzy.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ FizzyInstance* fizzy_instantiate(const FizzyModule* module,
134134
/// If passed pointer is NULL, has no effect.
135135
void fizzy_free_instance(FizzyInstance* instance);
136136

137+
/// Get pointer to module of an instance.
138+
///
139+
/// @note The returned pointer represents non-owning, "view"-access to the module and must not be
140+
/// passed to fizzy_free_module.
141+
const FizzyModule* fizzy_get_instance_module(FizzyInstance* instance);
142+
137143
/// Get pointer to memory of an instance.
138144
///
139145
/// @returns Pointer to memory data or NULL in case instance doesn't have any memory.

lib/fizzy/capi.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ void fizzy_free_instance(FizzyInstance* instance)
191191
delete unwrap(instance);
192192
}
193193

194+
const FizzyModule* fizzy_get_instance_module(FizzyInstance* instance)
195+
{
196+
return wrap(unwrap(instance)->module.get());
197+
}
198+
194199
uint8_t* fizzy_get_instance_memory_data(FizzyInstance* instance)
195200
{
196201
auto& memory = unwrap(instance)->memory;

test/unittests/capi_test.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ TEST(capi, free_instance_null)
141141
fizzy_free_instance(nullptr);
142142
}
143143

144+
TEST(capi, get_instance_module)
145+
{
146+
/* wat2wasm
147+
(func (param i32 i32))
148+
*/
149+
const auto wasm = from_hex("0061736d0100000001060160027f7f00030201000a040102000b");
150+
auto module = fizzy_parse(wasm.data(), wasm.size());
151+
ASSERT_NE(module, nullptr);
152+
153+
auto instance = fizzy_instantiate(module, nullptr, 0);
154+
ASSERT_NE(instance, nullptr);
155+
156+
auto instance_module = fizzy_get_instance_module(instance);
157+
ASSERT_NE(instance_module, nullptr);
158+
159+
EXPECT_EQ(fizzy_get_function_type(instance_module, 0).inputs_size, 2);
160+
161+
fizzy_free_instance(instance);
162+
}
163+
144164
TEST(capi, memory_access_no_memory)
145165
{
146166
/* wat2wasm

0 commit comments

Comments
 (0)