@@ -50,7 +50,11 @@ impl ParsedModule {
50
50
}
51
51
52
52
pub ( crate ) fn take_data ( self ) -> Box < [ u8 ] > {
53
- let ParsedModule { data, raw, env : _env } = self ;
53
+ let ParsedModule {
54
+ data,
55
+ raw,
56
+ env : _env,
57
+ } = self ;
54
58
mem:: forget ( raw) ;
55
59
data
56
60
}
@@ -114,7 +118,7 @@ impl<'rt> Module<'rt> {
114
118
module_name_cstr. as_ptr ( ) ,
115
119
function_name_cstr. as_ptr ( ) ,
116
120
signature. as_ptr ( ) ,
117
- Some ( f)
121
+ Some ( f) ,
118
122
)
119
123
} ;
120
124
Error :: from_ffi_res ( result)
@@ -147,10 +151,10 @@ impl<'rt> Module<'rt> {
147
151
sp : * mut u64 ,
148
152
_mem : * mut cty:: c_void ,
149
153
) -> * const cty:: c_void
150
- where
151
- Args : crate :: WasmArgs ,
152
- Ret : crate :: WasmType ,
153
- F : for < ' cc > FnMut ( CallContext < ' cc > , Args ) -> core:: result:: Result < Ret , Trap > + ' static ,
154
+ where
155
+ Args : crate :: WasmArgs ,
156
+ Ret : crate :: WasmType ,
157
+ F : for < ' cc > FnMut ( CallContext < ' cc > , Args ) -> core:: result:: Result < Ret , Trap > + ' static ,
154
158
{
155
159
let runtime = NonNull :: new ( runtime)
156
160
. expect ( "wasm3 calls imported functions with non-null runtime" ) ;
@@ -165,7 +169,7 @@ impl<'rt> Module<'rt> {
165
169
Ok ( ret) => {
166
170
ret. push_on_stack ( sp) ;
167
171
ffi:: m3Err_none
168
- } ,
172
+ }
169
173
Err ( trap) => trap. as_ptr ( ) ,
170
174
} ;
171
175
result as * const cty:: c_void
@@ -183,7 +187,7 @@ impl<'rt> Module<'rt> {
183
187
function_name_cstr. as_ptr ( ) ,
184
188
signature. as_ptr ( ) ,
185
189
Some ( trampoline :: < Args , Ret , F > ) ,
186
- closure. as_mut ( ) . get_unchecked_mut ( ) as * mut F as * const cty:: c_void
190
+ closure. as_mut ( ) . get_unchecked_mut ( ) as * mut F as * const cty:: c_void ,
187
191
)
188
192
} ;
189
193
Error :: from_ffi_res ( result) ?;
@@ -226,17 +230,14 @@ impl<'rt> Module<'rt> {
226
230
227
231
impl < ' rt > Module < ' rt > {
228
232
pub ( crate ) fn from_raw ( rt : & ' rt Runtime , raw : ffi:: IM3Module ) -> Self {
229
- Module {
230
- raw,
231
- rt,
232
- }
233
+ Module { raw, rt }
233
234
}
234
235
}
235
236
236
237
fn function_signature < Args , Ret > ( ) -> Vec < cty:: c_char >
237
- where
238
- Args : crate :: WasmArgs ,
239
- Ret : crate :: WasmType ,
238
+ where
239
+ Args : crate :: WasmArgs ,
240
+ Ret : crate :: WasmType ,
240
241
{
241
242
let mut signature = <Vec < cty:: c_char > >:: new ( ) ;
242
243
signature. push ( Ret :: SIGNATURE as cty:: c_char ) ;
@@ -250,8 +251,8 @@ fn function_signature<Args, Ret>() -> Vec<cty::c_char>
250
251
#[ cfg( test) ]
251
252
mod tests {
252
253
use super :: * ;
253
- use crate :: make_func_wrapper;
254
254
use crate :: error:: TrappedResult ;
255
+ use crate :: make_func_wrapper;
255
256
256
257
make_func_wrapper ! ( mul_u32_and_f32_wrap: mul_u32_and_f32( a: u32 , b: f32 ) -> f64 ) ;
257
258
fn mul_u32_and_f32 ( a : u32 , b : f32 ) -> f64 {
@@ -270,11 +271,11 @@ mod tests {
270
271
fn module_parse ( ) {
271
272
let env = Environment :: new ( ) . expect ( "env alloc failure" ) ;
272
273
let fib32 = [
273
- 0x00 , 0x61 , 0x73 , 0x6d , 0x01 , 0x00 , 0x00 , 0x00 , 0x01 , 0x06 , 0x01 , 0x60 , 0x01 , 0x7f , 0x01 ,
274
- 0x7f , 0x03 , 0x02 , 0x01 , 0x00 , 0x07 , 0x07 , 0x01 , 0x03 , 0x66 , 0x69 , 0x62 , 0x00 , 0x00 , 0x0a ,
275
- 0x1f , 0x01 , 0x1d , 0x00 , 0x20 , 0x00 , 0x41 , 0x02 , 0x49 , 0x04 , 0x40 , 0x20 , 0x00 , 0x0f , 0x0b ,
276
- 0x20 , 0x00 , 0x41 , 0x02 , 0x6b , 0x10 , 0x00 , 0x20 , 0x00 , 0x41 , 0x01 , 0x6b , 0x10 , 0x00 , 0x6a ,
277
- 0x0f , 0x0b ,
274
+ 0x00 , 0x61 , 0x73 , 0x6d , 0x01 , 0x00 , 0x00 , 0x00 , 0x01 , 0x06 , 0x01 , 0x60 , 0x01 , 0x7f ,
275
+ 0x01 , 0x7f , 0x03 , 0x02 , 0x01 , 0x00 , 0x07 , 0x07 , 0x01 , 0x03 , 0x66 , 0x69 , 0x62 , 0x00 ,
276
+ 0x00 , 0x0a , 0x1f , 0x01 , 0x1d , 0x00 , 0x20 , 0x00 , 0x41 , 0x02 , 0x49 , 0x04 , 0x40 , 0x20 ,
277
+ 0x00 , 0x0f , 0x0b , 0x20 , 0x00 , 0x41 , 0x02 , 0x6b , 0x10 , 0x00 , 0x20 , 0x00 , 0x41 , 0x01 ,
278
+ 0x6b , 0x10 , 0x00 , 0x6a , 0x0f , 0x0b ,
278
279
] ;
279
280
let _ = Module :: parse ( & env, & fib32[ ..] ) . unwrap ( ) ;
280
281
}
@@ -284,20 +285,32 @@ mod tests {
284
285
let env = Environment :: new ( ) . expect ( "env alloc failure" ) ;
285
286
let runtime = Runtime :: new ( & env, STACK_SIZE ) . expect ( "runtime init failure" ) ;
286
287
let mut module = runtime. parse_and_load_module ( TEST_BIN ) . unwrap ( ) ;
287
- module. link_function :: < ( u32 , f32 ) , f64 > ( "env" , "mul_u32_and_f32" , mul_u32_and_f32_wrap)
288
+ module
289
+ . link_function :: < ( u32 , f32 ) , f64 > ( "env" , "mul_u32_and_f32" , mul_u32_and_f32_wrap)
290
+ . unwrap ( ) ;
291
+ module
292
+ . link_function :: < ( ) , ( ) > ( "env" , "hello" , hello_wrap)
288
293
. unwrap ( ) ;
289
- module. link_function :: < ( ) , ( ) > ( "env" , "hello" , hello_wrap) . unwrap ( ) ;
290
294
}
291
295
292
296
#[ test]
293
297
fn test_link_closures ( ) {
294
298
let env = Environment :: new ( ) . expect ( "env alloc failure" ) ;
295
299
let runtime = Runtime :: new ( & env, STACK_SIZE ) . expect ( "runtime init failure" ) ;
296
300
let mut module = runtime. parse_and_load_module ( TEST_BIN ) . unwrap ( ) ;
297
- module. link_closure ( "env" , "mul_u32_and_f32" , |_ctx, args : ( u32 , f32 ) | -> TrappedResult < f64 > {
298
- Ok ( mul_u32_and_f32 ( args. 0 , args. 1 ) )
299
- } ) . unwrap ( ) ;
300
- module. link_closure ( "env" , "hello" , |_ctx, _args : ( ) | -> TrappedResult < ( ) > { hello ( ) } )
301
+ module
302
+ . link_closure (
303
+ "env" ,
304
+ "mul_u32_and_f32" ,
305
+ |_ctx, args : ( u32 , f32 ) | -> TrappedResult < f64 > {
306
+ Ok ( mul_u32_and_f32 ( args. 0 , args. 1 ) )
307
+ } ,
308
+ )
309
+ . unwrap ( ) ;
310
+ module
311
+ . link_closure ( "env" , "hello" , |_ctx, _args : ( ) | -> TrappedResult < ( ) > {
312
+ hello ( )
313
+ } )
301
314
. unwrap ( ) ;
302
315
}
303
316
}
0 commit comments