Skip to content

Commit

Permalink
Merge pull request #1621 from quo/pr-sendweakref
Browse files Browse the repository at this point in the history
glib: Remove SendWeakRef::new() because implementation is unsound
  • Loading branch information
sdroege authored Jan 8, 2025
2 parents 6d1669f + cb0eaca commit ced2343
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions glib/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3583,18 +3583,13 @@ impl<T: ObjectType> PartialOrd for WeakRef<T> {
/// where it was created on will panic but dropping or cloning can be done
/// safely from any thread.
#[derive(Debug)]
pub struct SendWeakRef<T: ObjectType>(WeakRef<T>, Option<usize>);
pub struct SendWeakRef<T: ObjectType>(WeakRef<T>, usize);

impl<T: ObjectType> SendWeakRef<T> {
#[inline]
pub fn new() -> SendWeakRef<T> {
SendWeakRef(WeakRef::new(), None)
}

#[inline]
pub fn into_weak_ref(self) -> WeakRef<T> {
assert!(
self.1.is_none() || self.1 == Some(thread_id()),
self.1 == thread_id(),
"SendWeakRef dereferenced on a different thread",
);

Expand All @@ -3608,7 +3603,7 @@ impl<T: ObjectType> ops::Deref for SendWeakRef<T> {
#[inline]
fn deref(&self) -> &WeakRef<T> {
assert!(
self.1.is_none() || self.1 == Some(thread_id()),
self.1 == thread_id(),
"SendWeakRef dereferenced on a different thread"
);

Expand All @@ -3627,14 +3622,14 @@ impl<T: ObjectType> Clone for SendWeakRef<T> {
impl<T: ObjectType> Default for SendWeakRef<T> {
#[inline]
fn default() -> Self {
Self::new()
Self::from(WeakRef::new())
}
}

impl<T: ObjectType> From<WeakRef<T>> for SendWeakRef<T> {
#[inline]
fn from(v: WeakRef<T>) -> SendWeakRef<T> {
SendWeakRef(v, Some(thread_id()))
SendWeakRef(v, thread_id())
}
}

Expand Down

0 comments on commit ced2343

Please sign in to comment.