Skip to content

Commit

Permalink
glib: Add unsafe bindings to g_object_run_dispose()
Browse files Browse the repository at this point in the history
  • Loading branch information
sdroege committed Oct 23, 2022
1 parent 9f414cd commit 2162541
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions glib/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,20 @@ pub trait ObjectExt: ObjectType {
// rustdoc-stripper-ignore-next
/// Returns the strong reference count of this object.
fn ref_count(&self) -> u32;

// rustdoc-stripper-ignore-next
/// Runs the dispose mechanism of the object.
///
/// This will dispose of any references the object has to other objects, and among other things
/// will disconnect all signal handlers.
///
/// # Safety
///
/// Theoretically this is safe to run and afterwards the object is simply in a non-functional
/// state, however many object implementations in C end up with memory safety issues if the
/// object is used after disposal.
#[doc(alias = "g_object_run_dispose")]
unsafe fn run_dispose(&self);
}

impl<T: ObjectType> ObjectExt for T {
Expand Down Expand Up @@ -3125,6 +3139,10 @@ impl<T: ObjectType> ObjectExt for T {

unsafe { ffi::g_atomic_int_get(&(*ptr).ref_count as *const u32 as *const i32) as u32 }
}

unsafe fn run_dispose(&self) {
gobject_ffi::g_object_run_dispose(self.as_ptr() as *mut _);
}
}

// Helper struct to avoid creating an extra ref on objects inside closure watches. This is safe
Expand Down

0 comments on commit 2162541

Please sign in to comment.