Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/fizzy/fizzy.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ FizzyInstance* fizzy_instantiate(const FizzyModule* module,
/// If passed pointer is NULL, has no effect.
void fizzy_free_instance(FizzyInstance* instance);

/// Get pointer to module of an instance.
///
/// @note The returned pointer represents non-owning, "view"-access to the module and must not be
/// passed to fizzy_free_module.
const FizzyModule* fizzy_get_instance_module(FizzyInstance* instance);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const FizzyModule* fizzy_get_instance_module(FizzyInstance* instance);
const FizzyModule* fizzy_instance_get_module(FizzyInstance* instance);

?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be better wording, but we already have get_instance_memory, so I suggest we go with what is the PR and then rename all of them at once if we want.


/// Get pointer to memory of an instance.
///
/// @returns Pointer to memory data or NULL in case instance doesn't have any memory.
Expand Down
5 changes: 5 additions & 0 deletions lib/fizzy/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ void fizzy_free_instance(FizzyInstance* instance)
delete unwrap(instance);
}

const FizzyModule* fizzy_get_instance_module(FizzyInstance* instance)
{
return wrap(unwrap(instance)->module.get());
}

uint8_t* fizzy_get_instance_memory_data(FizzyInstance* instance)
{
auto& memory = unwrap(instance)->memory;
Expand Down
20 changes: 20 additions & 0 deletions test/unittests/capi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ TEST(capi, free_instance_null)
fizzy_free_instance(nullptr);
}

TEST(capi, get_instance_module)
{
/* wat2wasm
(func (param i32 i32))
*/
const auto wasm = from_hex("0061736d0100000001060160027f7f00030201000a040102000b");
auto module = fizzy_parse(wasm.data(), wasm.size());
ASSERT_NE(module, nullptr);

auto instance = fizzy_instantiate(module, nullptr, 0);
ASSERT_NE(instance, nullptr);

auto instance_module = fizzy_get_instance_module(instance);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding EXPECT_EQ(module, instance_module) ?

ASSERT_NE(instance_module, nullptr);

EXPECT_EQ(fizzy_get_function_type(instance_module, 0).inputs_size, 2);

fizzy_free_instance(instance);
}

TEST(capi, memory_access_no_memory)
{
/* wat2wasm
Expand Down