diff --git a/glib/src/boxed.rs b/glib/src/boxed.rs index 8eb5fe61bbe9..2946e34a6373 100644 --- a/glib/src/boxed.rs +++ b/glib/src/boxed.rs @@ -47,6 +47,7 @@ macro_rules! glib_boxed_wrapper { #[doc = "Borrows the underlying C value."] #[inline] + #[deprecated = "Use FromGlibBorrow2 trait"] pub unsafe fn from_glib_ptr_borrow(ptr: &*mut $ffi_name) -> &Self { debug_assert_eq!( std::mem::size_of::(), @@ -58,6 +59,7 @@ macro_rules! glib_boxed_wrapper { #[doc = "Borrows the underlying C value mutably."] #[inline] + #[deprecated = "Use FromGlibBorrowMut2 trait"] pub unsafe fn from_glib_ptr_borrow_mut(ptr: &mut *mut $ffi_name) -> &mut Self { debug_assert_eq!( std::mem::size_of::(), @@ -252,6 +254,45 @@ macro_rules! glib_boxed_wrapper { } } + #[doc(hidden)] + impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibPtrBorrow2<*mut $ffi_name> for $name $(<$($generic),+>)? { + #[inline] + unsafe fn from_glib_borrow2(ptr: &*mut $ffi_name) -> &Self { + debug_assert_eq!( + std::mem::size_of::(), + std::mem::size_of::<$crate::ffi::gpointer>() + ); + debug_assert!(!ptr.is_null()); + &*(ptr as *const *mut $ffi_name as *const Self) + } + } + + #[doc(hidden)] + impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibPtrBorrow2<*const $ffi_name> for $name $(<$($generic),+>)? { + #[inline] + unsafe fn from_glib_borrow2(ptr: &*const $ffi_name) -> &Self { + debug_assert_eq!( + std::mem::size_of::(), + std::mem::size_of::<$crate::ffi::gpointer>() + ); + debug_assert!(!ptr.is_null()); + &*(ptr as *const *const $ffi_name as *const Self) + } + } + + #[doc(hidden)] + impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibPtrBorrowMut2<*mut $ffi_name> for $name $(<$($generic),+>)? { + #[inline] + unsafe fn from_glib_borrow_mut2(ptr: &mut *mut $ffi_name) -> &mut Self { + debug_assert_eq!( + std::mem::size_of::(), + std::mem::size_of::<$crate::ffi::gpointer>() + ); + debug_assert!(!ptr.is_null()); + &mut *(ptr as *mut *mut $ffi_name as *mut Self) + } + } + #[doc(hidden)] impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name> for $name $(<$($generic),+>)? { unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec { @@ -363,7 +404,7 @@ macro_rules! glib_boxed_wrapper { #[inline] unsafe fn from_value(value: &'a $crate::Value) -> Self { let value = &*(value as *const $crate::Value as *const $crate::gobject_ffi::GValue); - <$name $(<$($generic),+>)?>::from_glib_ptr_borrow(&*(&value.data[0].v_pointer as *const $crate::ffi::gpointer as *const *mut $ffi_name)) + <$name $(<$($generic),+>)? as $crate::translate::FromGlibPtrBorrow2<*mut $ffi_name>>::from_glib_borrow2(&*(&value.data[0].v_pointer as *const $crate::ffi::gpointer as *const *mut $ffi_name)) } } diff --git a/glib/src/boxed_inline.rs b/glib/src/boxed_inline.rs index 55c7d0b0abaa..d27a92285a46 100644 --- a/glib/src/boxed_inline.rs +++ b/glib/src/boxed_inline.rs @@ -171,6 +171,7 @@ macro_rules! glib_boxed_inline_wrapper { #[doc = "Borrows the underlying C value."] #[inline] + #[deprecated = "Use FromGlibBorrow2 trait"] pub unsafe fn from_glib_ptr_borrow<'a>(ptr: *const $ffi_name) -> &'a Self { debug_assert!(!ptr.is_null()); &*(ptr as *const Self) @@ -178,6 +179,7 @@ macro_rules! glib_boxed_inline_wrapper { #[doc = "Borrows the underlying C value mutably."] #[inline] + #[deprecated = "Use FromGlibBorrowMut2 trait"] pub unsafe fn from_glib_ptr_borrow_mut<'a>(ptr: *mut $ffi_name) -> &'a mut Self { debug_assert!(!ptr.is_null()); &mut *(ptr as *mut Self) @@ -229,6 +231,7 @@ macro_rules! glib_boxed_inline_wrapper { } #[inline] + #[allow(unused_unsafe)] fn to_glib_full(&self) -> *const $ffi_name { unsafe { let copy = |$copy_arg: *const $ffi_name| $copy_expr; @@ -430,6 +433,30 @@ macro_rules! glib_boxed_inline_wrapper { } } + #[doc(hidden)] + impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibPtrBorrow2<$ffi_name> for $name $(<$($generic),+>)? { + #[inline] + unsafe fn from_glib_borrow2(ptr: &$ffi_name) -> &Self { + debug_assert_eq!( + std::mem::size_of::(), + std::mem::size_of::<$ffi_name>() + ); + &*(ptr as *const $ffi_name as *const Self) + } + } + + #[doc(hidden)] + impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibPtrBorrowMut2<$ffi_name> for $name $(<$($generic),+>)? { + #[inline] + unsafe fn from_glib_borrow_mut2(ptr: &mut $ffi_name) -> &mut Self { + debug_assert_eq!( + std::mem::size_of::(), + std::mem::size_of::<$ffi_name>() + ); + &mut *(ptr as *mut $ffi_name as *mut Self) + } + } + #[doc(hidden)] impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibContainerAsVec<*mut $ffi_name, *mut $ffi_name> for $name $(<$($generic),+>)? { unsafe fn from_glib_none_num_as_vec(ptr: *mut $ffi_name, num: usize) -> Vec { @@ -593,7 +620,7 @@ macro_rules! glib_boxed_inline_wrapper { unsafe fn from_value(value: &'_ $crate::Value) -> Self { let ptr = $crate::gobject_ffi::g_value_get_boxed($crate::translate::ToGlibPtr::to_glib_none(value).0); debug_assert!(!ptr.is_null()); - &*(ptr as *const $ffi_name as *const $name $(<$($generic),+>)?) + <$name $(<$($generic),+>)? as $crate::translate::FromGlibPtrBorrow2<$ffi_name>>::from_glib_borrow2(&*(ptr as *const $ffi_name)) } } diff --git a/glib/src/gobject/interface_info.rs b/glib/src/gobject/interface_info.rs index 2db458b5dcaf..8c08ce122ca5 100644 --- a/glib/src/gobject/interface_info.rs +++ b/glib/src/gobject/interface_info.rs @@ -1,40 +1,18 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use crate::gobject_ffi; +use crate::{gobject_ffi, translate::*}; -#[derive(Debug, Copy, Clone)] -#[doc(alias = "GInterfaceInfo")] -#[repr(transparent)] -pub struct InterfaceInfo(pub(crate) gobject_ffi::GInterfaceInfo); - -impl InterfaceInfo { - // rustdoc-stripper-ignore-next - /// Returns a `GInterfaceInfo` pointer. - #[doc(hidden)] - #[inline] - pub fn as_ptr(&self) -> *mut gobject_ffi::GInterfaceInfo { - &self.0 as *const gobject_ffi::GInterfaceInfo as *mut _ - } - - // rustdoc-stripper-ignore-next - /// Borrows the underlying C value mutably. - #[doc(hidden)] - #[inline] - pub unsafe fn from_glib_ptr_borrow_mut<'a>( - ptr: *mut gobject_ffi::GInterfaceInfo, - ) -> &'a mut Self { - &mut *(ptr as *mut Self) - } +wrapper! { + #[derive(Debug)] + #[doc(alias = "GInterfaceInfo")] + pub struct InterfaceInfo(BoxedInline); } +unsafe impl Send for InterfaceInfo {} +unsafe impl Sync for InterfaceInfo {} + impl Default for InterfaceInfo { - // rustdoc-stripper-ignore-next - /// Creates a new InterfaceInfo with default value. fn default() -> Self { - Self(gobject_ffi::GInterfaceInfo { - interface_init: None, - interface_finalize: None, - interface_data: ::std::ptr::null_mut(), - }) + unsafe { Self::uninitialized() } } } diff --git a/glib/src/gobject/type_info.rs b/glib/src/gobject/type_info.rs index dd715d033275..a54b65e597ae 100644 --- a/glib/src/gobject/type_info.rs +++ b/glib/src/gobject/type_info.rs @@ -1,45 +1,18 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use crate::gobject_ffi; +use crate::{gobject_ffi, translate::*}; -#[derive(Debug, Copy, Clone)] -#[doc(alias = "GTypeInfo")] -#[repr(transparent)] -pub struct TypeInfo(pub(crate) gobject_ffi::GTypeInfo); - -impl TypeInfo { - // rustdoc-stripper-ignore-next - /// Returns a `GTypeInfo` pointer. - #[doc(hidden)] - #[inline] - pub fn as_ptr(&self) -> *mut gobject_ffi::GTypeInfo { - &self.0 as *const gobject_ffi::GTypeInfo as *mut _ - } - - // rustdoc-stripper-ignore-next - /// Borrows the underlying C value mutably. - #[doc(hidden)] - #[inline] - pub unsafe fn from_glib_ptr_borrow_mut<'a>(ptr: *mut gobject_ffi::GTypeInfo) -> &'a mut Self { - &mut *(ptr as *mut Self) - } +wrapper! { + #[derive(Debug)] + #[doc(alias = "GTypeInfo")] + pub struct TypeInfo(BoxedInline); } +unsafe impl Send for TypeInfo {} +unsafe impl Sync for TypeInfo {} + impl Default for TypeInfo { - // rustdoc-stripper-ignore-next - /// Creates a new TypeInfo with default value. fn default() -> Self { - Self(gobject_ffi::GTypeInfo { - class_size: 0u16, - base_init: None, - base_finalize: None, - class_init: None, - class_finalize: None, - class_data: ::std::ptr::null(), - instance_size: 0, - n_preallocs: 0, - instance_init: None, - value_table: ::std::ptr::null(), - }) + unsafe { Self::uninitialized() } } } diff --git a/glib/src/gobject/type_value_table.rs b/glib/src/gobject/type_value_table.rs index bb664063885a..fed97e8935db 100644 --- a/glib/src/gobject/type_value_table.rs +++ b/glib/src/gobject/type_value_table.rs @@ -1,45 +1,18 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use crate::gobject_ffi; +use crate::{gobject_ffi, translate::*}; -#[derive(Debug, Copy, Clone)] -#[doc(alias = "GTypeValueTable")] -#[repr(transparent)] -pub struct TypeValueTable(pub(crate) gobject_ffi::GTypeValueTable); - -impl TypeValueTable { - // rustdoc-stripper-ignore-next - /// Returns a `GTypeValueTable` pointer. - #[doc(hidden)] - #[inline] - pub fn as_ptr(&self) -> *mut gobject_ffi::GTypeValueTable { - &self.0 as *const gobject_ffi::GTypeValueTable as *mut _ - } - - // rustdoc-stripper-ignore-next - /// Borrows the underlying C value mutably. - #[doc(hidden)] - #[inline] - pub unsafe fn from_glib_ptr_borrow_mut<'a>( - ptr: *mut gobject_ffi::GTypeValueTable, - ) -> &'a mut Self { - &mut *(ptr as *mut Self) - } +wrapper! { + #[derive(Debug)] + #[doc(alias = "GTypeValueTable")] + pub struct TypeValueTable(BoxedInline); } +unsafe impl Send for TypeValueTable {} +unsafe impl Sync for TypeValueTable {} + impl Default for TypeValueTable { - // rustdoc-stripper-ignore-next - /// Creates a new TypeValueTable with default value. fn default() -> Self { - Self(gobject_ffi::GTypeValueTable { - value_init: None, - value_free: None, - value_copy: None, - value_peek_pointer: None, - collect_format: ::std::ptr::null(), - collect_value: None, - lcopy_format: ::std::ptr::null(), - lcopy_value: None, - }) + unsafe { Self::uninitialized() } } } diff --git a/glib/src/match_info.rs b/glib/src/match_info.rs index 69f24ca1f1c0..66fbcd65bd0d 100644 --- a/glib/src/match_info.rs +++ b/glib/src/match_info.rs @@ -36,16 +36,6 @@ impl MatchInfo<'_> { pub fn as_ptr(&self) -> *mut ffi::GMatchInfo { self.inner.as_ptr() } - #[doc = "Borrows the underlying C value."] - #[inline] - pub unsafe fn from_glib_ptr_borrow(ptr: &*mut ffi::GMatchInfo) -> &Self { - debug_assert_eq!( - std::mem::size_of::(), - std::mem::size_of::() - ); - debug_assert!(!ptr.is_null()); - &*(ptr as *const *mut ffi::GMatchInfo as *const Self) - } } #[doc(hidden)] @@ -149,6 +139,32 @@ impl FromGlibPtrBorrow<*const ffi::GMatchInfo> for MatchInfo<'_> { } } +impl<'a> FromGlibPtrBorrow2<*mut ffi::GMatchInfo> for MatchInfo<'a> { + #[doc = "Borrows the underlying C value."] + #[inline] + unsafe fn from_glib_borrow2(ptr: &*mut ffi::GMatchInfo) -> &Self { + debug_assert_eq!( + std::mem::size_of::(), + std::mem::size_of::() + ); + debug_assert!(!ptr.is_null()); + &*(ptr as *const *mut ffi::GMatchInfo as *const Self) + } +} + +impl<'a> FromGlibPtrBorrow2<*const ffi::GMatchInfo> for MatchInfo<'a> { + #[doc = "Borrows the underlying C value."] + #[inline] + unsafe fn from_glib_borrow2(ptr: &*const ffi::GMatchInfo) -> &Self { + debug_assert_eq!( + std::mem::size_of::(), + std::mem::size_of::() + ); + debug_assert!(!ptr.is_null()); + &*(ptr as *const *const ffi::GMatchInfo as *const Self) + } +} + #[doc(hidden)] impl IntoGlibPtr<*mut ffi::GMatchInfo> for MatchInfo<'_> { #[inline] @@ -200,7 +216,7 @@ unsafe impl<'a, 'input: 'a> crate::value::FromValue<'a> for &'a MatchInfo<'input #[inline] unsafe fn from_value(value: &'a crate::Value) -> Self { let value = &*(value as *const crate::Value as *const crate::gobject_ffi::GValue); - >::from_glib_ptr_borrow( + >::from_glib_borrow2( &*(&value.data[0].v_pointer as *const crate::ffi::gpointer as *const *mut ffi::GMatchInfo), ) diff --git a/glib/src/object.rs b/glib/src/object.rs index 22637311b59d..cc8ae2c2cb8f 100644 --- a/glib/src/object.rs +++ b/glib/src/object.rs @@ -36,6 +36,7 @@ pub unsafe trait ObjectType: + crate::value::FromValueOptional<'static> + for<'a> ToGlibPtr<'a, *mut ::GlibType> + IntoGlibPtr<*mut ::GlibType> + + FromGlibPtrBorrow2<*mut ::GlibType> + 'static { // rustdoc-stripper-ignore-next @@ -48,6 +49,7 @@ pub unsafe trait ObjectType: fn as_object_ref(&self) -> &ObjectRef; fn as_ptr(&self) -> *mut Self::GlibType; + #[deprecated = "Use FromGlibBorrow2 trait"] unsafe fn from_glib_ptr_borrow(ptr: &*mut Self::GlibType) -> &Self; } @@ -958,6 +960,34 @@ macro_rules! glib_object_wrapper { } } + #[doc(hidden)] + impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibPtrBorrow2<*mut $ffi_name> for $name $(<$($generic),+>)? { + #[inline] + unsafe fn from_glib_borrow2(ptr: &*mut $ffi_name) -> &Self { + debug_assert_eq!( + std::mem::size_of::(), + std::mem::size_of::<$crate::ffi::gpointer>() + ); + debug_assert!(!ptr.is_null()); + debug_assert_ne!((*(*ptr as *const $crate::gobject_ffi::GObject)).ref_count, 0); + &*(ptr as *const *mut $ffi_name as *const Self) + } + } + + #[doc(hidden)] + impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibPtrBorrow2<*const $ffi_name> for $name $(<$($generic),+>)? { + #[inline] + unsafe fn from_glib_borrow2(ptr: &*const $ffi_name) -> &Self { + debug_assert_eq!( + std::mem::size_of::(), + std::mem::size_of::<$crate::ffi::gpointer>() + ); + debug_assert!(!ptr.is_null()); + debug_assert_ne!((*(*ptr as *const $crate::gobject_ffi::GObject)).ref_count, 0); + &*(ptr as *const *const $ffi_name as *const Self) + } + } + #[doc(hidden)] impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name> for $name $(<$($generic),+>)? { unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec { @@ -1081,7 +1111,7 @@ macro_rules! glib_object_wrapper { #[inline] unsafe fn from_value(value: &'a $crate::Value) -> Self { let value = &*(value as *const $crate::Value as *const $crate::gobject_ffi::GValue); - <$name $(<$($generic),+>)? as $crate::object::ObjectType>::from_glib_ptr_borrow(&*(&value.data[0].v_pointer as *const $crate::ffi::gpointer as *const *mut $ffi_name)) + <$name $(<$($generic),+>)? as $crate::translate::FromGlibPtrBorrow2<*mut $ffi_name>>::from_glib_borrow2(&*(&value.data[0].v_pointer as *const $crate::ffi::gpointer as *const *mut $ffi_name)) } } diff --git a/glib/src/shared.rs b/glib/src/shared.rs index 4282780fb284..eecc965f3ba6 100644 --- a/glib/src/shared.rs +++ b/glib/src/shared.rs @@ -45,6 +45,7 @@ macro_rules! glib_shared_wrapper { #[doc = "Borrows the underlying C value."] #[inline] + #[deprecated = "Use FromGlibBorrow2 trait"] pub unsafe fn from_glib_ptr_borrow(ptr: &*mut $ffi_name) -> &Self { debug_assert_eq!( std::mem::size_of::(), @@ -234,6 +235,32 @@ macro_rules! glib_shared_wrapper { } } + #[doc(hidden)] + impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibPtrBorrow2<*mut $ffi_name> for $name $(<$($generic),+>)? { + #[inline] + unsafe fn from_glib_borrow2(ptr: &*mut $ffi_name) -> &Self { + debug_assert_eq!( + std::mem::size_of::(), + std::mem::size_of::<$crate::ffi::gpointer>() + ); + debug_assert!(!ptr.is_null()); + &*(ptr as *const *mut $ffi_name as *const Self) + } + } + + #[doc(hidden)] + impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibPtrBorrow2<*const $ffi_name> for $name $(<$($generic),+>)? { + #[inline] + unsafe fn from_glib_borrow2(ptr: &*const $ffi_name) -> &Self { + debug_assert_eq!( + std::mem::size_of::(), + std::mem::size_of::<$crate::ffi::gpointer>() + ); + debug_assert!(!ptr.is_null()); + &*(ptr as *const *const $ffi_name as *const Self) + } + } + #[doc(hidden)] impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::translate::FromGlibContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name> for $name $(<$($generic),+>)? { unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec { @@ -378,7 +405,7 @@ macro_rules! glib_shared_wrapper { #[inline] unsafe fn from_value(value: &'a $crate::Value) -> Self { let value = &*(value as *const $crate::Value as *const $crate::gobject_ffi::GValue); - <$name $(<$($generic),+>)?>::from_glib_ptr_borrow(&*(&value.data[0].v_pointer as *const $crate::ffi::gpointer as *const *mut $ffi_name)) + <$name $(<$($generic),+>)? as $crate::translate::FromGlibPtrBorrow2<*mut $ffi_name>>::from_glib_borrow2(&*(&value.data[0].v_pointer as *const $crate::ffi::gpointer as *const *mut $ffi_name)) } } diff --git a/glib/src/subclass/interface.rs b/glib/src/subclass/interface.rs index d9e490d2b60b..d23ef2c8a09d 100644 --- a/glib/src/subclass/interface.rs +++ b/glib/src/subclass/interface.rs @@ -287,10 +287,10 @@ pub fn register_dynamic_interface() as u16, class_init: Some(interface_init::), - ..TypeInfo::default().0 + ..TypeInfo::default().inner }); // registers the interface within the `type_plugin` diff --git a/glib/src/subclass/type_plugin.rs b/glib/src/subclass/type_plugin.rs index 78e2c2e6b544..4db72486c3ff 100644 --- a/glib/src/subclass/type_plugin.rs +++ b/glib/src/subclass/type_plugin.rs @@ -149,8 +149,8 @@ unsafe extern "C" fn complete_type_info( let instance = &*(type_plugin as *mut T::Instance); let imp = instance.imp(); let type_ = Type::from_glib(gtype); - let info = TypeInfo::from_glib_ptr_borrow_mut(info_ptr); - let value_table = TypeValueTable::from_glib_ptr_borrow_mut(value_table_ptr); + let info = TypeInfo::from_glib_borrow_mut2(&mut *info_ptr); + let value_table = TypeValueTable::from_glib_borrow_mut2(&mut *value_table_ptr); let (info_, value_table_) = imp.complete_type_info(type_); @@ -169,7 +169,7 @@ unsafe extern "C" fn complete_interface_info( let imp = instance.imp(); let instance_type = Type::from_glib(instance_gtype); let interface_type = Type::from_glib(interface_gtype); - let info = InterfaceInfo::from_glib_ptr_borrow_mut(info_ptr); + let info = InterfaceInfo::from_glib_borrow_mut2(&mut *info_ptr); let info_ = imp.complete_interface_info(instance_type, interface_type); *info = info_; diff --git a/glib/src/subclass/types.rs b/glib/src/subclass/types.rs index bf2e0c6af17e..5915f21d3fdd 100644 --- a/glib/src/subclass/types.rs +++ b/glib/src/subclass/types.rs @@ -368,13 +368,12 @@ where ::GlibClassType: Copy, { fn iface_infos() -> Vec<(Type, InterfaceInfo)> { - vec![( - A::static_type(), - InterfaceInfo(gobject_ffi::GInterfaceInfo { + vec![(A::static_type(), unsafe { + InterfaceInfo::unsafe_from(gobject_ffi::GInterfaceInfo { interface_init: Some(interface_init::), - ..InterfaceInfo::default().0 - }), - )] + ..InterfaceInfo::default().inner + }) + })] } #[inline] @@ -413,11 +412,13 @@ macro_rules! interface_list_trait_impl( $( ( $name::static_type(), - InterfaceInfo(gobject_ffi::GInterfaceInfo { - interface_init: Some(interface_init::), - interface_finalize: None, - interface_data: ptr::null_mut(), - }), + unsafe { + InterfaceInfo::unsafe_from(gobject_ffi::GInterfaceInfo { + interface_init: Some(interface_init::), + interface_finalize: None, + interface_data: ptr::null_mut(), + }) + }, ) ),+ ] @@ -1122,12 +1123,12 @@ pub fn register_dynamic_type( let already_registered = gobject_ffi::g_type_from_name(type_name.as_ptr()) != gobject_ffi::G_TYPE_INVALID; - let type_info = TypeInfo(gobject_ffi::GTypeInfo { + let type_info = TypeInfo::unsafe_from(gobject_ffi::GTypeInfo { class_size: mem::size_of::() as u16, class_init: Some(class_init::), instance_size: mem::size_of::() as u16, instance_init: Some(instance_init::), - ..TypeInfo::default().0 + ..TypeInfo::default().inner }); // registers the type within the `type_plugin` diff --git a/glib/src/translate.rs b/glib/src/translate.rs index 60a446b1c330..ae2df6458e76 100644 --- a/glib/src/translate.rs +++ b/glib/src/translate.rs @@ -1587,7 +1587,7 @@ pub trait FromGlibPtrFull: Sized { } // rustdoc-stripper-ignore-next -/// Translate from a pointer type by borrowing, without affecting the refcount. +/// Translate from a pointer type by borrowing, without affecting the refcount or copying. /// /// The purpose of this trait is to access values inside callbacks /// without changing their reference status. @@ -1621,6 +1621,64 @@ pub trait FromGlibPtrBorrow: Sized { } } +// rustdoc-stripper-ignore-next +/// Translate from a pointer type by borrowing, without affecting the refcount or copying. +/// +/// The purpose of this trait is to access values inside callbacks +/// without changing their reference status. +/// The obtained borrow must not be accessed outside of the scope of the callback, +/// and called procedures must not store any references to the underlying data. +/// Safe Rust code must never obtain a mutable Rust reference. +/// +/// +/// # Safety +/// +/// The implementation of this trait as well as the returned type +/// must satisfy the same constraints together. +/// They must not take ownership of the underlying value, copy it, +/// and should not change its reference count. +/// If it does, it must properly release obtained references. +/// +/// For more information, refer to module level documentation. +// FIXME: Rename to FromGlibPtrBorrow once all users are gone +pub trait FromGlibPtrBorrow2

: Sized { + // rustdoc-stripper-ignore-next + /// # Safety + /// + /// See trait level [notes on safety](#safety_points) + unsafe fn from_glib_borrow2(_ptr: &P) -> &Self { + unimplemented!(); + } +} + +// rustdoc-stripper-ignore-next +/// Translate from a pointer type by borrowing mutably, without affecting the refcount or copying. +/// +/// The purpose of this trait is to access values inside callbacks +/// without changing their reference status. +/// The obtained borrow must not be accessed outside of the scope of the callback, +/// and called procedures must not store any references to the underlying data. +/// +/// +/// # Safety +/// +/// The implementation of this trait as well as the returned type +/// must satisfy the same constraints together. +/// They must not take ownership of the underlying value, copy it, +/// and should not change its reference count. +/// +/// For more information, refer to module level documentation. +// FIXME: Rename to FromGlibPtrBorrowMut once all users are gone +pub trait FromGlibPtrBorrowMut2

: Sized { + // rustdoc-stripper-ignore-next + /// # Safety + /// + /// See trait level [notes on safety](#safety_points) + unsafe fn from_glib_borrow_mut2(_ptr: &mut P) -> &mut Self { + unimplemented!(); + } +} + // rustdoc-stripper-ignore-next /// Translate from a pointer type, transfer: none. /// @@ -1648,6 +1706,24 @@ pub unsafe fn from_glib_borrow>(ptr: P) -> Borro FromGlibPtrBorrow::from_glib_borrow(ptr) } +// rustdoc-stripper-ignore-next +/// Translate from a pointer type, borrowing the pointer. +/// +/// See [`FromGlibPtrBorrow2`](trait.FromGlibPtrBorrow2.html). +#[inline] +pub unsafe fn from_glib_borrow2>(ptr: &P) -> &T { + FromGlibPtrBorrow2::from_glib_borrow2(ptr) +} + +// rustdoc-stripper-ignore-next +/// Translate from a pointer type, borrowing the pointer mutable. +/// +/// See [`FromGlibPtrBorrowMut2`](trait.FromGlibPtrBorrowMut2.html). +#[inline] +pub unsafe fn from_glib_borrow_mut2>(ptr: &mut P) -> &mut T { + FromGlibPtrBorrowMut2::from_glib_borrow_mut2(ptr) +} + impl> FromGlibPtrNone

for Option { #[inline] unsafe fn from_glib_none(ptr: P) -> Option { diff --git a/glib/src/value_array.rs b/glib/src/value_array.rs index 3051e1872c09..2656e29f2f3f 100644 --- a/glib/src/value_array.rs +++ b/glib/src/value_array.rs @@ -244,7 +244,7 @@ unsafe impl<'a> crate::value::FromValue<'a> for &'a ValueArray { ); let value = &*(value as *const Value as *const gobject_ffi::GValue); debug_assert!(!value.data[0].v_pointer.is_null()); - ::from_glib_ptr_borrow( + ::from_glib_borrow2( &*(&value.data[0].v_pointer as *const ffi::gpointer as *const *mut gobject_ffi::GValueArray), )