diff --git a/lib/fizzy/instantiate.cpp b/lib/fizzy/instantiate.cpp index e782838710..8233072146 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*/) diff --git a/lib/fizzy/instantiate.hpp b/lib/fizzy/instantiate.hpp index 5673bda7b6..89a18170b8 100644 --- a/lib/fizzy/instantiate.hpp +++ b/lib/fizzy/instantiate.hpp @@ -54,7 +54,7 @@ using bytes_ptr = std::unique_ptr; // The module instance. struct Instance { - std::unique_ptr module; + std::unique_ptr module; // Memory is either allocated and owned by the instance or imported as already allocated bytes // and owned externally. // For these cases unique_ptr would either have a normal deleter or noop deleter respectively @@ -70,7 +70,7 @@ struct Instance std::vector imported_functions; std::vector imported_globals; - Instance(std::unique_ptr _module, bytes_ptr _memory, Limits _memory_limits, + Instance(std::unique_ptr _module, bytes_ptr _memory, Limits _memory_limits, uint32_t _memory_pages_limit, table_ptr _table, Limits _table_limits, std::vector _globals, std::vector _imported_functions, std::vector _imported_globals) @@ -87,7 +87,7 @@ struct Instance }; // Instantiate a module. -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 = {}, diff --git a/lib/fizzy/parser.cpp b/lib/fizzy/parser.cpp index e25d55c448..f7b14f4b67 100644 --- a/lib/fizzy/parser.cpp +++ b/lib/fizzy/parser.cpp @@ -430,7 +430,7 @@ inline parser_result parse(const uint8_t* pos, const uint8_t* end) return {{offset, std::move(init)}, pos}; } -std::unique_ptr parse(bytes_view input) +std::unique_ptr parse(bytes_view input) { if (input.substr(0, wasm_prefix.size()) != wasm_prefix) throw parser_error{"invalid wasm module prefix"}; @@ -658,7 +658,7 @@ std::unique_ptr parse(bytes_view input) module->codesec.emplace_back( parse_code(code_binaries[i], static_cast(i), *module)); - return module; + return std::unique_ptr(module.release()); } parser_result> parse_vec_i32(const uint8_t* pos, const uint8_t* end) diff --git a/lib/fizzy/parser.hpp b/lib/fizzy/parser.hpp index 8841265fd1..118c265c71 100644 --- a/lib/fizzy/parser.hpp +++ b/lib/fizzy/parser.hpp @@ -17,7 +17,7 @@ constexpr bytes_view wasm_prefix{wasm_prefix_data, sizeof(wasm_prefix_data)}; template using parser_result = std::pair; -std::unique_ptr parse(bytes_view input); +std::unique_ptr parse(bytes_view input); inline parser_result parse_byte(const uint8_t* pos, const uint8_t* end) { diff --git a/test/unittests/execute_numeric_test.cpp b/test/unittests/execute_numeric_test.cpp index 2288896ba4..00ebc898ec 100644 --- a/test/unittests/execute_numeric_test.cpp +++ b/test/unittests/execute_numeric_test.cpp @@ -16,25 +16,25 @@ namespace { ExecutionResult execute_unary_operation(Instr instr, uint64_t arg) { - const auto module{std::make_unique()}; + auto module{std::make_unique()}; // type is currently needed only to get arity of function, so exact value types don't matter module->typesec.emplace_back(FuncType{{ValType::i32}, {ValType::i32}}); module->funcsec.emplace_back(TypeIdx{0}); module->codesec.emplace_back(Code{1, 0, {Instr::local_get, instr, Instr::end}, {0, 0, 0, 0}}); - return execute(module, 0, {arg}); + return execute(*instantiate(std::move(module)), 0, {arg}); } ExecutionResult execute_binary_operation(Instr instr, uint64_t lhs, uint64_t rhs) { - const auto module{std::make_unique()}; + auto module{std::make_unique()}; // type is currently needed only to get arity of function, so exact value types don't matter module->typesec.emplace_back(FuncType{{ValType::i32, ValType::i32}, {ValType::i32}}); module->funcsec.emplace_back(TypeIdx{0}); module->codesec.emplace_back(Code{ 2, 0, {Instr::local_get, Instr::local_get, instr, Instr::end}, {0, 0, 0, 0, 1, 0, 0, 0}}); - return execute(module, 0, {lhs, rhs}); + return execute(*instantiate(std::move(module)), 0, {lhs, rhs}); } } // namespace diff --git a/test/unittests/execute_test.cpp b/test/unittests/execute_test.cpp index 126914a695..b375232920 100644 --- a/test/unittests/execute_test.cpp +++ b/test/unittests/execute_test.cpp @@ -380,7 +380,7 @@ TEST(execute, i32_load_all_variants) from_hex("0061736d0100000001060160017f017f030201000504010101010a0901070020002802000b"); const auto module = parse(wasm); - auto& load_instr = module->codesec[0].instructions[1]; + auto& load_instr = const_cast(module->codesec[0].instructions[1]); ASSERT_EQ(load_instr, Instr::i32_load); ASSERT_EQ(module->codesec[0].immediates.substr(4), "00000000"_bytes); // load offset. @@ -418,7 +418,7 @@ TEST(execute, i64_load_all_variants) from_hex("0061736d0100000001060160017f017e030201000504010101010a0901070020002903000b"); const auto module = parse(wasm); - auto& load_instr = module->codesec[0].instructions[1]; + auto& load_instr = const_cast(module->codesec[0].instructions[1]); ASSERT_EQ(load_instr, Instr::i64_load); ASSERT_EQ(module->codesec[0].immediates.substr(4), "00000000"_bytes); // load offset. @@ -529,7 +529,7 @@ TEST(execute, i32_store_all_variants) from_hex("0061736d0100000001060160027f7f00030201000504010101010a0b010900200120003602000b"); const auto module = parse(wasm); - auto& store_instr = module->codesec[0].instructions[2]; + auto& store_instr = const_cast(module->codesec[0].instructions[2]); ASSERT_EQ(store_instr, Instr::i32_store); ASSERT_EQ(module->codesec[0].immediates.substr(8), "00000000"_bytes); // store offset @@ -565,7 +565,7 @@ TEST(execute, i64_store_all_variants) from_hex("0061736d0100000001060160027e7f00030201000504010101010a0b010900200120003703000b"); const auto module = parse(wasm); - auto& store_instr = module->codesec[0].instructions[2]; + auto& store_instr = const_cast(module->codesec[0].instructions[2]); ASSERT_EQ(store_instr, Instr::i64_store); ASSERT_EQ(module->codesec[0].immediates.substr(8), "00000000"_bytes); // store offset diff --git a/test/utils/execute_helpers.hpp b/test/utils/execute_helpers.hpp index 0d235f92ed..0a76374c2d 100644 --- a/test/utils/execute_helpers.hpp +++ b/test/utils/execute_helpers.hpp @@ -10,8 +10,8 @@ namespace fizzy::test { -inline ExecutionResult execute( - const std::unique_ptr& module, FuncIdx func_idx, std::initializer_list args) +inline ExecutionResult execute(const std::unique_ptr& module, FuncIdx func_idx, + std::initializer_list args) { auto instance = instantiate(*module); return execute(*instance, func_idx, args);