use glib_sys;
use gobject_sys;
use std::ptr;
#[macro_export]
macro_rules! glib_floating_reference_guard {
($obj:ident) => {
let _guard = $crate::subclass::guard::FloatingReferenceGuard::new($obj as *mut _);
};
}
pub struct FloatingReferenceGuard(ptr::NonNull<gobject_sys::GObject>);
impl FloatingReferenceGuard {
#[doc(hidden)]
pub unsafe fn new(obj: *mut gobject_sys::GObject) -> Option<FloatingReferenceGuard> {
assert!(!obj.is_null());
if gobject_sys::g_object_is_floating(obj) != glib_sys::GFALSE {
gobject_sys::g_object_ref_sink(obj);
Some(FloatingReferenceGuard(ptr::NonNull::new_unchecked(obj)))
} else {
None
}
}
}
impl Drop for FloatingReferenceGuard {
fn drop(&mut self) {
unsafe {
gobject_sys::g_object_force_floating(self.0.as_ptr());
}
}
}