From 1d7f105585e4f961967ee8d8cbd8fbfbc4787281 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Fri, 6 Aug 2021 11:14:16 +0100 Subject: [PATCH] Don't catch Rust panics in userdata finalizer on drop --- src/util.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/util.rs b/src/util.rs index 026b99f..fa11981 100644 --- a/src/util.rs +++ b/src/util.rs @@ -450,11 +450,10 @@ pub unsafe fn init_userdata_metatable( } pub unsafe extern "C" fn userdata_destructor(state: *mut ffi::lua_State) -> c_int { - callback_error(state, |_| { - check_stack(state, 1)?; - take_userdata::(state); - Ok(0) - }) + // It's probably NOT a good idea to catch Rust panics in finalizer + // Lua 5.4 ignores it, other versions generates `LUA_ERRGCMM` without calling message handler + take_userdata::(state); + 0 } // In the context of a lua callback, this will call the given function and if the given function