From 4358034bbf38b1217898baee8389c59f4d15d80a Mon Sep 17 00:00:00 2001 From: kyren Date: Mon, 12 Mar 2018 17:48:05 -0400 Subject: [PATCH] Do not crash in release when accessing an AnyUserData Also, don't bother asserting if the userdata has no metatable, just behave as though the userdata has no type. This should be impossible to trigger currently without the debug library, but it is not really that useful of an assert anyway. --- src/userdata.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/userdata.rs b/src/userdata.rs index 914914c..21af656 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -420,22 +420,20 @@ impl<'lua> AnyUserData<'lua> { lua.push_ref(&self.0); - rlua_debug_assert!( - ffi::lua_getmetatable(lua.state, -1) != 0, - "AnyUserData missing metatable" - ); - - ffi::lua_rawgeti( - lua.state, - ffi::LUA_REGISTRYINDEX, - lua.userdata_metatable::()? as ffi::lua_Integer, - ); - - if ffi::lua_rawequal(lua.state, -1, -2) == 0 { + if ffi::lua_getmetatable(lua.state, -1) == 0 { Err(Error::UserDataTypeMismatch) } else { - let res = func(&*get_userdata::>(lua.state, -3)); - res + ffi::lua_rawgeti( + lua.state, + ffi::LUA_REGISTRYINDEX, + lua.userdata_metatable::()? as ffi::lua_Integer, + ); + + if ffi::lua_rawequal(lua.state, -1, -2) == 0 { + Err(Error::UserDataTypeMismatch) + } else { + func(&*get_userdata::>(lua.state, -3)) + } } } }