1- use crate :: r#ref:: { ref_into_val , val_into_ref} ;
1+ use crate :: r#ref:: { ref_to_val , val_into_ref} ;
22use crate :: { handle_result, wasm_func_t, wasm_ref_t, wasmtime_error_t} ;
33use crate :: { wasm_extern_t, wasm_store_t, wasm_tabletype_t} ;
44use std:: ptr;
@@ -30,21 +30,24 @@ impl wasm_table_t {
3030 }
3131}
3232
33- fn ref_into_val_for_table ( r : Option < Box < wasm_ref_t > > , table_ty : & TableType ) -> Val {
34- ref_into_val ( r) . unwrap_or_else ( || match table_ty. element ( ) {
35- ValType :: FuncRef => Val :: FuncRef ( None ) ,
36- ValType :: ExternRef => Val :: ExternRef ( None ) ,
37- ty => panic ! ( "unsupported table element type: {:?}" , ty) ,
38- } )
33+ fn ref_to_val_for_table ( r : Option < & wasm_ref_t > , table_ty : & TableType ) -> Val {
34+ r. map_or_else (
35+ || match table_ty. element ( ) {
36+ ValType :: FuncRef => Val :: FuncRef ( None ) ,
37+ ValType :: ExternRef => Val :: ExternRef ( None ) ,
38+ ty => panic ! ( "unsupported table element type: {:?}" , ty) ,
39+ } ,
40+ |r| ref_to_val ( r) ,
41+ )
3942}
4043
4144#[ no_mangle]
4245pub extern "C" fn wasm_table_new (
4346 store : & wasm_store_t ,
4447 tt : & wasm_tabletype_t ,
45- init : Option < Box < wasm_ref_t > > ,
48+ init : Option < & wasm_ref_t > ,
4649) -> Option < Box < wasm_table_t > > {
47- let init = ref_into_val_for_table ( init, & tt. ty ( ) . ty ) ;
50+ let init = ref_to_val_for_table ( init, & tt. ty ( ) . ty ) ;
4851 let table = Table :: new ( & store. store , tt. ty ( ) . ty . clone ( ) , init) . ok ( ) ?;
4952 Some ( Box :: new ( wasm_table_t {
5053 ext : wasm_extern_t {
@@ -115,9 +118,9 @@ pub extern "C" fn wasmtime_funcref_table_get(
115118pub unsafe extern "C" fn wasm_table_set (
116119 t : & wasm_table_t ,
117120 index : wasm_table_size_t ,
118- r : Option < Box < wasm_ref_t > > ,
121+ r : Option < & wasm_ref_t > ,
119122) -> bool {
120- let val = ref_into_val_for_table ( r, & t. table ( ) . ty ( ) ) ;
123+ let val = ref_to_val_for_table ( r, & t. table ( ) . ty ( ) ) ;
121124 t. table ( ) . set ( index, val) . is_ok ( )
122125}
123126
@@ -143,9 +146,9 @@ pub extern "C" fn wasm_table_size(t: &wasm_table_t) -> wasm_table_size_t {
143146pub unsafe extern "C" fn wasm_table_grow (
144147 t : & wasm_table_t ,
145148 delta : wasm_table_size_t ,
146- init : Option < Box < wasm_ref_t > > ,
149+ init : Option < & wasm_ref_t > ,
147150) -> bool {
148- let init = ref_into_val_for_table ( init, & t. table ( ) . ty ( ) ) ;
151+ let init = ref_to_val_for_table ( init, & t. table ( ) . ty ( ) ) ;
149152 t. table ( ) . grow ( delta, init) . is_ok ( )
150153}
151154
0 commit comments