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,4 +1,3 @@
|
||||
use crate::host_ref::HostRef;
|
||||
use crate::{wasm_frame_vec_t, wasm_instance_t, wasm_name_t, wasm_store_t};
|
||||
use once_cell::unsync::OnceCell;
|
||||
use wasmtime::Trap;
|
||||
@@ -6,27 +5,21 @@ use wasmtime::Trap;
|
||||
#[repr(C)]
|
||||
#[derive(Clone)]
|
||||
pub struct wasm_trap_t {
|
||||
pub(crate) trap: HostRef<Trap>,
|
||||
pub(crate) trap: Trap,
|
||||
}
|
||||
|
||||
wasmtime_c_api_macros::declare_ref!(wasm_trap_t);
|
||||
|
||||
impl wasm_trap_t {
|
||||
pub(crate) fn new(trap: Trap) -> wasm_trap_t {
|
||||
wasm_trap_t {
|
||||
trap: HostRef::new(trap),
|
||||
}
|
||||
}
|
||||
|
||||
fn externref(&self) -> wasmtime::ExternRef {
|
||||
self.trap.clone().into()
|
||||
wasm_trap_t { trap: trap }
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone)]
|
||||
pub struct wasm_frame_t {
|
||||
trap: HostRef<Trap>,
|
||||
trap: Trap,
|
||||
idx: usize,
|
||||
func_name: OnceCell<Option<wasm_name_t>>,
|
||||
module_name: OnceCell<Option<wasm_name_t>>,
|
||||
@@ -47,14 +40,14 @@ pub extern "C" fn wasm_trap_new(
|
||||
}
|
||||
let message = String::from_utf8_lossy(&message[..message.len() - 1]);
|
||||
Box::new(wasm_trap_t {
|
||||
trap: HostRef::new(Trap::new(message)),
|
||||
trap: Trap::new(message),
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_trap_message(trap: &wasm_trap_t, out: &mut wasm_message_t) {
|
||||
let mut buffer = Vec::new();
|
||||
buffer.extend_from_slice(trap.trap.borrow().to_string().as_bytes());
|
||||
buffer.extend_from_slice(trap.trap.to_string().as_bytes());
|
||||
buffer.reserve_exact(1);
|
||||
buffer.push(0);
|
||||
out.set_buffer(buffer);
|
||||
@@ -62,8 +55,7 @@ pub extern "C" fn wasm_trap_message(trap: &wasm_trap_t, out: &mut wasm_message_t
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_trap_origin(raw: &wasm_trap_t) -> Option<Box<wasm_frame_t>> {
|
||||
let trap = raw.trap.borrow();
|
||||
if trap.trace().len() > 0 {
|
||||
if raw.trap.trace().len() > 0 {
|
||||
Some(Box::new(wasm_frame_t {
|
||||
trap: raw.trap.clone(),
|
||||
idx: 0,
|
||||
@@ -77,8 +69,7 @@ pub extern "C" fn wasm_trap_origin(raw: &wasm_trap_t) -> Option<Box<wasm_frame_t
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_trap_trace(raw: &wasm_trap_t, out: &mut wasm_frame_vec_t) {
|
||||
let trap = raw.trap.borrow();
|
||||
let vec = (0..trap.trace().len())
|
||||
let vec = (0..raw.trap.trace().len())
|
||||
.map(|idx| {
|
||||
Some(Box::new(wasm_frame_t {
|
||||
trap: raw.trap.clone(),
|
||||
@@ -93,8 +84,7 @@ pub extern "C" fn wasm_trap_trace(raw: &wasm_trap_t, out: &mut wasm_frame_vec_t)
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmtime_trap_exit_status(raw: &wasm_trap_t, status: &mut i32) -> bool {
|
||||
let trap = raw.trap.borrow();
|
||||
match trap.i32_exit_status() {
|
||||
match raw.trap.i32_exit_status() {
|
||||
Some(i) => {
|
||||
*status = i;
|
||||
true
|
||||
@@ -105,7 +95,7 @@ pub extern "C" fn wasmtime_trap_exit_status(raw: &wasm_trap_t, status: &mut i32)
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_frame_func_index(frame: &wasm_frame_t) -> u32 {
|
||||
frame.trap.borrow().trace()[frame.idx].func_index()
|
||||
frame.trap.trace()[frame.idx].func_index()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -113,8 +103,7 @@ pub extern "C" fn wasmtime_frame_func_name(frame: &wasm_frame_t) -> Option<&wasm
|
||||
frame
|
||||
.func_name
|
||||
.get_or_init(|| {
|
||||
let trap = frame.trap.borrow();
|
||||
trap.trace()[frame.idx]
|
||||
frame.trap.trace()[frame.idx]
|
||||
.func_name()
|
||||
.map(|s| wasm_name_t::from(s.to_string().into_bytes()))
|
||||
})
|
||||
@@ -126,8 +115,7 @@ pub extern "C" fn wasmtime_frame_module_name(frame: &wasm_frame_t) -> Option<&wa
|
||||
frame
|
||||
.module_name
|
||||
.get_or_init(|| {
|
||||
let trap = frame.trap.borrow();
|
||||
trap.trace()[frame.idx]
|
||||
frame.trap.trace()[frame.idx]
|
||||
.module_name()
|
||||
.map(|s| wasm_name_t::from(s.to_string().into_bytes()))
|
||||
})
|
||||
@@ -136,8 +124,7 @@ pub extern "C" fn wasmtime_frame_module_name(frame: &wasm_frame_t) -> Option<&wa
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_frame_func_offset(frame: &wasm_frame_t) -> usize {
|
||||
let trap = frame.trap.borrow();
|
||||
trap.trace()[frame.idx].func_offset()
|
||||
frame.trap.trace()[frame.idx].func_offset()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -147,6 +134,5 @@ pub extern "C" fn wasm_frame_instance(_arg1: *const wasm_frame_t) -> *mut wasm_i
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_frame_module_offset(frame: &wasm_frame_t) -> usize {
|
||||
let trap = frame.trap.borrow();
|
||||
trap.trace()[frame.idx].module_offset()
|
||||
frame.trap.trace()[frame.idx].module_offset()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user