mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-24 06:01:33 +00:00
Misc fixes
This commit is contained in:
@ -119,7 +119,6 @@ impl std::error::Error for LinkError {}
|
||||
/// The main way to do this is `Instance.call`.
|
||||
///
|
||||
/// Comparing two `RuntimeError`s always evaluates to false.
|
||||
#[derive(Debug)]
|
||||
pub enum RuntimeError {
|
||||
Trap { msg: Box<str> },
|
||||
Exception { data: Box<[Value]> },
|
||||
@ -141,9 +140,25 @@ impl std::fmt::Display for RuntimeError {
|
||||
RuntimeError::Exception { ref data } => {
|
||||
write!(f, "Uncaught WebAssembly exception: {:?}", data)
|
||||
}
|
||||
RuntimeError::Panic { data: _ } => write!(f, "User-defined \"panic\""),
|
||||
RuntimeError::Panic { data } => {
|
||||
let msg = if let Some(s) = data.downcast_ref::<String>() {
|
||||
s
|
||||
} else if let Some(s) = data.downcast_ref::<&str>() {
|
||||
s
|
||||
} else {
|
||||
"user-defined, opaque"
|
||||
};
|
||||
|
||||
write!(f, "{}", msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for RuntimeError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{}", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for RuntimeError {}
|
||||
@ -197,7 +212,6 @@ impl std::error::Error for ResolveError {}
|
||||
/// be the `CallError::Runtime(RuntimeError)` variant.
|
||||
///
|
||||
/// Comparing two `CallError`s always evaluates to false.
|
||||
#[derive(Debug)]
|
||||
pub enum CallError {
|
||||
Resolve(ResolveError),
|
||||
Runtime(RuntimeError),
|
||||
@ -218,6 +232,15 @@ impl std::fmt::Display for CallError {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for CallError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
CallError::Resolve(resolve_err) => write!(f, "ResolveError: {:?}", resolve_err),
|
||||
CallError::Runtime(runtime_err) => write!(f, "RuntimeError: {:?}", runtime_err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for CallError {}
|
||||
|
||||
/// This error type is produced when creating something,
|
||||
|
@ -129,7 +129,8 @@ unsafe impl WasmExternType for f64 {
|
||||
pub unsafe trait ValueType: Copy
|
||||
where
|
||||
Self: Sized,
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
macro_rules! convert_value_impl {
|
||||
($t:ty) => {
|
||||
|
@ -8,11 +8,11 @@ use hashbrown::hash_map::{Entry, HashMap};
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
ops::{Index, IndexMut},
|
||||
path::PathBuf,
|
||||
rc::Rc,
|
||||
time::SystemTime,
|
||||
path::PathBuf,
|
||||
};
|
||||
use zbox::{File, FileType, OpenOptions, Repo, RepoOpener, init_env as zbox_init_env};
|
||||
use zbox::{init_env as zbox_init_env, File, FileType, OpenOptions, Repo, RepoOpener};
|
||||
|
||||
pub const MAX_SYMLINKS: usize = 100;
|
||||
|
||||
|
@ -815,8 +815,8 @@ pub fn poll_oneoff(
|
||||
) -> __wasi_errno_t {
|
||||
unimplemented!()
|
||||
}
|
||||
pub fn proc_exit(ctx: &mut Ctx, rval: __wasi_exitcode_t) {
|
||||
unimplemented!()
|
||||
pub fn proc_exit(ctx: &mut Ctx, rval: __wasi_exitcode_t) -> Result<(), &'static str> {
|
||||
Err("Instance exited")
|
||||
}
|
||||
pub fn proc_raise(ctx: &mut Ctx, sig: __wasi_signal_t) -> __wasi_errno_t {
|
||||
unimplemented!()
|
||||
@ -833,13 +833,11 @@ pub fn random_get(ctx: &mut Ctx, buf: WasmPtr<u8, Array>, buf_len: u32) -> __was
|
||||
let mut rng = thread_rng();
|
||||
let memory = ctx.memory(0);
|
||||
|
||||
if let Ok(buf) = buf.deref(memory, 0, buf_len) {
|
||||
for i in 0..(buf_len as usize) {
|
||||
let random_byte = rng.gen::<u8>();
|
||||
buf[i].set(random_byte);
|
||||
}
|
||||
} else {
|
||||
return __WASI_EFAULT;
|
||||
let buf = wasi_try!(buf.deref(memory, 0, buf_len));
|
||||
|
||||
unsafe {
|
||||
let u8_buffer = &mut *(buf as *const [_] as *mut [_] as *mut [u8]);
|
||||
thread_rng().fill(u8_buffer);
|
||||
}
|
||||
|
||||
__WASI_ESUCCESS
|
||||
|
Reference in New Issue
Block a user