@@ -7,7 +7,7 @@ use core::str;
7
7
use crate :: error:: { Error , Result } ;
8
8
use crate :: runtime:: Runtime ;
9
9
use crate :: utils:: cstr_to_str;
10
- use crate :: { Module , WasmArgs , WasmType } ;
10
+ use crate :: { Module , WasmArg , WasmArgs , WasmType } ;
11
11
12
12
/// Calling Context for a host function.
13
13
pub struct CallContext < ' cc > {
@@ -136,11 +136,7 @@ where
136
136
} )
137
137
}
138
138
139
- fn call_impl ( & self , args : Args ) -> Result < Ret > {
140
- let mut argv = args. ptrs_vec ( ) ;
141
- let result =
142
- unsafe { ffi:: m3_Call ( self . raw . as_ptr ( ) , argv. len ( ) as u32 , argv. as_mut_ptr ( ) ) } ;
143
- Error :: from_ffi_res ( result) ?;
139
+ fn get_call_result ( & self ) -> Result < Ret > {
144
140
unsafe {
145
141
let mut ret = core:: mem:: MaybeUninit :: < Ret > :: uninit ( ) ;
146
142
let result = ffi:: m3_GetResultsV ( self . raw . as_ptr ( ) , ret. as_mut_ptr ( ) ) ;
@@ -168,7 +164,9 @@ macro_rules! func_call_impl {
168
164
#[ inline]
169
165
#[ allow( non_snake_case, clippy:: too_many_arguments) ]
170
166
pub fn call( & self , $( $types: $types) ,* ) -> Result <Ret > {
171
- self . call_impl( ( $( $types, ) * ) )
167
+ let result = unsafe { ffi:: m3_CallV( self . raw. as_ptr( ) , $( $types, ) * ) } ;
168
+ Error :: from_ffi_res( result) ?;
169
+ self . get_call_result( )
172
170
}
173
171
}
174
172
} ;
@@ -178,13 +176,15 @@ func_call_impl!(A, B, C, D, E, F, G, H, J, K, L, M, N, O, P, Q);
178
176
impl < ' rt , ARG , Ret > Function < ' rt , ARG , Ret >
179
177
where
180
178
Ret : WasmType ,
181
- ARG : crate :: WasmArg ,
179
+ ARG : WasmArg ,
182
180
{
183
181
/// Calls this function with the given parameter.
184
182
/// This is implemented with variable arguments depending on the functions Args type.
185
183
#[ inline]
186
184
pub fn call ( & self , arg : ARG ) -> Result < Ret > {
187
- self . call_impl ( arg)
185
+ let result = unsafe { ffi:: m3_CallV ( self . raw . as_ptr ( ) , arg) } ;
186
+ Error :: from_ffi_res ( result) ?;
187
+ self . get_call_result ( )
188
188
}
189
189
}
190
190
@@ -196,6 +196,8 @@ where
196
196
/// This is implemented with variable arguments depending on the functions Args type.
197
197
#[ inline]
198
198
pub fn call ( & self ) -> Result < Ret > {
199
- self . call_impl ( ( ) )
199
+ let result = unsafe { ffi:: m3_CallV ( self . raw . as_ptr ( ) ) } ;
200
+ Error :: from_ffi_res ( result) ?;
201
+ self . get_call_result ( )
200
202
}
201
203
}
0 commit comments