Use a Cow for the resumable parameters (#210)
* Use a Cow for the resumable parameters * Try fixing tests
This commit is contained in:
parent
08c09adbf2
commit
390f4b2c4a
10
src/func.rs
10
src/func.rs
|
@ -1,4 +1,5 @@
|
|||
use alloc::{
|
||||
borrow::Cow,
|
||||
rc::{Rc, Weak},
|
||||
vec::Vec,
|
||||
};
|
||||
|
@ -195,12 +196,13 @@ impl FuncInstance {
|
|||
/// [`resume_execution`]: struct.FuncInvocation.html#method.resume_execution
|
||||
pub fn invoke_resumable<'args>(
|
||||
func: &FuncRef,
|
||||
args: &'args [RuntimeValue],
|
||||
args: impl Into<Cow<'args, [RuntimeValue]>>,
|
||||
) -> Result<FuncInvocation<'args>, Trap> {
|
||||
let args = args.into();
|
||||
check_function_args(func.signature(), &args)?;
|
||||
match *func.as_internal() {
|
||||
FuncInstanceInternal::Internal { .. } => {
|
||||
let interpreter = Interpreter::new(func, args, None)?;
|
||||
let interpreter = Interpreter::new(func, &*args, None)?;
|
||||
Ok(FuncInvocation {
|
||||
kind: FuncInvocationKind::Internal(interpreter),
|
||||
})
|
||||
|
@ -257,7 +259,7 @@ pub struct FuncInvocation<'args> {
|
|||
enum FuncInvocationKind<'args> {
|
||||
Internal(Interpreter),
|
||||
Host {
|
||||
args: &'args [RuntimeValue],
|
||||
args: Cow<'args, [RuntimeValue]>,
|
||||
host_func_index: usize,
|
||||
finished: bool,
|
||||
},
|
||||
|
@ -304,7 +306,7 @@ impl<'args> FuncInvocation<'args> {
|
|||
return Err(ResumableError::AlreadyStarted);
|
||||
}
|
||||
*finished = true;
|
||||
Ok(externals.invoke_index(*host_func_index, args.clone().into())?)
|
||||
Ok(externals.invoke_index(*host_func_index, args.as_ref().into())?)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -285,7 +285,7 @@ fn resume_call_host_func() {
|
|||
let export = instance.export_by_name("test").unwrap();
|
||||
let func_instance = export.as_func().unwrap();
|
||||
|
||||
let mut invocation = FuncInstance::invoke_resumable(&func_instance, &[]).unwrap();
|
||||
let mut invocation = FuncInstance::invoke_resumable(&func_instance, &[][..]).unwrap();
|
||||
let result = invocation.start_execution(&mut env);
|
||||
match result {
|
||||
Err(ResumableError::Trap(_)) => {}
|
||||
|
@ -330,7 +330,7 @@ fn resume_call_host_func_type_mismatch() {
|
|||
let export = instance.export_by_name("test").unwrap();
|
||||
let func_instance = export.as_func().unwrap();
|
||||
|
||||
let mut invocation = FuncInstance::invoke_resumable(&func_instance, &[]).unwrap();
|
||||
let mut invocation = FuncInstance::invoke_resumable(&func_instance, &[][..]).unwrap();
|
||||
let result = invocation.start_execution(&mut env);
|
||||
match result {
|
||||
Err(ResumableError::Trap(_)) => {}
|
||||
|
|
Loading…
Reference in New Issue