From 2f16a58419dd140cc38aa4568bfa65381815738b Mon Sep 17 00:00:00 2001 From: csh <458761603@qq.com> Date: Mon, 27 May 2024 21:44:08 +0800 Subject: [PATCH] [Fix] Avoid panic due to new types introduced by GC Signed-off-by: csh <458761603@qq.com> --- crates/wasmedge-sys/src/types.rs | 12 ++++++++---- crates/wasmedge-types/src/lib.rs | 2 ++ src/types.rs | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/wasmedge-sys/src/types.rs b/crates/wasmedge-sys/src/types.rs index 5ec59e272..b00df8659 100644 --- a/crates/wasmedge-sys/src/types.rs +++ b/crates/wasmedge-sys/src/types.rs @@ -381,16 +381,18 @@ impl From for ValType { } else if ffi::WasmEdge_ValTypeIsExternRef(value) { ValType::ExternRef } else { - panic!( + log::warn!( "capi unsupport WasmEdge_RefType `{:x}`", u64::from_be_bytes(value.Data) - ) + ); + ValType::UnsupportedRef } } else { - panic!( + log::warn!( "unknown WasmEdge_ValType `{:x}`", u64::from_be_bytes(value.Data) - ) + ); + ValType::UnsupportedRef } } } @@ -406,6 +408,8 @@ impl From for ffi::WasmEdge_ValType { ValType::V128 => ffi::WasmEdge_ValTypeGenV128(), ValType::FuncRef => ffi::WasmEdge_ValTypeGenFuncRef(), ValType::ExternRef => ffi::WasmEdge_ValTypeGenExternRef(), + // C API is temporarily unsupported. + ValType::UnsupportedRef => ffi::WasmEdge_ValTypeGenExternRef(), } } } diff --git a/crates/wasmedge-types/src/lib.rs b/crates/wasmedge-types/src/lib.rs index b7077fe9c..7b99274ca 100644 --- a/crates/wasmedge-types/src/lib.rs +++ b/crates/wasmedge-types/src/lib.rs @@ -64,6 +64,8 @@ pub enum ValType { FuncRef, /// A reference to object. ExternRef, + /// A reference that unsupported by c-api. + UnsupportedRef, } /// Defines the mutability property of WasmEdge Global variables. diff --git a/src/types.rs b/src/types.rs index a44398db7..0ec9615eb 100644 --- a/src/types.rs +++ b/src/types.rs @@ -67,6 +67,10 @@ impl From for Val { Val::ExternRef(Some(ExternRef { inner: value })) } } + wasmedge_types::ValType::UnsupportedRef => { + // Waiting for more GC-related C APIs. + Val::ExternRef(None) + } } } }