From 50829bdec9a668e217c547273e19f3d8e253526f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 10 Apr 2017 16:24:49 +0300 Subject: [PATCH] Store GWeakRef in a Box Its memory location is important, and having it stored directly inside the struct allows it to possible be moved to a different address. --- gst-plugin/src/log.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gst-plugin/src/log.rs b/gst-plugin/src/log.rs index f884a63f..91f94a32 100644 --- a/gst-plugin/src/log.rs +++ b/gst-plugin/src/log.rs @@ -20,7 +20,7 @@ use gst; pub struct GstDebugDrain { category: *mut gst::GstDebugCategory, - element: gobject::GWeakRef, + element: Box, } impl GstDebugDrain { @@ -51,12 +51,12 @@ impl GstDebugDrain { let mut drain = GstDebugDrain { category: category, - element: unsafe { mem::zeroed() }, + element: Box::new(unsafe { mem::zeroed() }), }; if !element.is_null() { unsafe { - gobject::g_weak_ref_set(&mut drain.element, element as *mut gobject::GObject); + gobject::g_weak_ref_set(&mut *drain.element, element as *mut gobject::GObject); } } @@ -67,7 +67,7 @@ impl GstDebugDrain { impl Drop for GstDebugDrain { fn drop(&mut self) { unsafe { - gobject::g_weak_ref_clear(&mut self.element); + gobject::g_weak_ref_clear(&mut *self.element); } } } @@ -98,7 +98,7 @@ impl Drain for GstDebugDrain { let message_cstr = CString::new(fmt::format(record.msg()).as_bytes()).unwrap(); unsafe { - let element = gobject::g_weak_ref_get(&self.element as *const gobject::GWeakRef as + let element = gobject::g_weak_ref_get(&*self.element as *const gobject::GWeakRef as *mut gobject::GWeakRef); gst::gst_debug_log(self.category,