File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -134,6 +134,12 @@ FizzyInstance* fizzy_instantiate(const FizzyModule* module,
134134/// If passed pointer is NULL, has no effect.
135135void 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.
Original file line number Diff line number Diff 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+
194199uint8_t * fizzy_get_instance_memory_data (FizzyInstance* instance)
195200{
196201 auto & memory = unwrap (instance)->memory ;
Original file line number Diff line number Diff 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+
144164TEST (capi, memory_access_no_memory)
145165{
146166 /* wat2wasm
You can’t perform that action at this time.
0 commit comments