diff --git a/lib/fizzy/instantiate.cpp b/lib/fizzy/instantiate.cpp index b11d98b20..080b284cc 100644 --- a/lib/fizzy/instantiate.cpp +++ b/lib/fizzy/instantiate.cpp @@ -237,7 +237,7 @@ std::optional find_export(const Module& module, ExternalKind kind, std } // namespace -std::unique_ptr instantiate(std::unique_ptr&& module, +std::unique_ptr instantiate(std::unique_ptr module, std::vector imported_functions, std::vector imported_tables, std::vector imported_memories, std::vector imported_globals, uint32_t memory_pages_limit /*= DefaultMemoryPagesLimit*/) @@ -373,12 +373,12 @@ std::unique_ptr instantiate(std::unique_ptr&& module, return instance; } -std::unique_ptr instantiate(const std::unique_ptr& module, +std::unique_ptr instantiate(Module module, std::vector imported_functions, std::vector imported_tables, std::vector imported_memories, std::vector imported_globals, uint32_t memory_pages_limit) { - return instantiate(std::make_unique(*module), std::move(imported_functions), + return instantiate(std::make_unique(std::move(module)), std::move(imported_functions), std::move(imported_tables), std::move(imported_memories), std::move(imported_globals), memory_pages_limit); } diff --git a/lib/fizzy/instantiate.hpp b/lib/fizzy/instantiate.hpp index 5513684ce..4c4544de0 100644 --- a/lib/fizzy/instantiate.hpp +++ b/lib/fizzy/instantiate.hpp @@ -87,8 +87,7 @@ struct Instance }; // Instantiate a module. -// Transfers ownership of passed module to instance. -std::unique_ptr instantiate(std::unique_ptr&& module, +std::unique_ptr instantiate(std::unique_ptr module, std::vector imported_functions = {}, std::vector imported_tables = {}, std::vector imported_memories = {}, @@ -96,8 +95,7 @@ std::unique_ptr instantiate(std::unique_ptr&& module, uint32_t memory_pages_limit = DefaultMemoryPagesLimit); // Instantiate a module. -// Makes a copy of passed module and stores it in instance. -std::unique_ptr instantiate(const std::unique_ptr& module, +std::unique_ptr instantiate(Module _module, std::vector imported_functions = {}, std::vector imported_tables = {}, std::vector imported_memories = {}, diff --git a/test/spectests/spectests.cpp b/test/spectests/spectests.cpp index 4601b49f6..15ff95170 100644 --- a/test/spectests/spectests.cpp +++ b/test/spectests/spectests.cpp @@ -89,7 +89,7 @@ class test_runner explicit test_runner(const test_settings& ts) : m_settings{ts}, m_registered_names{{spectest_name, spectest_name}} { - m_instances[spectest_name] = fizzy::instantiate(spectest_module); + m_instances[spectest_name] = fizzy::instantiate(*spectest_module); } test_results run_from_file(const fs::path& path) diff --git a/test/unittests/api_test.cpp b/test/unittests/api_test.cpp index 955b366f8..ab5ac025f 100644 --- a/test/unittests/api_test.cpp +++ b/test/unittests/api_test.cpp @@ -96,7 +96,7 @@ TEST(api, resolve_imported_functions) Value global = 0; const std::vector external_globals{{&global, {ValType::i32, false}}}; auto instance = instantiate( - module, external_functions, {}, {}, std::vector(external_globals)); + *module, external_functions, {}, {}, std::vector(external_globals)); EXPECT_THAT(execute(*instance, 0, {}), Result(0)); EXPECT_THAT(execute(*instance, 1, {Value{0}}), Result(1)); @@ -115,7 +115,7 @@ TEST(api, resolve_imported_functions) resolve_imported_functions(*module, std::move(imported_functions_reordered)); EXPECT_EQ(external_functions_reordered.size(), 4); - auto instance_reordered = instantiate(module, external_functions_reordered, {}, {}, + auto instance_reordered = instantiate(*module, external_functions_reordered, {}, {}, std::vector(external_globals)); EXPECT_THAT(execute(*instance_reordered, 0, {}), Result(0)); @@ -138,7 +138,7 @@ TEST(api, resolve_imported_functions) EXPECT_EQ(external_functions_extra.size(), 4); auto instance_extra = instantiate( - module, external_functions_extra, {}, {}, std::vector(external_globals)); + *module, external_functions_extra, {}, {}, std::vector(external_globals)); EXPECT_THAT(execute(*instance_extra, 0, {}), Result(0)); EXPECT_THAT(execute(*instance_extra, 1, {Value{0}}), Result(1)); diff --git a/test/unittests/end_to_end_test.cpp b/test/unittests/end_to_end_test.cpp index c303b6ce9..e7c5d3a25 100644 --- a/test/unittests/end_to_end_test.cpp +++ b/test/unittests/end_to_end_test.cpp @@ -31,7 +31,7 @@ TEST(end_to_end, milestone1) const auto wasm = from_hex( "0061736d0100000001070160027f7f017f030201000a13011101017f200020016a20026a220220006a0b"); const auto module = parse(wasm); - auto instance = instantiate(module); + auto instance = instantiate(*module); EXPECT_THAT(execute(*instance, 0, {20, 22}), Result(20 + 22 + 20)); } @@ -71,7 +71,7 @@ TEST(end_to_end, milestone2) const auto module = parse(bin); - auto instance = instantiate(module); + auto instance = instantiate(*module); auto& memory = *instance->memory; // This performs uint256 x uint256 -> uint512 multiplication. @@ -129,7 +129,7 @@ TEST(end_to_end, nested_loops_in_c) const auto func_idx = find_exported_function(*module, "test"); ASSERT_TRUE(func_idx); - auto instance = instantiate(module); + auto instance = instantiate(*module); EXPECT_THAT(execute(*instance, *func_idx, {10, 2, 5}), Result(4)); } @@ -171,7 +171,7 @@ TEST(end_to_end, memset) const auto func_idx = find_exported_function(*module, "test"); ASSERT_TRUE(func_idx); - auto instance = instantiate(module); + auto instance = instantiate(*module); EXPECT_THAT(execute(*instance, *func_idx, {0, 2}), Result()); EXPECT_EQ(hex(instance->memory->substr(0, 2 * sizeof(int))), "d2040000d2040000"); } diff --git a/test/unittests/execute_call_test.cpp b/test/unittests/execute_call_test.cpp index 2790dbe1e..4ec8e1bd3 100644 --- a/test/unittests/execute_call_test.cpp +++ b/test/unittests/execute_call_test.cpp @@ -185,7 +185,7 @@ TEST(execute_call, call_indirect_imported_table) table_elements table{ {{f3, out_i32}}, {{f2, out_i32}}, {{f1, out_i32}}, {{f4, out_i64}}, {{f5, out_i32}}}; - auto instance = instantiate(module, {}, {{&table, {5, 20}}}); + auto instance = instantiate(*module, {}, {{&table, {5, 20}}}); for (const auto param : {0u, 1u, 2u}) { @@ -275,7 +275,7 @@ TEST(execute_call, imported_function_call) constexpr auto host_foo = [](Instance&, span, int) { return Value{42}; }; const auto host_foo_type = module->typesec[0]; - auto instance = instantiate(module, {{host_foo, host_foo_type}}); + auto instance = instantiate(*module, {{host_foo, host_foo_type}}); EXPECT_THAT(execute(*instance, 1, {}), Result(42)); } @@ -302,7 +302,7 @@ TEST(execute_call, imported_function_call_with_arguments) }; const auto host_foo_type = module->typesec[0]; - auto instance = instantiate(module, {{host_foo, host_foo_type}}); + auto instance = instantiate(*module, {{host_foo, host_foo_type}}); EXPECT_THAT(execute(*instance, 1, {20}), Result(42)); } @@ -350,7 +350,7 @@ TEST(execute_call, imported_functions_call_indirect) return Value{(11 + uint64_t{x} / 11) / 2}; }; - auto instance = instantiate(module, {{sqr, module->typesec[0]}, {isqrt, module->typesec[0]}}); + auto instance = instantiate(*module, {{sqr, module->typesec[0]}, {isqrt, module->typesec[0]}}); EXPECT_THAT(execute(*instance, 3, {0, 10}), Result(20)); // double(10) EXPECT_THAT(execute(*instance, 3, {1, 9}), Result(81)); // sqr(9) EXPECT_THAT(execute(*instance, 3, {2, 50}), Result(7)); // isqrt(50) @@ -370,7 +370,7 @@ TEST(execute_call, imported_function_from_another_module) const auto bin1 = from_hex( "0061736d0100000001070160027f7f017f030201000707010373756200000a09010700200020016b0b"); const auto module1 = parse(bin1); - auto instance1 = instantiate(module1); + auto instance1 = instantiate(*module1); /* wat2wasm (module @@ -395,7 +395,7 @@ TEST(execute_call, imported_function_from_another_module) return fizzy::execute(*instance1, *func_idx, args.data()); }; - auto instance2 = instantiate(module2, {{sub, module1->typesec[0]}}); + auto instance2 = instantiate(*module2, {{sub, module1->typesec[0]}}); EXPECT_THAT(execute(*instance2, 1, {44, 2}), Result(42)); } @@ -416,7 +416,7 @@ TEST(execute_call, imported_table_from_another_module) "0061736d0100000001070160027f7f017f030201000404017000010707010374616201000907010041000b0100" "0a09010700200020016b0b"); const auto module1 = parse(bin1); - auto instance1 = instantiate(module1); + auto instance1 = instantiate(*module1); /* wat2wasm (module @@ -438,7 +438,7 @@ TEST(execute_call, imported_table_from_another_module) const auto table = fizzy::find_exported_table(*instance1, "tab"); ASSERT_TRUE(table.has_value()); - auto instance2 = instantiate(module2, {}, {*table}); + auto instance2 = instantiate(*module2, {}, {*table}); EXPECT_THAT(execute(*instance2, 0, {44, 2}), Result(42)); } @@ -460,7 +460,7 @@ TEST(execute_call, imported_table_modified_by_uninstantiable_module) "0061736d0100000001070160027f7f017f030201000404017000010707010374616201000a0d010b0020002001" "41001100000b"); const auto module1 = parse(bin1); - auto instance1 = instantiate(module1); + auto instance1 = instantiate(*module1); /* wat2wasm (module @@ -483,7 +483,7 @@ TEST(execute_call, imported_table_modified_by_uninstantiable_module) ASSERT_TRUE(table.has_value()); EXPECT_THROW_MESSAGE( - instantiate(module2, {}, {*table}), instantiate_error, "start function failed to execute"); + instantiate(*module2, {}, {*table}), instantiate_error, "start function failed to execute"); EXPECT_THAT(execute(*instance1, 0, {44, 2}), Result(42)); } @@ -531,7 +531,7 @@ TEST(execute_call, call_max_depth) const auto bin = from_hex("0061736d010000000105016000017f03030200000a0b020400412a0b040010000b"); const auto module = parse(bin); - auto instance = instantiate(module); + auto instance = instantiate(*module); EXPECT_THAT(execute(*instance, 0, {}, MaxDepth), Result(42)); EXPECT_THAT(execute(*instance, 1, {}, MaxDepth), Traps()); @@ -574,7 +574,7 @@ TEST(execute_call, call_imported_infinite_recursion) }; const auto host_foo_type = module->typesec[0]; - auto instance = instantiate(module, {{host_foo, host_foo_type}}); + auto instance = instantiate(*module, {{host_foo, host_foo_type}}); EXPECT_THAT(execute(*instance, 0, {}), Traps()); } @@ -598,7 +598,7 @@ TEST(execute_call, call_via_imported_infinite_recursion) }; const auto host_foo_type = module->typesec[0]; - auto instance = instantiate(module, {{host_foo, host_foo_type}}); + auto instance = instantiate(*module, {{host_foo, host_foo_type}}); EXPECT_THAT(execute(*instance, 1, {}), Traps()); } @@ -618,7 +618,7 @@ TEST(execute_call, call_imported_max_depth_recursion) }; const auto host_foo_type = module->typesec[0]; - auto instance = instantiate(module, {{host_foo, host_foo_type}}); + auto instance = instantiate(*module, {{host_foo, host_foo_type}}); EXPECT_THAT(execute(*instance, 0, {}), Result(uint32_t{1})); } @@ -643,7 +643,7 @@ TEST(execute_call, call_via_imported_max_depth_recursion) }; const auto host_foo_type = module->typesec[0]; - auto instance = instantiate(module, {{host_foo, host_foo_type}}); + auto instance = instantiate(*module, {{host_foo, host_foo_type}}); EXPECT_THAT(execute(*instance, 1, {}), Result(uint32_t{1})); } @@ -664,7 +664,7 @@ TEST(execute_call, call_indirect_imported_table_infinite_recursion) "0061736d010000000105016000017f030201000404017000020707010374616201000907010041000b01000a09" "01070041011100000b"); const auto module1 = parse(bin1); - auto instance1 = instantiate(module1); + auto instance1 = instantiate(*module1); /* wat2wasm (module @@ -684,7 +684,7 @@ TEST(execute_call, call_indirect_imported_table_infinite_recursion) const auto table = fizzy::find_exported_table(*instance1, "tab"); ASSERT_TRUE(table.has_value()); - auto instance2 = instantiate(module2, {}, {*table}); + auto instance2 = instantiate(*module2, {}, {*table}); EXPECT_THAT(execute(*instance1, 0, {}), Traps()); } @@ -708,6 +708,6 @@ TEST(execute_call, drop_call_result) EXPECT_EQ(module->codesec[0].max_stack_height, 1); EXPECT_EQ(module->codesec[1].max_stack_height, 1); const auto func_idx = find_exported_function(*module, "drop_call_result"); - auto instance = instantiate(module); + auto instance = instantiate(*module); EXPECT_THAT(fizzy::execute(*instance, *func_idx, {}), Result()); } diff --git a/test/unittests/execute_control_test.cpp b/test/unittests/execute_control_test.cpp index a0d34efd2..6e7e46b11 100644 --- a/test/unittests/execute_control_test.cpp +++ b/test/unittests/execute_control_test.cpp @@ -668,7 +668,7 @@ TEST(execute_control, br_1_out_of_function_and_imported_function) int) noexcept -> ExecutionResult { return Void; }; const auto module = parse(bin); - auto instance = instantiate(module, {{fake_imported_function, module->typesec[0]}}); + auto instance = instantiate(*module, {{fake_imported_function, module->typesec[0]}}); EXPECT_THAT(execute(*instance, 1, {}), Result(1)); } diff --git a/test/unittests/execute_floating_point_test.cpp b/test/unittests/execute_floating_point_test.cpp index 4802d0670..7c1e1bdfa 100644 --- a/test/unittests/execute_floating_point_test.cpp +++ b/test/unittests/execute_floating_point_test.cpp @@ -2016,7 +2016,7 @@ TEST(execute_floating_point, f32_store) for (const auto& [arg, expected] : test_cases) { - auto instance = instantiate(module); + auto instance = instantiate(*module); EXPECT_THAT(execute(*instance, 0, {arg, 1}), Result()); EXPECT_EQ(instance->memory->substr(0, 6), expected); @@ -2093,7 +2093,7 @@ TEST(execute_floating_point, f64_store) for (const auto& [arg, expected] : test_cases) { - auto instance = instantiate(module); + auto instance = instantiate(*module); EXPECT_THAT(execute(*instance, 0, {arg, 1}), Result()); EXPECT_EQ(instance->memory->substr(0, 10), expected); diff --git a/test/unittests/execute_test.cpp b/test/unittests/execute_test.cpp index 65620e6e1..15bbed354 100644 --- a/test/unittests/execute_test.cpp +++ b/test/unittests/execute_test.cpp @@ -141,7 +141,7 @@ TEST(execute, global_get_imported) Value global_value = 42; auto instance = - instantiate(module, {}, {}, {}, {ExternalGlobal{&global_value, {ValType::i64, false}}}); + instantiate(*module, {}, {}, {}, {ExternalGlobal{&global_value, {ValType::i64, false}}}); EXPECT_THAT(execute(*instance, 0, {}), Result(42)); @@ -173,7 +173,7 @@ TEST(execute, global_get_imported_and_internal) Value g1 = 40; Value g2 = 41; - auto instance = instantiate(module, {}, {}, {}, + auto instance = instantiate(*module, {}, {}, {}, {ExternalGlobal{&g1, {ValType::i32, false}}, ExternalGlobal{&g2, {ValType::i32, false}}}); EXPECT_THAT(execute(*instance, 0, {}), Result(40)); @@ -399,7 +399,7 @@ TEST(execute, i32_load_all_variants) for (const auto& test_case : test_cases) { load_instr = std::get<0>(test_case); - auto instance = instantiate(module); + auto instance = instantiate(*module); std::copy(std::begin(memory_fill), std::end(memory_fill), std::begin(*instance->memory)); EXPECT_THAT(execute(*instance, 0, {1}), Result(std::get<1>(test_case))); @@ -439,7 +439,7 @@ TEST(execute, i64_load_all_variants) for (const auto& test_case : test_cases) { load_instr = std::get<0>(test_case); - auto instance = instantiate(module); + auto instance = instantiate(*module); std::copy(std::begin(memory_fill), std::end(memory_fill), std::begin(*instance->memory)); EXPECT_THAT(execute(*instance, 0, {1}), Result(std::get<1>(test_case))); @@ -544,7 +544,7 @@ TEST(execute, i32_store_all_variants) for (const auto& test_case : test_cases) { store_instr = std::get<0>(test_case); - auto instance = instantiate(module); + auto instance = instantiate(*module); std::fill_n(instance->memory->begin(), 6, uint8_t{0xcc}); EXPECT_THAT(execute(*instance, 0, {0xb3b2b1b0, 1}), Result()); EXPECT_EQ(instance->memory->substr(0, 6), std::get<1>(test_case)); @@ -581,7 +581,7 @@ TEST(execute, i64_store_all_variants) for (const auto& test_case : test_cases) { store_instr = std::get<0>(test_case); - auto instance = instantiate(module); + auto instance = instantiate(*module); std::fill_n(instance->memory->begin(), 10, uint8_t{0xcc}); EXPECT_THAT(execute(*instance, 0, {0xb7b6b5b4b3b2b1b0, 1}), Result()); EXPECT_EQ(instance->memory->substr(0, 10), std::get<1>(test_case)); @@ -655,7 +655,7 @@ TEST(execute, memory_grow_custom_hard_limit) for (const auto& test_case : test_cases) { - const auto instance = instantiate(module, {}, {}, {}, {}, 16); + const auto instance = instantiate(*module, {}, {}, {}, {}, 16); EXPECT_THAT(execute(*instance, 0, {test_case.first}), Result(test_case.second)); } @@ -672,7 +672,7 @@ TEST(execute, memory_grow_custom_hard_limit) for (const auto& test_case : test_cases) { - const auto instance = instantiate(module_max_limit, {}, {}, {}, {}, 32); + const auto instance = instantiate(*module_max_limit, {}, {}, {}, {}, 32); EXPECT_THAT(execute(*instance, 0, {test_case.first}), Result(test_case.second)); } @@ -691,12 +691,12 @@ TEST(execute, memory_grow_custom_hard_limit) { bytes memory(PageSize, 0); const auto instance = - instantiate(module_imported, {}, {}, {{&memory, {1, std::nullopt}}}, {}, 16); + instantiate(*module_imported, {}, {}, {{&memory, {1, std::nullopt}}}, {}, 16); EXPECT_THAT(execute(*instance, 0, {test_case.first}), Result(test_case.second)); bytes memory_max_limit(PageSize, 0); const auto instance_max_limit = - instantiate(module_imported, {}, {}, {{&memory_max_limit, {1, 16}}}, {}, 32); + instantiate(*module_imported, {}, {}, {{&memory_max_limit, {1, 16}}}, {}, 32); EXPECT_THAT(execute(*instance_max_limit, 0, {test_case.first}), Result(test_case.second)); } @@ -716,7 +716,7 @@ TEST(execute, memory_grow_custom_hard_limit) { bytes memory(PageSize, 0); const auto instance = - instantiate(module_imported_max_limit, {}, {}, {{&memory, {1, 16}}}, {}, 32); + instantiate(*module_imported_max_limit, {}, {}, {{&memory, {1, 16}}}, {}, 32); EXPECT_THAT(execute(*instance, 0, {test_case.first}), Result(test_case.second)); } @@ -736,7 +736,7 @@ TEST(execute, memory_grow_custom_hard_limit) { bytes memory(PageSize, 0); const auto instance = - instantiate(module_imported_max_limit_narrowing, {}, {}, {{&memory, {1, 16}}}, {}, 32); + instantiate(*module_imported_max_limit_narrowing, {}, {}, {{&memory, {1, 16}}}, {}, 32); EXPECT_THAT(execute(*instance, 0, {test_case.first}), Result(test_case.second)); } } @@ -780,7 +780,7 @@ TEST(execute, imported_function) return Value{as_uint32(args[0]) + as_uint32(args[1])}; }; - auto instance = instantiate(module, {{host_foo, module->typesec[0]}}); + auto instance = instantiate(*module, {{host_foo, module->typesec[0]}}); EXPECT_THAT(execute(*instance, 0, {20, 22}), Result(42)); } @@ -804,7 +804,7 @@ TEST(execute, imported_two_functions) }; auto instance = - instantiate(module, {{host_foo1, module->typesec[0]}, {host_foo2, module->typesec[0]}}); + instantiate(*module, {{host_foo1, module->typesec[0]}, {host_foo2, module->typesec[0]}}); EXPECT_THAT(execute(*instance, 0, {20, 22}), Result(42)); EXPECT_THAT(execute(*instance, 1, {20, 22}), Result(440)); } @@ -833,7 +833,7 @@ TEST(execute, imported_functions_and_regular_one) const auto module = parse(wasm); ASSERT_EQ(module->typesec.size(), 1); auto instance = - instantiate(module, {{host_foo1, module->typesec[0]}, {host_foo2, module->typesec[0]}}); + instantiate(*module, {{host_foo1, module->typesec[0]}, {host_foo2, module->typesec[0]}}); EXPECT_THAT(execute(*instance, 0, {20, 22}), Result(42)); EXPECT_THAT(execute(*instance, 1, {20, 10}), Result(200)); } @@ -858,7 +858,7 @@ TEST(execute, imported_functions_count_args) const auto module = parse(wasm); ASSERT_EQ(module->typesec.size(), 2); auto instance_counter = - instantiate(module, {{count_args, module->typesec[0]}, {count_args, module->typesec[1]}}); + instantiate(*module, {{count_args, module->typesec[0]}, {count_args, module->typesec[1]}}); EXPECT_THAT(execute(*instance_counter, 0, {20, 22}), Result(2)); EXPECT_THAT(execute(*instance_counter, 1, {20}), Result(1)); } @@ -888,7 +888,7 @@ TEST(execute, imported_two_functions_different_type) const auto module = parse(wasm); ASSERT_EQ(module->typesec.size(), 2); auto instance = - instantiate(module, {{host_foo1, module->typesec[0]}, {host_foo2, module->typesec[1]}}); + instantiate(*module, {{host_foo1, module->typesec[0]}, {host_foo2, module->typesec[1]}}); EXPECT_THAT(execute(*instance, 0, {20, 22}), Result(42)); EXPECT_THAT(execute(*instance, 1, {0x3000'0000}), Result(0x900'0000'0000'0000)); @@ -907,7 +907,7 @@ TEST(execute, imported_function_traps) }; const auto module = parse(wasm); - auto instance = instantiate(module, {{host_foo, module->typesec[0]}}); + auto instance = instantiate(*module, {{host_foo, module->typesec[0]}}); EXPECT_THAT(execute(*instance, 0, {20, 22}), Traps()); } @@ -942,7 +942,7 @@ TEST(execute, memory_copy_32bytes) "030837030820002001290310370310200020012903183703180b"); const auto module = parse(bin); - auto instance = instantiate(module); + auto instance = instantiate(*module); ASSERT_EQ(instance->memory->size(), 65536); const auto input = from_hex("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"); ASSERT_EQ(input.size(), 32); diff --git a/test/unittests/instantiate_test.cpp b/test/unittests/instantiate_test.cpp index 87165ab1c..1d794a587 100644 --- a/test/unittests/instantiate_test.cpp +++ b/test/unittests/instantiate_test.cpp @@ -32,7 +32,7 @@ TEST(instantiate, imported_functions) const auto module = parse(bin); auto host_foo = [](Instance&, span, int) { return Trap; }; - auto instance = instantiate(module, {{host_foo, module->typesec[0]}}); + auto instance = instantiate(*module, {{host_foo, module->typesec[0]}}); ASSERT_EQ(instance->imported_functions.size(), 1); EXPECT_EQ(*instance->imported_functions[0].function.target(), host_foo); @@ -55,7 +55,7 @@ TEST(instantiate, imported_functions_multiple) auto host_foo1 = [](Instance&, span, int) { return Trap; }; auto host_foo2 = [](Instance&, span, int) { return Trap; }; auto instance = - instantiate(module, {{host_foo1, module->typesec[0]}, {host_foo2, module->typesec[1]}}); + instantiate(*module, {{host_foo1, module->typesec[0]}, {host_foo2, module->typesec[1]}}); ASSERT_EQ(instance->imported_functions.size(), 2); EXPECT_EQ(*instance->imported_functions[0].function.target(), host_foo1); @@ -76,7 +76,7 @@ TEST(instantiate, imported_functions_not_enough) const auto bin = from_hex("0061736d0100000001060160017f017f020b01036d6f6403666f6f0000"); const auto module = parse(bin); - EXPECT_THROW_MESSAGE(instantiate(module, {}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}), instantiate_error, "module requires 1 imported functions, 0 provided"); } @@ -91,7 +91,7 @@ TEST(instantiate, imported_function_wrong_type) auto host_foo = [](Instance&, span, int) { return Trap; }; const auto host_foo_type = FuncType{{}, {}}; - EXPECT_THROW_MESSAGE(instantiate(module, {{host_foo, host_foo_type}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {{host_foo, host_foo_type}}), instantiate_error, "function 0 type doesn't match module's imported function type"); } @@ -104,7 +104,7 @@ TEST(instantiate, imported_table) const auto module = parse(bin); table_elements table(10); - auto instance = instantiate(module, {}, {{&table, {10, 30}}}); + auto instance = instantiate(*module, {}, {{&table, {10, 30}}}); ASSERT_TRUE(instance->table); EXPECT_EQ(instance->table->size(), 10); @@ -120,7 +120,7 @@ TEST(instantiate, imported_table_stricter_limits) const auto module = parse(bin); table_elements table(20); - auto instance = instantiate(module, {}, {{&table, {20, 20}}}); + auto instance = instantiate(*module, {}, {{&table, {20, 20}}}); ASSERT_TRUE(instance->table); EXPECT_EQ(instance->table->size(), 20); @@ -138,7 +138,7 @@ TEST(instantiate, imported_table_invalid) table_elements table(10); // Providing more than 1 table - EXPECT_THROW_MESSAGE(instantiate(module, {}, {{&table, {10, 30}}, {&table, {10, 10}}}), + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{&table, {10, 30}}, {&table, {10, 10}}}), instantiate_error, "only 1 imported table is allowed"); // Providing table when none expected @@ -147,37 +147,37 @@ TEST(instantiate, imported_table_invalid) */ const auto bin_no_imported_table = from_hex("0061736d01000000"); const auto module_no_imported_table = parse(bin_no_imported_table); - EXPECT_THROW_MESSAGE(instantiate(module_no_imported_table, {}, {{&table, {10, 30}}}), + EXPECT_THROW_MESSAGE(instantiate(*module_no_imported_table, {}, {{&table, {10, 30}}}), instantiate_error, "trying to provide imported table to a module that doesn't define one"); // Not providing table when one is expected - EXPECT_THROW_MESSAGE(instantiate(module), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module), instantiate_error, "module defines an imported table but none was provided"); // Provided min too low table_elements table_empty; - EXPECT_THROW_MESSAGE(instantiate(module, {}, {{&table_empty, {0, 3}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{&table_empty, {0, 3}}}), instantiate_error, "provided import's min is below import's min defined in module"); // Provided max too high - EXPECT_THROW_MESSAGE(instantiate(module, {}, {{&table, {10, 40}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{&table, {10, 40}}}), instantiate_error, "provided import's max is above import's max defined in module"); // Provided max is unlimited - EXPECT_THROW_MESSAGE(instantiate(module, {}, {{&table, {10, std::nullopt}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{&table, {10, std::nullopt}}}), instantiate_error, "provided import's max is above import's max defined in module"); // Null pointer - EXPECT_THROW_MESSAGE(instantiate(module, {}, {{nullptr, {10, 30}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{nullptr, {10, 30}}}), instantiate_error, "provided imported table has a null pointer to data"); // Allocated less than min - EXPECT_THROW_MESSAGE(instantiate(module, {}, {{&table_empty, {10, 30}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{&table_empty, {10, 30}}}), instantiate_error, "provided imported table doesn't fit provided limits"); // Allocated more than max table_elements table_big(40); - EXPECT_THROW_MESSAGE(instantiate(module, {}, {{&table_big, {10, 30}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{&table_big, {10, 30}}}), instantiate_error, "provided imported table doesn't fit provided limits"); } @@ -190,7 +190,7 @@ TEST(instantiate, imported_memory) const auto module = parse(bin); bytes memory(PageSize, 0); - auto instance = instantiate(module, {}, {}, {{&memory, {1, 3}}}); + auto instance = instantiate(*module, {}, {}, {{&memory, {1, 3}}}); ASSERT_TRUE(instance->memory); EXPECT_EQ(instance->memory->size(), PageSize); @@ -209,7 +209,7 @@ TEST(instantiate, imported_memory_unlimited) const auto module = parse(bin); bytes memory(PageSize, 0); - auto instance = instantiate(module, {}, {}, {{&memory, {1, std::nullopt}}}); + auto instance = instantiate(*module, {}, {}, {{&memory, {1, std::nullopt}}}); ASSERT_TRUE(instance->memory); EXPECT_EQ(instance->memory->size(), PageSize); @@ -227,7 +227,7 @@ TEST(instantiate, imported_memory_stricter_limits) const auto module = parse(bin); bytes memory(PageSize * 2, 0); - auto instance = instantiate(module, {}, {}, {{&memory, {2, 2}}}); + auto instance = instantiate(*module, {}, {}, {{&memory, {2, 2}}}); ASSERT_TRUE(instance->memory); EXPECT_EQ(instance->memory->size(), PageSize * 2); @@ -248,7 +248,7 @@ TEST(instantiate, imported_memory_invalid) bytes memory(PageSize, 0); // Providing more than 1 memory - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {{&memory, {1, 3}}, {&memory, {1, 1}}}), + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory, {1, 3}}, {&memory, {1, 1}}}), instantiate_error, "only 1 imported memory is allowed"); // Providing memory when none expected @@ -257,37 +257,37 @@ TEST(instantiate, imported_memory_invalid) */ const auto bin_no_imported_memory = from_hex("0061736d01000000"); const auto module_no_imported_memory = parse(bin_no_imported_memory); - EXPECT_THROW_MESSAGE(instantiate(module_no_imported_memory, {}, {}, {{&memory, {1, 3}}}), + EXPECT_THROW_MESSAGE(instantiate(*module_no_imported_memory, {}, {}, {{&memory, {1, 3}}}), instantiate_error, "trying to provide imported memory to a module that doesn't define one"); // Not providing memory when one is expected - EXPECT_THROW_MESSAGE(instantiate(module), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module), instantiate_error, "module defines an imported memory but none was provided"); // Provided min too low bytes memory_empty; - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {{&memory_empty, {0, 3}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory_empty, {0, 3}}}), instantiate_error, "provided import's min is below import's min defined in module"); // Provided max too high - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {{&memory, {1, 4}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory, {1, 4}}}), instantiate_error, "provided import's max is above import's max defined in module"); // Provided max is unlimited - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {{&memory, {1, std::nullopt}}}), + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory, {1, std::nullopt}}}), instantiate_error, "provided import's max is above import's max defined in module"); // Null pointer - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {{nullptr, {1, 3}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{nullptr, {1, 3}}}), instantiate_error, "provided imported memory has a null pointer to data"); // Allocated less than min - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {{&memory_empty, {1, 3}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory_empty, {1, 3}}}), instantiate_error, "provided imported memory doesn't fit provided limits"); // Allocated more than max bytes memory_big(PageSize * 4, 0); - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {{&memory_big, {1, 3}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory_big, {1, 3}}}), instantiate_error, "provided imported memory doesn't fit provided limits"); // Provided max exceeds the hard limit @@ -297,7 +297,7 @@ TEST(instantiate, imported_memory_invalid) const auto bin_without_max = from_hex("0061736d01000000020a01036d6f64016d020001"); const auto module_without_max = parse(bin_without_max); EXPECT_THROW_MESSAGE( - instantiate(module_without_max, {}, {}, {{&memory, {1, DefaultMemoryPagesLimit + 1}}}), + instantiate(*module_without_max, {}, {}, {{&memory, {1, DefaultMemoryPagesLimit + 1}}}), instantiate_error, "imported memory limits cannot exceed hard memory limit of 268435456 bytes"); } @@ -312,7 +312,7 @@ TEST(instantiate, imported_globals) Value global_value = 42; ExternalGlobal g{&global_value, {ValType::i32, true}}; - auto instance = instantiate(module, {}, {}, {}, {g}); + auto instance = instantiate(*module, {}, {}, {}, {g}); ASSERT_EQ(instance->imported_globals.size(), 1); EXPECT_EQ(instance->imported_globals[0].type.value_type, ValType::i32); @@ -334,7 +334,7 @@ TEST(instantiate, imported_globals_multiple) ExternalGlobal g1{&global_value1, {ValType::i32, true}}; Value global_value2 = 43; ExternalGlobal g2{&global_value2, {ValType::i32, false}}; - auto instance = instantiate(module, {}, {}, {}, {g1, g2}); + auto instance = instantiate(*module, {}, {}, {}, {g1, g2}); ASSERT_EQ(instance->imported_globals.size(), 2); EXPECT_EQ(instance->imported_globals[0].type.value_type, ValType::i32); @@ -357,7 +357,7 @@ TEST(instantiate, imported_globals_mismatched_count) Value global_value = 42; ExternalGlobal g{&global_value, {ValType::i32, true}}; - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {}, {g}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {}, {g}), instantiate_error, "module requires 2 imported globals, 1 provided"); } @@ -374,7 +374,7 @@ TEST(instantiate, imported_globals_mismatched_mutability) ExternalGlobal g1{&global_value1, {ValType::i32, false}}; Value global_value2 = 42; ExternalGlobal g2{&global_value2, {ValType::i32, true}}; - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {}, {g1, g2}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {}, {g1, g2}), instantiate_error, "global 0 mutability doesn't match module's global mutability"); } @@ -389,7 +389,7 @@ TEST(instantiate, imported_globals_mismatched_type) Value global_value = 42; ExternalGlobal g{&global_value, {ValType::i64, false}}; - EXPECT_THROW_MESSAGE(instantiate(module1, {}, {}, {}, {g}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module1, {}, {}, {}, {g}), instantiate_error, "global 0 value type doesn't match module's global type"); /* wat2wasm @@ -399,7 +399,7 @@ TEST(instantiate, imported_globals_mismatched_type) const auto bin2 = from_hex("0061736d01000000021502036d6f64026731037e00036d6f64026732037f00"); const auto module2 = parse(bin2); - EXPECT_THROW_MESSAGE(instantiate(module2, {}, {}, {}, {g, g}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module2, {}, {}, {}, {g, g}), instantiate_error, "global 1 value type doesn't match module's global type"); } @@ -420,7 +420,7 @@ TEST(instantiate, imported_global_from_another_module_mismatched_type) const auto bin2 = from_hex("0061736d01000000020b01036d6f64026731037f00"); const auto module2 = parse(bin2); - EXPECT_THROW_MESSAGE(instantiate(module2, {}, {}, {}, {*g}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module2, {}, {}, {}, {*g}), instantiate_error, "global 0 value type doesn't match module's global type"); } @@ -434,7 +434,7 @@ TEST(instantiate, imported_globals_nullptr) const auto module = parse(bin); ExternalGlobal g{nullptr, {ValType::i32, false}}; - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {}, {g, g}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {}, {g, g}), instantiate_error, "global 0 has a null pointer to value"); } @@ -442,7 +442,7 @@ TEST(instantiate, memory_default) { const auto module{std::make_unique()}; - auto instance = instantiate(module); + auto instance = instantiate(*module); EXPECT_FALSE(instance->memory); } @@ -452,7 +452,7 @@ TEST(instantiate, memory_single) const auto module{std::make_unique()}; module->memorysec.emplace_back(Memory{{1, 1}}); - auto instance = instantiate(module); + auto instance = instantiate(*module); ASSERT_EQ(instance->memory->size(), PageSize); EXPECT_EQ(instance->memory_limits.min, 1); @@ -465,7 +465,7 @@ TEST(instantiate, memory_single_unspecified_maximum) const auto module{std::make_unique()}; module->memorysec.emplace_back(Memory{{1, std::nullopt}}); - auto instance = instantiate(module); + auto instance = instantiate(*module); ASSERT_EQ(instance->memory->size(), PageSize); EXPECT_EQ(instance->memory_limits.min, 1); @@ -477,7 +477,7 @@ TEST(instantiate, memory_single_large_minimum) const auto module{std::make_unique()}; module->memorysec.emplace_back(Memory{{(1024 * 1024 * 1024) / PageSize, std::nullopt}}); - EXPECT_THROW_MESSAGE(instantiate(module), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module), instantiate_error, "cannot exceed hard memory limit of 268435456 bytes"); } @@ -486,7 +486,7 @@ TEST(instantiate, memory_single_large_maximum) const auto module{std::make_unique()}; module->memorysec.emplace_back(Memory{{1, (1024 * 1024 * 1024) / PageSize}}); - EXPECT_THROW_MESSAGE(instantiate(module), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module), instantiate_error, "cannot exceed hard memory limit of 268435456 bytes"); } @@ -498,13 +498,13 @@ TEST(instantiate, memory_single_custom_hard_limit) const auto bin = from_hex("0061736d01000000050401010204"); const auto module = parse(bin); - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {}, {}, 1), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {}, {}, 1), instantiate_error, "cannot exceed hard memory limit of 65536 bytes"); - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {}, {}, 3), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {}, {}, 3), instantiate_error, "cannot exceed hard memory limit of 196608 bytes"); - EXPECT_NO_THROW(instantiate(module, {}, {}, {}, {}, 4)); - EXPECT_NO_THROW(instantiate(module, {}, {}, {}, {}, 8)); + EXPECT_NO_THROW(instantiate(*module, {}, {}, {}, {}, 4)); + EXPECT_NO_THROW(instantiate(*module, {}, {}, {}, {}, 8)); } TEST(instantiate, imported_memory_custom_hard_limit) @@ -517,17 +517,17 @@ TEST(instantiate, imported_memory_custom_hard_limit) bytes memory(PageSize * 3, 0); - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {{&memory, {3, 4}}}, {}, 1), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory, {3, 4}}}, {}, 1), instantiate_error, "imported memory limits cannot exceed hard memory limit of 65536 bytes"); - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {{&memory, {3, 4}}}, {}, 2), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory, {3, 4}}}, {}, 2), instantiate_error, "imported memory limits cannot exceed hard memory limit of 131072 bytes"); - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {{&memory, {3, 4}}}, {}, 3), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory, {3, 4}}}, {}, 3), instantiate_error, "imported memory limits cannot exceed hard memory limit of 196608 bytes"); - EXPECT_NO_THROW(instantiate(module, {}, {}, {{&memory, {3, std::nullopt}}}, {}, 3)); - EXPECT_NO_THROW(instantiate(module, {}, {}, {{&memory, {3, std::nullopt}}}, {}, 4)); - EXPECT_NO_THROW(instantiate(module, {}, {}, {{&memory, {3, 4}}}, {}, 4)); - EXPECT_NO_THROW(instantiate(module, {}, {}, {{&memory, {3, 4}}}, {}, 8)); + EXPECT_NO_THROW(instantiate(*module, {}, {}, {{&memory, {3, std::nullopt}}}, {}, 3)); + EXPECT_NO_THROW(instantiate(*module, {}, {}, {{&memory, {3, std::nullopt}}}, {}, 4)); + EXPECT_NO_THROW(instantiate(*module, {}, {}, {{&memory, {3, 4}}}, {}, 4)); + EXPECT_NO_THROW(instantiate(*module, {}, {}, {{&memory, {3, 4}}}, {}, 8)); /* wat2wasm (memory (import "mod" "mem") 2 6) @@ -535,18 +535,18 @@ TEST(instantiate, imported_memory_custom_hard_limit) const auto bin_max_limit = from_hex("0061736d01000000020d01036d6f64036d656d02010206"); const auto module_max_limit = parse(bin_max_limit); - EXPECT_THROW_MESSAGE(instantiate(module_max_limit, {}, {}, {{&memory, {3, 4}}}, {}, 1), + EXPECT_THROW_MESSAGE(instantiate(*module_max_limit, {}, {}, {{&memory, {3, 4}}}, {}, 1), instantiate_error, "imported memory limits cannot exceed hard memory limit of 65536 bytes"); - EXPECT_THROW_MESSAGE(instantiate(module_max_limit, {}, {}, {{&memory, {3, 4}}}, {}, 2), + EXPECT_THROW_MESSAGE(instantiate(*module_max_limit, {}, {}, {{&memory, {3, 4}}}, {}, 2), instantiate_error, "imported memory limits cannot exceed hard memory limit of 131072 bytes"); - EXPECT_THROW_MESSAGE(instantiate(module_max_limit, {}, {}, {{&memory, {3, 4}}}, {}, 3), + EXPECT_THROW_MESSAGE(instantiate(*module_max_limit, {}, {}, {{&memory, {3, 4}}}, {}, 3), instantiate_error, "imported memory limits cannot exceed hard memory limit of 196608 bytes"); - EXPECT_NO_THROW(instantiate(module_max_limit, {}, {}, {{&memory, {3, 4}}}, {}, 4)); - EXPECT_NO_THROW(instantiate(module_max_limit, {}, {}, {{&memory, {3, 6}}}, {}, 6)); - EXPECT_NO_THROW(instantiate(module_max_limit, {}, {}, {{&memory, {3, 6}}}, {}, 8)); + EXPECT_NO_THROW(instantiate(*module_max_limit, {}, {}, {{&memory, {3, 4}}}, {}, 4)); + EXPECT_NO_THROW(instantiate(*module_max_limit, {}, {}, {{&memory, {3, 6}}}, {}, 6)); + EXPECT_NO_THROW(instantiate(*module_max_limit, {}, {}, {{&memory, {3, 6}}}, {}, 8)); } TEST(instantiate, element_section) @@ -634,7 +634,7 @@ TEST(instantiate, element_section_offset_too_large) Element{{ConstantExpression::Kind::Constant, {2}}, {0x55, 0x55}}); EXPECT_THROW_MESSAGE( - instantiate(module), instantiate_error, "element segment is out of table bounds"); + instantiate(*module), instantiate_error, "element segment is out of table bounds"); } TEST(instantiate, element_section_fills_imported_table) @@ -687,7 +687,7 @@ TEST(instantiate, element_section_out_of_bounds_doesnt_change_imported_table) table_elements table(3); table[0] = ExternalFunction{f0, FuncType{{}, {ValType::i32}}}; - EXPECT_THROW_MESSAGE(instantiate(module, {}, {{&table, {3, std::nullopt}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {{&table, {3, std::nullopt}}}), instantiate_error, "element segment is out of table bounds"); ASSERT_EQ(table.size(), 3); @@ -705,7 +705,7 @@ TEST(instantiate, data_section) // Memory contents: 0, 0xaa, 0x55, 0x55, 0, ... module->datasec.emplace_back(Data{{ConstantExpression::Kind::Constant, {2}}, {0x55, 0x55}}); - auto instance = instantiate(module); + auto instance = instantiate(*module); EXPECT_EQ(instance->memory->substr(0, 6), from_hex("00aa55550000")); } @@ -719,7 +719,7 @@ TEST(instantiate, data_section_offset_from_global) // Memory contents: 0, 0xaa, 0xff, 0, ... module->datasec.emplace_back(Data{{ConstantExpression::Kind::GlobalGet, {0}}, {0xaa, 0xff}}); - auto instance = instantiate(module); + auto instance = instantiate(*module); EXPECT_EQ(instance->memory->substr(42, 2), "aaff"_bytes); } @@ -738,7 +738,7 @@ TEST(instantiate, data_section_offset_from_imported_global) Value global_value = 42; ExternalGlobal g{&global_value, {ValType::i32, false}}; - auto instance = instantiate(module, {}, {}, {}, {g}); + auto instance = instantiate(*module, {}, {}, {}, {g}); EXPECT_EQ(instance->memory->substr(42, 2), "aaff"_bytes); } @@ -751,7 +751,7 @@ TEST(instantiate, data_section_offset_too_large) module->datasec.emplace_back(Data{{ConstantExpression::Kind::Constant, {1}}, {0xaa, 0xff}}); EXPECT_THROW_MESSAGE( - instantiate(module), instantiate_error, "data segment is out of memory bounds"); + instantiate(*module), instantiate_error, "data segment is out of memory bounds"); } TEST(instantiate, data_section_fills_imported_memory) @@ -766,7 +766,7 @@ TEST(instantiate, data_section_fills_imported_memory) const auto module = parse(bin); bytes memory(PageSize, 0); - auto instance = instantiate(module, {}, {}, {{&memory, {1, 1}}}); + auto instance = instantiate(*module, {}, {}, {{&memory, {1, 1}}}); EXPECT_EQ(memory.substr(0, 6), from_hex("00aa55550000")); } @@ -785,7 +785,7 @@ TEST(instantiate, data_section_out_of_bounds_doesnt_change_imported_memory) const auto module = parse(bin); bytes memory(PageSize, 0); - EXPECT_THROW_MESSAGE(instantiate(module, {}, {}, {{&memory, {1, 1}}}), instantiate_error, + EXPECT_THROW_MESSAGE(instantiate(*module, {}, {}, {{&memory, {1, 1}}}), instantiate_error, "data segment is out of memory bounds"); EXPECT_EQ(memory[0], 0); @@ -811,7 +811,7 @@ TEST(instantiate, data_elem_section_errors_dont_change_imports) table_elements table(3); bytes memory(PageSize, 0); EXPECT_THROW_MESSAGE( - instantiate(module_data_error, {}, {{&table, {3, std::nullopt}}}, {{&memory, {1, 1}}}), + instantiate(*module_data_error, {}, {{&table, {3, std::nullopt}}}, {{&memory, {1, 1}}}), instantiate_error, "data segment is out of memory bounds"); EXPECT_FALSE(table[0].has_value()); @@ -834,7 +834,7 @@ TEST(instantiate, data_elem_section_errors_dont_change_imports) const auto module_elem_error = parse(bin_elem_error); EXPECT_THROW_MESSAGE( - instantiate(module_elem_error, {}, {{&table, {3, std::nullopt}}}, {{&memory, {1, 1}}}), + instantiate(*module_elem_error, {}, {{&table, {3, std::nullopt}}}, {{&memory, {1, 1}}}), instantiate_error, "element segment is out of table bounds"); EXPECT_FALSE(table[0].has_value()); @@ -849,7 +849,7 @@ TEST(instantiate, globals_single) module->globalsec.emplace_back( Global{{ValType::i32, true}, {ConstantExpression::Kind::Constant, {42}}}); - auto instance = instantiate(module); + auto instance = instantiate(*module); ASSERT_EQ(instance->globals.size(), 1); EXPECT_EQ(as_uint32(instance->globals[0]), 42); @@ -863,7 +863,7 @@ TEST(instantiate, globals_multiple) module->globalsec.emplace_back( Global{{ValType::i32, false}, {ConstantExpression::Kind::Constant, {43}}}); - auto instance = instantiate(module); + auto instance = instantiate(*module); ASSERT_EQ(instance->globals.size(), 2); EXPECT_EQ(as_uint32(instance->globals[0]), 42); @@ -884,7 +884,7 @@ TEST(instantiate, globals_with_imported) Value global_value = 41; ExternalGlobal g{&global_value, {ValType::i32, true}}; - auto instance = instantiate(module, {}, {}, {}, {g}); + auto instance = instantiate(*module, {}, {}, {}, {g}); ASSERT_EQ(instance->imported_globals.size(), 1); EXPECT_EQ(as_uint32(*instance->imported_globals[0].value), 41); @@ -906,7 +906,7 @@ TEST(instantiate, globals_initialized_from_imported) Value global_value = 42; ExternalGlobal g{&global_value, {ValType::i32, false}}; - auto instance = instantiate(module, {}, {}, {}, {g}); + auto instance = instantiate(*module, {}, {}, {}, {g}); ASSERT_EQ(instance->globals.size(), 1); EXPECT_EQ(as_uint32(instance->globals[0]), 42); @@ -931,7 +931,7 @@ TEST(instantiate, globals_float) Value global_value2 = 7.8; ExternalGlobal g2{&global_value2, {ValType::f64, false}}; - auto instance = instantiate(module, {}, {}, {}, {g1, g2}); + auto instance = instantiate(*module, {}, {}, {}, {g1, g2}); ASSERT_EQ(instance->imported_globals.size(), 2); EXPECT_EQ(instance->imported_globals[0].value->f32, 5.6f); diff --git a/test/utils/execute_helpers.hpp b/test/utils/execute_helpers.hpp index 7c69bdf89..c02889caa 100644 --- a/test/utils/execute_helpers.hpp +++ b/test/utils/execute_helpers.hpp @@ -12,7 +12,7 @@ namespace fizzy::test inline ExecutionResult execute( const std::unique_ptr& module, FuncIdx func_idx, std::initializer_list args) { - auto instance = instantiate(module); + auto instance = instantiate(*module); return execute(*instance, func_idx, args); } } // namespace fizzy::test