A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Fix some more mistakes in the C++ API (#15098)
Alex Crichton11722fb6adcb
diff --git a/crates/c-api/include/wasmtime/types/_val_class.hh b/crates/c-api/include/wasmtime/types/_val_class.hhindex 210b1409e3..d26b6d2233 100644--- a/crates/c-api/include/wasmtime/types/_val_class.hh+++ b/crates/c-api/include/wasmtime/types/_val_class.hh@@ -110,9 +110,11 @@ public:ValType &operator=(ValType &&other) {ptr = std::move(other.ptr);ref = ptr.get();+ wasmtime_valtype_t old = wasmtime_ty;wasmtime_ty = other.wasmtime_ty;other.ref = nullptr;other.wasmtime_ty.kind = WASMTIME_VALTYPE_KIND_I32;+ wasmtime_valtype_delete(&old);return *this;}diff --git a/crates/c-api/include/wasmtime/types/func.hh b/crates/c-api/include/wasmtime/types/func.hhindex 1425b0800f..ed3d79db75 100644--- a/crates/c-api/include/wasmtime/types/func.hh+++ b/crates/c-api/include/wasmtime/types/func.hh@@ -63,6 +63,7 @@ public:/// Copies another type's information into this one.FuncType &operator=(const FuncType &other) {ptr.reset(wasm_functype_copy(other.ptr.get()));+ ref = ptr.get();return *this;}~FuncType() = default;diff --git a/crates/c-api/include/wasmtime/types/global.hh b/crates/c-api/include/wasmtime/types/global.hhindex d10e0e46d4..728dacae92 100644--- a/crates/c-api/include/wasmtime/types/global.hh+++ b/crates/c-api/include/wasmtime/types/global.hh@@ -61,6 +61,7 @@ public:/// Copies other type information into this one.GlobalType &operator=(const GlobalType &other) {ptr.reset(wasm_globaltype_copy(other.ptr.get()));+ ref = ptr.get();return *this;}~GlobalType() = default;diff --git a/crates/c-api/include/wasmtime/types/memory.hh b/crates/c-api/include/wasmtime/types/memory.hhindex 3d08b9f685..4de2e4896b 100644--- a/crates/c-api/include/wasmtime/types/memory.hh+++ b/crates/c-api/include/wasmtime/types/memory.hh@@ -129,6 +129,7 @@ public:/// Copies the provided type into a new type.MemoryType &operator=(const MemoryType &other) {ptr.reset(wasm_memorytype_copy(other.ptr.get()));+ ref = ptr.get();return *this;}~MemoryType() = default;diff --git a/crates/c-api/include/wasmtime/types/table.hh b/crates/c-api/include/wasmtime/types/table.hhindex dd898bc5ab..8a8561e0c8 100644--- a/crates/c-api/include/wasmtime/types/table.hh+++ b/crates/c-api/include/wasmtime/types/table.hh@@ -88,6 +88,7 @@ public:/// Copies another table type into this one.TableType &operator=(const TableType &other) {ptr.reset(wasm_tabletype_copy(other.ptr.get()));+ ref = ptr.get();return *this;}~TableType() = default;diff --git a/crates/c-api/tests/func_type.cc b/crates/c-api/tests/func_type.ccindex b26abba650..526ef268ee 100644--- a/crates/c-api/tests/func_type.cc+++ b/crates/c-api/tests/func_type.cc@@ -12,6 +12,10 @@ TEST(FuncType, Smoke) {auto other = t;other = t;+ FuncType assigned({ValType::i32()}, {});+ assigned = t;+ EXPECT_EQ(assigned->params().size(), 0);+FuncType t2({ValType::i32()}, {ValType::i64()});EXPECT_EQ(t2->params().size(), 1);for (auto ty : t2->params()) {diff --git a/crates/c-api/tests/global_type.cc b/crates/c-api/tests/global_type.ccindex a9d5642c1a..0c045e275b 100644--- a/crates/c-api/tests/global_type.cc+++ b/crates/c-api/tests/global_type.cc@@ -12,4 +12,8 @@ TEST(GlobalType, Simple) {ty = GlobalType(ValType::v128(), true);EXPECT_TRUE(ty->is_mutable());EXPECT_EQ(ty->content(), ValType::v128());++ GlobalType other(ValType::i32(), false);+ other = ty;+ EXPECT_TRUE(other->is_mutable());}diff --git a/crates/c-api/tests/memory_type.cc b/crates/c-api/tests/memory_type.ccindex 173c8cabc0..5d030c88e2 100644--- a/crates/c-api/tests/memory_type.cc+++ b/crates/c-api/tests/memory_type.cc@@ -21,6 +21,10 @@ TEST(MemoryType, WithMax) {EXPECT_FALSE(ty->is_shared());EXPECT_EQ(ty->page_size_log2(), 16);EXPECT_EQ(ty->page_size(), 1 << 16);++ MemoryType other(3);+ other = ty;+ EXPECT_EQ(other->min(), 1);}TEST(MemoryType, Mem64) {diff --git a/crates/c-api/tests/table_type.cc b/crates/c-api/tests/table_type.ccindex 83c8b2c0d5..693af69b88 100644--- a/crates/c-api/tests/table_type.cc+++ b/crates/c-api/tests/table_type.cc@@ -16,6 +16,10 @@ TEST(TableType, Simple) {EXPECT_EQ(ty->min(), 2);EXPECT_EQ(ty->max(), 3);EXPECT_EQ(ty->element(), ValType::externref());++ TableType other(ValType::funcref(), 1);+ other = ty;+ EXPECT_EQ(other->min(), 2);}TEST(TableType, Table64) {