Remove HostRef<T> from the C API (#1926)
This commit removes `HostRef<T>` from the C API which only served the purpose now of converting each type to a `wasm_ref_t*`. Our implementation, however, does not guarantee that you'll get the same `wasm_ref_t*` for each actual underlying item (e.g. if you put a func in a table and then get the func as an export and from the table then `same` will report `false`). Additionally the fate of `wasm_ref_t*` seems somewhat unclear at this point. The change here is to make the `same` and cast functions all abort saying they're unimplemented. (similar to the host info functions). If and when we get around to reimplementing these functions we can ensure they're implemented uniformly and work well for all intended use cases.
This commit is contained in:
@@ -1,53 +1,27 @@
|
||||
use crate::host_ref::HostRef;
|
||||
use crate::wasm_externkind_t;
|
||||
use crate::{wasm_externtype_t, wasm_func_t, wasm_global_t, wasm_memory_t, wasm_table_t};
|
||||
use wasmtime::{ExternType, Func, Global, Memory, Table};
|
||||
use wasmtime::Extern;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct wasm_extern_t {
|
||||
pub(crate) which: ExternHost,
|
||||
pub(crate) which: Extern,
|
||||
}
|
||||
|
||||
wasmtime_c_api_macros::declare_ref!(wasm_extern_t);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) enum ExternHost {
|
||||
Func(HostRef<Func>),
|
||||
Global(HostRef<Global>),
|
||||
Memory(HostRef<Memory>),
|
||||
Table(HostRef<Table>),
|
||||
}
|
||||
|
||||
impl wasm_extern_t {
|
||||
pub(crate) fn externref(&self) -> wasmtime::ExternRef {
|
||||
match &self.which {
|
||||
ExternHost::Func(f) => f.clone().into(),
|
||||
ExternHost::Global(f) => f.clone().into(),
|
||||
ExternHost::Memory(f) => f.clone().into(),
|
||||
ExternHost::Table(f) => f.clone().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_extern_kind(e: &wasm_extern_t) -> wasm_externkind_t {
|
||||
match e.which {
|
||||
ExternHost::Func(_) => crate::WASM_EXTERN_FUNC,
|
||||
ExternHost::Global(_) => crate::WASM_EXTERN_GLOBAL,
|
||||
ExternHost::Table(_) => crate::WASM_EXTERN_TABLE,
|
||||
ExternHost::Memory(_) => crate::WASM_EXTERN_MEMORY,
|
||||
Extern::Func(_) => crate::WASM_EXTERN_FUNC,
|
||||
Extern::Global(_) => crate::WASM_EXTERN_GLOBAL,
|
||||
Extern::Table(_) => crate::WASM_EXTERN_TABLE,
|
||||
Extern::Memory(_) => crate::WASM_EXTERN_MEMORY,
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_extern_type(e: &wasm_extern_t) -> Box<wasm_externtype_t> {
|
||||
let ty = match &e.which {
|
||||
ExternHost::Func(f) => ExternType::Func(f.borrow().ty()),
|
||||
ExternHost::Global(f) => ExternType::Global(f.borrow().ty()),
|
||||
ExternHost::Table(f) => ExternType::Table(f.borrow().ty()),
|
||||
ExternHost::Memory(f) => ExternType::Memory(f.borrow().ty()),
|
||||
};
|
||||
Box::new(wasm_externtype_t::new(ty))
|
||||
Box::new(wasm_externtype_t::new(e.which.ty()))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
Reference in New Issue
Block a user