Skip to content

Commit

Permalink
simple implementation of InterfaceInfo, TypeInfo and TypeValueTable
Browse files Browse the repository at this point in the history
Signed-off-by: fbrouille <[email protected]>
  • Loading branch information
fbrouille committed Aug 30, 2023
1 parent ef9971e commit d631c13
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 275 deletions.
4 changes: 2 additions & 2 deletions glib/Gir_GObject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ generate = [
"GObject.BindingFlags",
"GObject.SignalFlags",
"GObject.TypeFlags",
"GObject.TypePlugin",
"GObject.TypeModule",
]

ignore = [
Expand Down Expand Up @@ -56,6 +54,8 @@ manual = [
"GObject.ParamSpecVariant",
"GObject.InterfaceInfo",
"GObject.TypeInfo",
"GObject.TypePlugin",
"GObject.TypeModule",
]

[[object]]
Expand Down
12 changes: 0 additions & 12 deletions glib/src/gobject/auto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,7 @@ mod signal_group;
#[cfg_attr(docsrs, doc(cfg(feature = "v2_74")))]
pub use self::signal_group::SignalGroup;

mod type_module;
pub use self::type_module::TypeModule;

mod type_plugin;
pub use self::type_plugin::TypePlugin;

mod flags;
pub use self::flags::BindingFlags;
pub use self::flags::SignalFlags;
pub use self::flags::TypeFlags;

#[doc(hidden)]
pub mod traits {
pub use super::type_module::TypeModuleExt;
pub use super::type_plugin::TypePluginExt;
}
80 changes: 1 addition & 79 deletions glib/src/gobject/interface_info.rs
Original file line number Diff line number Diff line change
@@ -1,84 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::translate::{
FromGlib, FromGlibPtrNone, IntoGlib, Stash, StashMut, ToGlibPtr, ToGlibPtrMut,
};

#[derive(Debug)]
#[doc(alias = "GInterfaceInfo")]
#[repr(transparent)]
pub struct InterfaceInfo(gobject_ffi::GInterfaceInfo);

impl InterfaceInfo {
#[inline]
pub fn as_ptr(&self) -> *mut gobject_ffi::GInterfaceInfo {
&self.0 as *const gobject_ffi::GInterfaceInfo as *mut _
}

#[doc = "Borrows the underlying C value."]
#[inline]
pub unsafe fn from_glib_ptr_borrow<'a>(ptr: *const gobject_ffi::GInterfaceInfo) -> &'a Self {
&*(ptr as *const Self)
}

#[doc = "Borrows the underlying C value mutably."]
#[inline]
pub unsafe fn from_glib_ptr_borrow_mut<'a>(
ptr: *mut gobject_ffi::GInterfaceInfo,
) -> &'a mut Self {
&mut *(ptr as *mut Self)
}
}

#[doc(hidden)]
impl IntoGlib for InterfaceInfo {
type GlibType = gobject_ffi::GInterfaceInfo;

#[inline]
fn into_glib(self) -> Self::GlibType {
self.0
}
}

#[doc(hidden)]
impl FromGlib<gobject_ffi::GInterfaceInfo> for InterfaceInfo {
#[inline]
unsafe fn from_glib(val: gobject_ffi::GInterfaceInfo) -> Self {
Self(val)
}
}

#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const gobject_ffi::GInterfaceInfo> for InterfaceInfo {
type Storage = ();

#[inline]
fn to_glib_none(&'a self) -> Stash<'a, *const gobject_ffi::GInterfaceInfo, Self> {
Stash(self.as_ptr() as *const _, ())
}
}

#[doc(hidden)]
impl<'a> ToGlibPtrMut<'a, *mut gobject_ffi::GInterfaceInfo> for InterfaceInfo {
type Storage = ();

#[inline]
fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut gobject_ffi::GInterfaceInfo, Self> {
StashMut(self.as_ptr(), ())
}
}

#[doc(hidden)]
impl FromGlibPtrNone<*mut gobject_ffi::GInterfaceInfo> for InterfaceInfo {
unsafe fn from_glib_none(ptr: *mut gobject_ffi::GInterfaceInfo) -> Self {
debug_assert!(!ptr.is_null());
Self(*ptr)
}
}

