tqchen commented on code in PR #814:
URL: https://github.com/apache/tvm-ffi/pull/814#discussion_r4105798635


##########
rust/tvm-ffi/src/function.rs:
##########
@@ -81,17 +81,7 @@ impl<F: Fn(&[AnyView]) -> Result<Any> + 'static> 
CallbackFunctionObjImpl<F> {
     ) -> i32 {
         let this = &*(handle as *mut Self);
         let packed_args = std::slice::from_raw_parts(args as *const AnyView, 
num_args as usize);
-        let ret_value = (this.callback)(packed_args);
-        match ret_value {
-            Ok(value) => {

Review Comment:
   helpful to not introduce the helper and the syntax here should be simple 
enough to do
   ```rust
   // function_internal.rs — non-generic, no closure parameter, reusable 
verbatim                                 
     // by rust_vtable_* and the deleters when those get covered.               
                                    
     #[doc(hidden)]                                                             
                                    
     pub fn panic_to_error(payload: Box<dyn std::any::Any + Send>) -> Error {   
                                    
         let message = payload                                                  
                                    
             .downcast_ref::<&str>()                                            
                                    
             .copied()                                                          
                                    
             .or_else(|| payload.downcast_ref::<String>().map(String::as_str))  
                                    
             .unwrap_or("unknown payload");                                     
                                    
         Error::new(INTERNAL_ERROR, &format!("panicked: {message}"), "")        
                                    
     }                                                                          
                                    
             
   
    // each boundary — catch_unwind stays visible, original match restored 
verbatim                                
     let ret_value = match catch_unwind(AssertUnwindSafe(|| 
(this.callback)(packed_args))) {                        
         Ok(result) => result,                                                  
                                    
         Err(payload) => Err(panic_to_error(payload)),                          
                                    
     };                                                                         
                                    
     match ret_value {                                                          
                                    
         Ok(value) => { *result = Any::into_raw_ffi_any(value); 0 }             
                                    
         Err(error) => { Error::set_raised(&error); -1 }                        
                                    
     } 
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to