From cb0eaca7080b3f5fe53ea0468b69b4c6bae6cc12 Mon Sep 17 00:00:00 2001 From: quo Date: Tue, 7 Jan 2025 21:39:50 +0100 Subject: [PATCH] glib: Remove SendWeakRef::new() because implementation is unsound --- glib/src/object.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/glib/src/object.rs b/glib/src/object.rs index a9d8b87c2261..e694da21f864 100644 --- a/glib/src/object.rs +++ b/glib/src/object.rs @@ -3583,18 +3583,13 @@ impl PartialOrd for WeakRef { /// where it was created on will panic but dropping or cloning can be done /// safely from any thread. #[derive(Debug)] -pub struct SendWeakRef(WeakRef, Option); +pub struct SendWeakRef(WeakRef, usize); impl SendWeakRef { - #[inline] - pub fn new() -> SendWeakRef { - SendWeakRef(WeakRef::new(), None) - } - #[inline] pub fn into_weak_ref(self) -> WeakRef { assert!( - self.1.is_none() || self.1 == Some(thread_id()), + self.1 == thread_id(), "SendWeakRef dereferenced on a different thread", ); @@ -3608,7 +3603,7 @@ impl ops::Deref for SendWeakRef { #[inline] fn deref(&self) -> &WeakRef { assert!( - self.1.is_none() || self.1 == Some(thread_id()), + self.1 == thread_id(), "SendWeakRef dereferenced on a different thread" ); @@ -3627,14 +3622,14 @@ impl Clone for SendWeakRef { impl Default for SendWeakRef { #[inline] fn default() -> Self { - Self::new() + Self::from(WeakRef::new()) } } impl From> for SendWeakRef { #[inline] fn from(v: WeakRef) -> SendWeakRef { - SendWeakRef(v, Some(thread_id())) + SendWeakRef(v, thread_id()) } }