#[doc(hidden)]
impl FromGlibPtrNone<*const gobject_ffi::GInterfaceInfo> for InterfaceInfo {
unsafe fn from_glib_none(ptr: *const gobject_ffi::GInterfaceInfo) -> Self {
<Self as FromGlibPtrNone<_>>::from_glib_none(ptr as *mut gobject_ffi::GInterfaceInfo)
}
}
pub struct InterfaceInfo(pub gobject_ffi::GInterfaceInfo);
20 changes: 16 additions & 4 deletions glib/src/gobject/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,23 @@ pub use binding_group::BindingGroupBuilder;
pub use self::{auto::*, flags::*};
//pub use self::auto::functions::*;

mod type_value_table;
pub use type_value_table::TypeValueTable;
mod interface_info;
pub use interface_info::InterfaceInfo;

mod type_info;
pub use type_info::TypeInfo;

mod interface_info;
pub use interface_info::InterfaceInfo;
mod type_value_table;
pub use type_value_table::TypeValueTable;

mod type_module;
pub use self::type_module::TypeModule;

mod type_plugin;
pub use self::type_plugin::TypePlugin;

#[doc(hidden)]
pub mod traits {
pub use super::type_module::TypeModuleExt;
pub use super::type_plugin::TypePluginExt;
}
78 changes: 1 addition & 77 deletions glib/src/gobject/type_info.rs
Original file line number Diff line number Diff line change
@@ -1,82 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::translate::{
FromGlib, FromGlibPtrNone, IntoGlib, Stash, StashMut, ToGlibPtr, ToGlibPtrMut,
};

#[derive(Debug)]
#[doc(alias = "GTypeInfo")]
#[repr(transparent)]
pub struct TypeInfo(gobject_ffi::GTypeInfo);

impl TypeInfo {
#[inline]
pub fn as_ptr(&self) -> *mut gobject_ffi::GTypeInfo {
&self.0 as *const gobject_ffi::GTypeInfo as *mut _
}

#[doc = "Borrows the underlying C value."]
#[inline]
pub unsafe fn from_glib_ptr_borrow<'a>(ptr: *const gobject_ffi::GTypeInfo) -> &'a Self {
&*(ptr as *const Self)
}

#[doc = "Borrows the underlying C value mutably."]
#[inline]
pub unsafe fn from_glib_ptr_borrow_mut<'a>(ptr: *mut gobject_ffi::GTypeInfo) -> &'a mut Self {
&mut *(ptr as *mut Self)
}
}

#[doc(hidden)]
impl IntoGlib for TypeInfo {
type GlibType = gobject_ffi::GTypeInfo;

#[inline]
fn into_glib(self) -> Self::GlibType {
self.0
}
}

#[doc(hidden)]
impl FromGlib<gobject_ffi::GTypeInfo> for TypeInfo {
#[inline]
unsafe fn from_glib(val: gobject_ffi::GTypeInfo) -> Self {
Self(val)
}
}

#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const gobject_ffi::GTypeInfo> for TypeInfo {
type Storage = ();

#[inline]
fn to_glib_none(&'a self) -> Stash<'a, *const gobject_ffi::GTypeInfo, Self> {
Stash(self.as_ptr() as *const _, ())
}
}

#[doc(hidden)]
impl<'a> ToGlibPtrMut<'a, *mut gobject_ffi::GTypeInfo> for TypeInfo {
type Storage = ();

#[inline]
fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut gobject_ffi::GTypeInfo, Self> {
StashMut(self.as_ptr(), ())
}
}

#[doc(hidden)]
impl FromGlibPtrNone<*mut gobject_ffi::GTypeInfo> for TypeInfo {
unsafe fn from_glib_none(ptr: *mut gobject_ffi::GTypeInfo) -> Self {
debug_assert!(!ptr.is_null());
Self(*ptr)
}
}

