From dcb584019b395b966bc973f439a8750b6fe268b6 Mon Sep 17 00:00:00 2001 From: ad hoc <postma.marin@protonmail.com> Date: Tue, 26 Sep 2023 12:02:38 +0200 Subject: [PATCH] add correct function name in catch_panic macro (#703) --- sqld-libsql-bindings/src/wal_hook.rs | 54 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/sqld-libsql-bindings/src/wal_hook.rs b/sqld-libsql-bindings/src/wal_hook.rs index ad704f30..ff5e2f6c 100644 --- a/sqld-libsql-bindings/src/wal_hook.rs +++ b/sqld-libsql-bindings/src/wal_hook.rs @@ -197,24 +197,26 @@ impl<T: WalHook> WalMethodsHook<T> { } macro_rules! catch_panic { - ($($body:tt)*) => { - let ret = catch_unwind(move || { - $($body)* - }); - - match ret { - Ok(x) => x, - Err(e) => { - let error = if let Some(s) = e.downcast_ref::<String>() { - s.as_str() - } else if let Some(s) = e.downcast_ref::<&str>() { - s - } else { - "unknown" - }; - let bt = std::backtrace::Backtrace::force_capture(); - tracing::error!("panic in call to xframe: {error}:\n{bt}"); - resume_unwind(e) + ($name:literal, { $($body:tt)* }) => { + { + let ret = catch_unwind(move || { + $($body)* + }); + + match ret { + Ok(x) => x, + Err(e) => { + let error = if let Some(s) = e.downcast_ref::<String>() { + s.as_str() + } else if let Some(s) = e.downcast_ref::<&str>() { + s + } else { + "unknown" + }; + let bt = std::backtrace::Backtrace::force_capture(); + tracing::error!("panic in call to {}: {error}:\n{bt}", $name); + resume_unwind(e) + } } } }; @@ -320,13 +322,13 @@ pub extern "C" fn xUndo<T: WalHook>( func: Option<unsafe extern "C" fn(*mut c_void, u32) -> i32>, undo_ctx: *mut c_void, ) -> i32 { - catch_panic! { + catch_panic!("xUndo", { assert!(!wal.is_null()); let wal = unsafe { &mut *wal }; let orig_methods = get_orig_methods::<T>(wal); let orig_xundo = orig_methods.xUndo.unwrap(); T::on_undo(wal, func, undo_ctx, orig_xundo) - } + }) } #[allow(non_snake_case)] @@ -337,12 +339,12 @@ pub extern "C" fn xSavepoint<T: WalHook>(wal: *mut Wal, wal_data: *mut u32) { #[allow(non_snake_case)] pub extern "C" fn xSavepointUndo<T: WalHook>(wal: *mut Wal, wal_data: *mut u32) -> i32 { - catch_panic! { + catch_panic!("xSavepointUndo", { let wal = unsafe { &mut *wal }; let orig_methods = get_orig_methods::<T>(wal); let orig_xsavepointundo = orig_methods.xSavepointUndo.unwrap(); T::on_savepoint_undo(wal, wal_data, orig_xsavepointundo) - } + }) } #[allow(non_snake_case)] @@ -354,7 +356,7 @@ pub extern "C" fn xFrames<T: WalHook>( is_commit: c_int, sync_flags: c_int, ) -> c_int { - catch_panic! { + catch_panic!("xFrames", { assert!(!wal.is_null()); let wal = unsafe { &mut *wal }; let orig_methods = get_orig_methods::<T>(wal); @@ -369,7 +371,7 @@ pub extern "C" fn xFrames<T: WalHook>( sync_flags, orig_xframe, ) - } + }) } #[tracing::instrument(skip(wal, db))] @@ -386,7 +388,7 @@ pub extern "C" fn xCheckpoint<T: WalHook>( frames_in_wal: *mut c_int, backfilled_frames: *mut c_int, ) -> i32 { - catch_panic! { + catch_panic!("xCheckpoint", { let wal = unsafe { &mut *wal }; let orig_methods = get_orig_methods::<T>(wal); let orig_xcheckpoint = orig_methods.xCheckpoint.unwrap(); @@ -403,7 +405,7 @@ pub extern "C" fn xCheckpoint<T: WalHook>( backfilled_frames, orig_xcheckpoint, ) - } + }) } #[allow(non_snake_case)]