Skip to content

Commit

Permalink
add as_ptr() and from_glib_ptr_borrow_mut() to TypeInfo, InterfaceInf…
Browse files Browse the repository at this point in the history
…o, TypeValueTable

Signed-off-by: fbrouille <[email protected]>
  • Loading branch information
fbrouille committed Sep 7, 2023
1 parent 05c4b24 commit f1eac51
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 16 deletions.
22 changes: 21 additions & 1 deletion glib/src/gobject/interface_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,24 @@
#[derive(Debug)]
#[doc(alias = "GInterfaceInfo")]
#[repr(transparent)]
pub struct InterfaceInfo(pub gobject_ffi::GInterfaceInfo);
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)
}
}
20 changes: 19 additions & 1 deletion glib/src/gobject/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,22 @@
#[derive(Debug)]
#[doc(alias = "GTypeInfo")]
#[repr(transparent)]
pub struct TypeInfo(pub gobject_ffi::GTypeInfo);
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)
}
}
4 changes: 2 additions & 2 deletions glib/src/gobject/type_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub trait TypeModuleExt: IsA<TypeModule> + sealed::Sealed + 'static {
self.as_ref().to_glib_none().0,
instance_type.into_glib(),
interface_type.into_glib(),
&interface_info.0 as *const _ as *mut _,
interface_info.as_ptr(),
);
}
}
Expand Down Expand Up @@ -78,7 +78,7 @@ pub trait TypeModuleExt: IsA<TypeModule> + sealed::Sealed + 'static {
self.as_ref().to_glib_none().0,
parent_type.into_glib(),
type_name.to_glib_none().0,
&type_info.0 as *const _ as *mut _,
type_info.as_ptr(),
flags.into_glib(),
))
}
Expand Down
6 changes: 3 additions & 3 deletions glib/src/gobject/type_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub trait TypePluginExt: IsA<TypePlugin> + sealed::Sealed + 'static {
self.as_ref().to_glib_none().0,
instance_type.into_glib(),
interface_type.into_glib(),
&info.0 as *const _ as *mut _,
info.as_ptr(),
);
}
}
Expand All @@ -52,8 +52,8 @@ pub trait TypePluginExt: IsA<TypePlugin> + sealed::Sealed + 'static {
gobject_ffi::g_type_plugin_complete_type_info(
self.as_ref().to_glib_none().0,
g_type.into_glib(),
&info.0 as *const _ as *mut _,
&value_table.0 as *const _ as *mut _,
info.as_ptr(),
value_table.as_ptr(),
);
}
}
Expand Down
22 changes: 21 additions & 1 deletion glib/src/gobject/type_value_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,24 @@
#[derive(Debug)]
#[doc(alias = "GTypeValueTable")]
#[repr(transparent)]
pub struct TypeValueTable(pub gobject_ffi::GTypeValueTable);
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)
}
}
12 changes: 6 additions & 6 deletions glib/src/subclass/type_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ impl<T: TypePluginImpl> TypePluginImplExt for T {
f(
self.obj().unsafe_cast_ref::<TypePlugin>().to_glib_none().0,
type_.into_glib(),
&info.0 as *const _ as *mut _,
&value_table.0 as *const _ as *mut _,
info.as_ptr(),
value_table.as_ptr(),
)
}
}
Expand All @@ -124,7 +124,7 @@ impl<T: TypePluginImpl> TypePluginImplExt for T {
self.obj().unsafe_cast_ref::<TypePlugin>().to_glib_none().0,
instance_type.into_glib(),
interface_type.into_glib(),
&info.0 as *const _ as *mut _,
info.as_ptr(),
)
}
}
Expand Down Expand Up @@ -164,8 +164,8 @@ unsafe extern "C" fn complete_type_info<T: TypePluginImpl>(
let instance = &*(type_plugin as *mut T::Instance);
let imp = instance.imp();
let type_ = Type::from_glib(gtype);
let info: &mut TypeInfo = &mut *(info_ptr as *mut _);
let value_table: &mut TypeValueTable = &mut *(value_table_ptr as *mut _);
let info = TypeInfo::from_glib_ptr_borrow_mut(info_ptr);
let value_table = TypeValueTable::from_glib_ptr_borrow_mut(value_table_ptr);

imp.complete_type_info(type_, info, value_table);
}
Expand All @@ -180,7 +180,7 @@ unsafe extern "C" fn complete_interface_info<T: TypePluginImpl>(
let imp = instance.imp();
let instance_type = Type::from_glib(instance_gtype);
let interface_type = Type::from_glib(interface_gtype);
let info: &mut InterfaceInfo = &mut *(info_ptr as *mut _);
let info = InterfaceInfo::from_glib_ptr_borrow_mut(info_ptr);

imp.complete_interface_info(instance_type, interface_type, info);
}
4 changes: 2 additions & 2 deletions glib/src/subclass/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ pub fn register_type<T: ObjectSubclass>() -> Type {
gobject_ffi::g_type_add_interface_static(
type_.into_glib(),
iface_type.into_glib(),
&iface_info.0 as *const _ as *mut _,
iface_info.as_ptr(),
);
}

Expand Down Expand Up @@ -1136,7 +1136,7 @@ pub fn register_module_type<T: ObjectSubclass>(type_module: &TypeModule) -> Type
gobject_ffi::g_type_add_interface_static(
type_.into_glib(),
iface_type.into_glib(),
&iface_info.0 as *const _ as *mut _,
iface_info.as_ptr(),
);
}
}
Expand Down

0 comments on commit f1eac51

Please sign in to comment.