#[doc(hidden)]
impl FromGlibPtrNone<*const gobject_ffi::GTypeInfo> for TypeInfo {
unsafe fn from_glib_none(ptr: *const gobject_ffi::GTypeInfo) -> Self {
<Self as FromGlibPtrNone<_>>::from_glib_none(ptr as *mut gobject_ffi::GTypeInfo)
}
}
pub struct TypeInfo(pub gobject_ffi::GTypeInfo);
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.to_glib_none().0,
&interface_info.0 as *const _ as *mut _,
);
}
}
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.to_glib_none().0,
&type_info.0 as *const _ as *mut _,
flags.into_glib(),
))
}
Expand Down
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.to_glib_none_mut().0,
&info.0 as *const _ as *mut _,
);
}
}
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.to_glib_none_mut().0,
value_table.to_glib_none_mut().0,
&info.0 as *const _ as *mut _,
&value_table.0 as *const _ as *mut _,
);
}
}
Expand Down
80 changes: 1 addition & 79 deletions glib/src/gobject/type_value_table.rs
Original file line number Diff line number Diff line change
@@ -1,84 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::translate::{
FromGlib, FromGlibPtrNone, IntoGlib, Stash, StashMut, ToGlibPtr, ToGlibPtrMut,
};

#[derive(Debug)]
#[doc(alias = "GTypeValueTable")]
#[repr(transparent)]
pub struct TypeValueTable(gobject_ffi::GTypeValueTable);

impl TypeValueTable {
#[inline]
pub fn as_ptr(&self) -> *mut gobject_ffi::GTypeValueTable {
&self.0 as *const gobject_ffi::GTypeValueTable as *mut _
}

#[doc = "Borrows the underlying C value."]
#[inline]
pub unsafe fn from_glib_ptr_borrow<'a>(ptr: *const gobject_ffi::GTypeValueTable) -> &'a Self {
&*(ptr as *const Self)
}

#[doc = "Borrows the underlying C value mutably."]
#[inline]
pub unsafe fn from_glib_ptr_borrow_mut<'a>(
ptr: *mut gobject_ffi::GTypeValueTable,
) -> &'a mut Self {
&mut *(ptr as *mut Self)
}
}

#[doc(hidden)]
impl IntoGlib for TypeValueTable {
type GlibType = gobject_ffi::GTypeValueTable;

#[inline]
fn into_glib(self) -> Self::GlibType {
self.0
}
}

#[doc(hidden)]
impl FromGlib<gobject_ffi::GTypeValueTable> for TypeValueTable {
#[inline]
unsafe fn from_glib(val: gobject_ffi::GTypeValueTable) -> Self {
Self(val)
}
}

#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const gobject_ffi::GTypeValueTable> for TypeValueTable {
type Storage = ();

#[inline]
fn to_glib_none(&'a self) -> Stash<'a, *const gobject_ffi::GTypeValueTable, Self> {
Stash(self.as_ptr() as *const _, ())
}
}

#[doc(hidden)]
impl<'a> ToGlibPtrMut<'a, *mut gobject_ffi::GTypeValueTable> for TypeValueTable {
type Storage = ();

#[inline]
fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut gobject_ffi::GTypeValueTable, Self> {
StashMut(self.as_ptr(), ())
}
}

#[doc(hidden)]
impl FromGlibPtrNone<*mut gobject_ffi::GTypeValueTable> for TypeValueTable {
unsafe fn from_glib_none(ptr: *mut gobject_ffi::GTypeValueTable) -> Self {
debug_assert!(!ptr.is_null());
Self(*ptr)
}
}

#[doc(hidden)]
impl FromGlibPtrNone<*const gobject_ffi::GTypeValueTable> for TypeValueTable {
unsafe fn from_glib_none(ptr: *const gobject_ffi::GTypeValueTable) -> Self {
<Self as FromGlibPtrNone<_>>::from_glib_none(ptr as *mut gobject_ffi::GTypeValueTable)
}
}
pub struct TypeValueTable(pub gobject_ffi::GTypeValueTable);
2 changes: 1 addition & 1 deletion glib/src/subclass/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ pub fn register_module_interface<T: ObjectInterface>(type_module: &TypeModule) -
let already_registered =
gobject_ffi::g_type_from_name(type_name.as_ptr()) != gobject_ffi::G_TYPE_INVALID;

let type_info = TypeInfo::from_glib(gobject_ffi::GTypeInfo {
let type_info = TypeInfo(gobject_ffi::GTypeInfo {
class_size: mem::size_of::<T>() as u16,
base_init: None,
base_finalize: None,
Expand Down
Loading

0 comments on commit d631c13

Please sign in to comment.