summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkyren <kerriganw@gmail.com>2018-02-07 11:16:22 -0500
committerkyren <kerriganw@gmail.com>2018-02-07 11:16:22 -0500
commitab9841a02fb0c9ebe76e15247e68401fd13474cb (patch)
treea89aa106fcd384eec019308cb667fc540c99cbe9 /src
parentcb25a99f70b00b2cf2b1fc0ec0000d6fd89cfe9a (diff)
downloadmlua-ab9841a02fb0c9ebe76e15247e68401fd13474cb.zip
Don't keep the unref list around forever after Lua is dropped
Diffstat (limited to 'src')
-rw-r--r--src/lua.rs11
-rw-r--r--src/types.rs6
2 files changed, 10 insertions, 7 deletions
diff --git a/src/lua.rs b/src/lua.rs
index 948d142..0b02a14 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -39,7 +39,7 @@ pub struct Scope<'lua> {
// Data associated with the main lua_State via lua_getextraspace.
struct ExtraData {
registered_userdata: HashMap<TypeId, c_int>,
- registry_unref_list: Arc<Mutex<Vec<c_int>>>,
+ registry_unref_list: Arc<Mutex<Option<Vec<c_int>>>>,
}
unsafe impl Send for Lua {}
@@ -57,6 +57,7 @@ impl Drop for Lua {
}
let extra_data = *(ffi::lua_getextraspace(self.state) as *mut *mut ExtraData);
+ *(*extra_data).registry_unref_list.lock().unwrap() = None;
Box::from_raw(extra_data);
ffi::lua_close(self.state);
@@ -569,10 +570,10 @@ impl Lua {
pub fn expire_registry_values(&self) {
unsafe {
let unref_list = mem::replace(
- (*self.extra()).registry_unref_list.lock().unwrap().as_mut(),
- Vec::new(),
+ &mut *(*self.extra()).registry_unref_list.lock().unwrap(),
+ Some(Vec::new()),
);
- for id in unref_list {
+ for id in unref_list.unwrap() {
ffi::luaL_unref(self.state, ffi::LUA_REGISTRYINDEX, id);
}
}
@@ -935,7 +936,7 @@ impl Lua {
let extra_data = Box::into_raw(Box::new(ExtraData {
registered_userdata: HashMap::new(),
- registry_unref_list: Arc::new(Mutex::new(Vec::new())),
+ registry_unref_list: Arc::new(Mutex::new(Some(Vec::new()))),
}));
*(ffi::lua_getextraspace(state) as *mut *mut ExtraData) = extra_data;
});
diff --git a/src/types.rs b/src/types.rs
index de9f4e9..fb3a5d0 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -25,14 +25,16 @@ pub struct LightUserData(pub *mut c_void);
/// can be used in many situations where it would be impossible to store a regular handle value.
pub struct RegistryKey {
pub(crate) registry_id: c_int,
- pub(crate) unref_list: Arc<Mutex<Vec<c_int>>>,
+ pub(crate) unref_list: Arc<Mutex<Option<Vec<c_int>>>>,
pub(crate) drop_unref: bool,
}
impl Drop for RegistryKey {
fn drop(&mut self) {
if self.drop_unref {
- self.unref_list.lock().unwrap().push(self.registry_id);
+ if let Some(list) = self.unref_list.lock().unwrap().as_mut() {
+ list.push(self.registry_id);
+ }
}
}
}