@@ -224,7 +224,7 @@ impl<'a> FnOnce<((),)> for Builder<'a> {
224
224
let mut ret_val = unsafe { mem:: uninitialized :: < ts:: TVMValue > ( ) } ;
225
225
let mut ret_type_code = 0 as c_int ;
226
226
if self . arg_buf . is_some ( ) {
227
- let arg_buf = self . arg_buf . unwrap ( ) ;
227
+ let arg_buf = self . arg_buf ? ;
228
228
let mut num_args = arg_buf. len ( ) ;
229
229
let mut values = arg_buf
230
230
. iter ( )
@@ -236,15 +236,15 @@ impl<'a> FnOnce<((),)> for Builder<'a> {
236
236
. collect :: < Vec < _ > > ( ) ;
237
237
if self . ret_buf . is_some ( ) {
238
238
num_args = num_args + 1 ;
239
- ret_val = * self . ret_buf . clone ( ) . unwrap ( ) [ 0 ] . value ;
240
- ret_type_code = self . ret_buf . clone ( ) . unwrap ( ) [ 0 ] . type_code as c_int ;
239
+ ret_val = * self . ret_buf . clone ( ) ? [ 0 ] . value ;
240
+ ret_type_code = self . ret_buf . clone ( ) ? [ 0 ] . type_code as c_int ;
241
241
values. append ( & mut vec ! [ ret_val] ) ;
242
242
tcodes. append ( & mut vec ! [ ret_type_code] ) ;
243
243
}
244
244
values. truncate ( num_args) ;
245
245
tcodes. truncate ( num_args) ;
246
246
check_call ! ( ts:: TVMFuncCall (
247
- self . func. unwrap ( ) . handle,
247
+ self . func? . handle,
248
248
values. as_mut_ptr( ) ,
249
249
tcodes. as_mut_ptr( ) ,
250
250
num_args as c_int,
@@ -253,7 +253,7 @@ impl<'a> FnOnce<((),)> for Builder<'a> {
253
253
) ) ;
254
254
} else {
255
255
check_call ! ( ts:: TVMFuncCall (
256
- self . func. unwrap ( ) . handle,
256
+ self . func? . handle,
257
257
ptr:: null_mut( ) ,
258
258
ptr:: null_mut( ) ,
259
259
0 as c_int,
@@ -292,44 +292,47 @@ unsafe extern "C" fn tvm_callback(
292
292
fhandle : * mut c_void ,
293
293
) -> c_int {
294
294
let len = num_args as usize ;
295
- let args_list = unsafe { slice:: from_raw_parts_mut ( args, len) . to_vec ( ) } ;
296
- let type_codes_list = unsafe { slice:: from_raw_parts_mut ( type_codes, len) . to_vec ( ) } ;
295
+ let args_list = unsafe { slice:: from_raw_parts_mut ( args, len) } ;
296
+ let type_codes_list = unsafe { slice:: from_raw_parts_mut ( type_codes, len) } ;
297
297
let mut local_args: Vec < TVMArgValue > = Vec :: new ( ) ;
298
- let mut value = unsafe { mem:: uninitialized :: < ts:: TVMValue > ( ) } ;
299
- let mut tcode = unsafe { mem:: uninitialized :: < c_int > ( ) } ;
300
- let rust_fn = unsafe {
301
- mem:: transmute :: < * mut c_void , fn ( & [ TVMArgValue ] ) -> Result < TVMRetValue < ' static > > > ( fhandle)
302
- } ;
303
- for i in 0 ..len {
304
- value = args_list[ i] ;
305
- tcode = type_codes_list[ i] ;
306
- if tcode == TypeCode :: kNodeHandle as c_int
307
- || tcode == TypeCode :: kFuncHandle as c_int
308
- || tcode == TypeCode :: kModuleHandle as c_int
309
- {
310
- check_call ! ( ts:: TVMCbArgToReturn ( & mut value as * mut _, tcode) ) ;
298
+ unsafe {
299
+ let mut value = mem:: uninitialized :: < ts:: TVMValue > ( ) ;
300
+ let mut tcode = mem:: uninitialized :: < c_int > ( ) ;
301
+ let rust_fn = mem:: transmute :: <
302
+ * mut c_void ,
303
+ fn ( & [ TVMArgValue ] ) -> Result < TVMRetValue < ' static > > ,
304
+ > ( fhandle) ;
305
+ for i in 0 ..len {
306
+ value = args_list[ i] ;
307
+ tcode = type_codes_list[ i] ;
308
+ if tcode == TypeCode :: kNodeHandle as c_int
309
+ || tcode == TypeCode :: kFuncHandle as c_int
310
+ || tcode == TypeCode :: kModuleHandle as c_int
311
+ {
312
+ check_call ! ( ts:: TVMCbArgToReturn ( & mut value as * mut _, tcode) ) ;
313
+ }
314
+ local_args. push ( TVMArgValue :: new (
315
+ TVMValue :: new ( ValueKind :: Handle , value) ,
316
+ tcode. into ( ) ,
317
+ ) ) ;
311
318
}
312
- local_args. push ( TVMArgValue :: new (
313
- TVMValue :: new ( ValueKind :: Handle , value) ,
314
- tcode. into ( ) ,
319
+
320
+ let rv = match rust_fn ( local_args. as_slice ( ) ) {
321
+ Ok ( v) => v,
322
+ Err ( msg) => {
323
+ :: set_last_error ( & msg) ;
324
+ return -1 ;
325
+ }
326
+ } ;
327
+ let mut ret_val = * rv. value ;
328
+ let mut ret_type_code = rv. type_code as c_int ;
329
+ check_call ! ( ts:: TVMCFuncSetReturn (
330
+ ret,
331
+ & mut ret_val as * mut _,
332
+ & mut ret_type_code as * mut _,
333
+ 1 as c_int
315
334
) ) ;
316
335
}
317
-
318
- let rv = match rust_fn ( local_args. as_slice ( ) ) {
319
- Ok ( v) => v,
320
- Err ( msg) => {
321
- :: set_last_error ( & msg) ;
322
- return -1 ;
323
- }
324
- } ;
325
- let mut ret_val = * rv. value ;
326
- let mut ret_type_code = rv. type_code as c_int ;
327
- check_call ! ( ts:: TVMCFuncSetReturn (
328
- ret,
329
- & mut ret_val as * mut _,
330
- & mut ret_type_code as * mut _,
331
- 1 as c_int
332
- ) ) ;
333
336
0
334
337
}
335
338
@@ -384,12 +387,11 @@ pub fn register(
384
387
override_ : bool ,
385
388
) -> Result < ( ) > {
386
389
let func = convert_to_tvm_func ( f) ;
387
- let ovd = if override_ { 1 } else { 0 } ;
388
- let name = CString :: new ( name) . unwrap ( ) ;
390
+ let name = CString :: new ( name) ?;
389
391
check_call ! ( ts:: TVMFuncRegisterGlobal (
390
392
name. as_ptr( ) as * const c_char,
391
393
func. handle( ) ,
392
- ovd
394
+ override_ as c_int
393
395
) ) ;
394
396
mem:: forget ( name) ;
395
397
Ok ( ( ) )
0 commit comments