Skip to content

Commit

Permalink
[Fix] Avoid panic due to new types introduced by GC
Browse files Browse the repository at this point in the history
Signed-off-by: csh <[email protected]>
  • Loading branch information
L-jasmine committed May 27, 2024
1 parent f81ecc3 commit 2f16a58
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions crates/wasmedge-sys/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,18 @@ impl From<ffi::WasmEdge_ValType> 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
}
}
}
Expand All @@ -406,6 +408,8 @@ impl From<ValType> 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(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/wasmedge-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ impl From<WasmValue> for Val {
Val::ExternRef(Some(ExternRef { inner: value }))
}
}
wasmedge_types::ValType::UnsupportedRef => {
// Waiting for more GC-related C APIs.
Val::ExternRef(None)
}
}
}
}
Expand Down

0 comments on commit 2f16a58

Please sign in to comment.