Skip to content

Commit

Permalink
Merge pull request #1233 from sdroege/simplify-pointer-casts
Browse files Browse the repository at this point in the history
Simplify pointer casts
  • Loading branch information
sdroege committed Nov 29, 2023
2 parents d350915 + f49c2c0 commit a0d5234
Show file tree
Hide file tree
Showing 27 changed files with 58 additions and 63 deletions.
3 changes: 1 addition & 2 deletions cairo/src/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ gvalue_impl_inline!(
impl Rectangle {
#[inline]
pub fn to_raw_none(&self) -> *mut ffi::cairo_rectangle_t {
let ptr = self as *const Rectangle as usize;
ptr as *mut ffi::cairo_rectangle_t
&self.0 as *const ffi::cairo_rectangle_t as *mut ffi::cairo_rectangle_t
}
}

Expand Down
3 changes: 1 addition & 2 deletions cairo/src/rectangle_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ gvalue_impl_inline!(
impl RectangleInt {
#[inline]
pub fn to_raw_none(&self) -> *mut ffi::cairo_rectangle_int_t {
let ptr = self as *const RectangleInt as usize;
ptr as *mut ffi::cairo_rectangle_int_t
&self.0 as *const ffi::cairo_rectangle_int_t as *mut ffi::cairo_rectangle_int_t
}
}
4 changes: 2 additions & 2 deletions gdk-pixbuf/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions gdk-pixbuf/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
9 changes: 3 additions & 6 deletions gio/src/auto/desktop_app_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ impl DesktopAppInfo {
) -> Result<(), glib::Error> {
let user_setup_data: Box_<Option<Box_<dyn FnOnce() + 'static>>> = Box_::new(user_setup);
unsafe extern "C" fn user_setup_func(data: glib::ffi::gpointer) {
let callback: Box_<Option<Box_<dyn FnOnce() + 'static>>> =
Box_::from_raw(data as *mut _);
let callback = Box_::from_raw(data as *mut Option<Box_<dyn FnOnce() + 'static>>);
let callback = (*callback).expect("cannot get closure...");
callback()
}
Expand All @@ -227,9 +226,7 @@ impl DesktopAppInfo {
) {
let appinfo = from_glib_borrow(appinfo);
let pid = from_glib(pid);
let callback: *mut Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))> =
user_data as *const _ as usize
as *mut Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))>;
let callback = user_data as *mut Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))>;
if let Some(ref mut callback) = *callback {
callback(&appinfo, pid)
} else {
Expand All @@ -254,7 +251,7 @@ impl DesktopAppInfo {
user_setup,
Box_::into_raw(super_callback0) as *mut _,
pid_callback,
super_callback1 as *const _ as usize as *mut _,
super_callback1 as *const _ as *mut _,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
Expand Down
10 changes: 4 additions & 6 deletions gio/src/auto/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ pub trait FileExt: IsA<File> + sealed::Sealed + 'static {
total_num_bytes: i64,
data: glib::ffi::gpointer,
) {
let callback: *mut Option<&mut dyn (FnMut(i64, i64))> =
data as *const _ as usize as *mut Option<&mut dyn (FnMut(i64, i64))>;
let callback = data as *mut Option<&mut dyn (FnMut(i64, i64))>;
if let Some(ref mut callback) = *callback {
callback(current_num_bytes, total_num_bytes)
} else {
Expand All @@ -257,7 +256,7 @@ pub trait FileExt: IsA<File> + sealed::Sealed + 'static {
flags.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
progress_callback,
super_callback0 as *const _ as usize as *mut _,
super_callback0 as *const _ as *mut _,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
Expand Down Expand Up @@ -1375,8 +1374,7 @@ pub trait FileExt: IsA<File> + sealed::Sealed + 'static {
total_num_bytes: i64,
data: glib::ffi::gpointer,
) {
let callback: *mut Option<&mut dyn (FnMut(i64, i64))> =
data as *const _ as usize as *mut Option<&mut dyn (FnMut(i64, i64))>;
let callback = data as *mut Option<&mut dyn (FnMut(i64, i64))>;
if let Some(ref mut callback) = *callback {
callback(current_num_bytes, total_num_bytes)
} else {
Expand All @@ -1397,7 +1395,7 @@ pub trait FileExt: IsA<File> + sealed::Sealed + 'static {
flags.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
progress_callback,
super_callback0 as *const _ as usize as *mut _,
super_callback0 as *const _ as *mut _,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
Expand Down
4 changes: 2 additions & 2 deletions gio/src/auto/subprocess_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ impl SubprocessLauncher {
pub fn set_child_setup<P: Fn() + 'static>(&self, child_setup: P) {
let child_setup_data: Box_<P> = Box_::new(child_setup);
unsafe extern "C" fn child_setup_func<P: Fn() + 'static>(data: glib::ffi::gpointer) {
let callback: &P = &*(data as *mut _);
let callback = &*(data as *mut P);
(*callback)()
}
let child_setup = Some(child_setup_func::<P> as _);
unsafe extern "C" fn destroy_notify_func<P: Fn() + 'static>(data: glib::ffi::gpointer) {
let _callback: Box_<P> = Box_::from_raw(data as *mut _);
let _callback = Box_::from_raw(data as *mut P);
}
let destroy_call3 = Some(destroy_notify_func::<P> as _);
let super_callback0: Box_<P> = child_setup_data;
Expand Down
4 changes: 2 additions & 2 deletions gio/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
14 changes: 6 additions & 8 deletions gio/src/auto/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ pub trait VfsExt: IsA<Vfs> + sealed::Sealed + 'static {
) -> *mut ffi::GFile {
let vfs = from_glib_borrow(vfs);
let identifier: Borrowed<glib::GString> = from_glib_borrow(identifier);
let callback: &Option<Box_<dyn Fn(&Vfs, &str) -> File + 'static>> =
&*(user_data as *mut _);
let callback = &*(user_data as *mut Option<Box_<dyn Fn(&Vfs, &str) -> File + 'static>>);
if let Some(ref callback) = *callback {
callback(&vfs, identifier.as_str())
} else {
Expand All @@ -127,8 +126,7 @@ pub trait VfsExt: IsA<Vfs> + sealed::Sealed + 'static {
) -> *mut ffi::GFile {
let vfs = from_glib_borrow(vfs);
let identifier: Borrowed<glib::GString> = from_glib_borrow(identifier);
let callback: &Option<Box_<dyn Fn(&Vfs, &str) -> File + 'static>> =
&*(user_data as *mut _);
let callback = &*(user_data as *mut Option<Box_<dyn Fn(&Vfs, &str) -> File + 'static>>);
if let Some(ref callback) = *callback {
callback(&vfs, identifier.as_str())
} else {
Expand All @@ -142,13 +140,13 @@ pub trait VfsExt: IsA<Vfs> + sealed::Sealed + 'static {
None
};
unsafe extern "C" fn uri_destroy_func(data: glib::ffi::gpointer) {
let _callback: Box_<Option<Box_<dyn Fn(&Vfs, &str) -> File + 'static>>> =
Box_::from_raw(data as *mut _);
let _callback =
Box_::from_raw(data as *mut Option<Box_<dyn Fn(&Vfs, &str) -> File + 'static>>);
}
let destroy_call4 = Some(uri_destroy_func as _);
unsafe extern "C" fn parse_name_destroy_func(data: glib::ffi::gpointer) {
let _callback: Box_<Option<Box_<dyn Fn(&Vfs, &str) -> File + 'static>>> =
Box_::from_raw(data as *mut _);
let _callback =
Box_::from_raw(data as *mut Option<Box_<dyn Fn(&Vfs, &str) -> File + 'static>>);
}
let destroy_call7 = Some(parse_name_destroy_func as _);
let super_callback0: Box_<Option<Box_<dyn Fn(&Vfs, &str) -> File + 'static>>> =
Expand Down
6 changes: 2 additions & 4 deletions gio/src/desktop_app_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ pub trait DesktopAppInfoExtManual: sealed::Sealed + IsA<DesktopAppInfo> {
) {
let appinfo = from_glib_borrow(appinfo);
let pid = from_glib(pid);
let callback: *mut Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))> =
user_data as *const _ as usize
as *mut Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))>;
let callback = user_data as *mut Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))>;
if let Some(ref mut callback) = *callback {
callback(&appinfo, pid)
} else {
Expand All @@ -116,7 +114,7 @@ pub trait DesktopAppInfoExtManual: sealed::Sealed + IsA<DesktopAppInfo> {
user_setup,
Box_::into_raw(super_callback0) as *mut _,
pid_callback,
super_callback1 as *const _ as usize as *mut _,
super_callback1 as *const _ as *mut _,
stdin_fd.as_raw_fd(),
stdout_fd.as_raw_fd(),
stderr_fd.as_raw_fd(),
Expand Down
4 changes: 2 additions & 2 deletions gio/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
2 changes: 1 addition & 1 deletion gir
2 changes: 1 addition & 1 deletion gir-files
Submodule gir-files updated 2 files
+4 −1 Gsk-4.0.gir
+12 −7 Gtk-4.0.gir
4 changes: 2 additions & 2 deletions glib/gobject-sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
3 changes: 3 additions & 0 deletions glib/src/auto/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#[allow(unused_imports)]
use crate::auto::*;

#[doc(alias = "GDateDay")]
pub type DateDay = u8;
#[doc(alias = "GDateYear")]
pub type DateYear = u16;
#[doc(alias = "GTime")]
pub type Time = i32;
2 changes: 1 addition & 1 deletion glib/src/auto/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ pub fn spawn_async(
) -> Result<Pid, crate::Error> {
let child_setup_data: Box_<Option<Box_<dyn FnOnce() + 'static>>> = Box_::new(child_setup);
unsafe extern "C" fn child_setup_func(data: ffi::gpointer) {
let callback: Box_<Option<Box_<dyn FnOnce() + 'static>>> = Box_::from_raw(data as *mut _);
let callback = Box_::from_raw(data as *mut Option<Box_<dyn FnOnce() + 'static>>);
let callback = (*callback).expect("cannot get closure...");
callback()
}
Expand Down
4 changes: 2 additions & 2 deletions glib/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions glib/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions graphene/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions graphene/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
3 changes: 3 additions & 0 deletions pango/src/auto/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#[allow(unused_imports)]
use crate::auto::*;

#[doc(alias = "PangoGlyph")]
pub type Glyph = u32;
#[doc(alias = "PangoGlyphUnit")]
pub type GlyphUnit = i32;
#[doc(alias = "PangoLayoutRun")]
pub type LayoutRun = GlyphItem;
4 changes: 2 additions & 2 deletions pango/src/auto/attr_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl AttrList {
user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let attribute = from_glib_borrow(attribute);
let callback: *mut P = user_data as *const _ as usize as *mut P;
let callback = user_data as *mut P;
(*callback)(&attribute).into_glib()
}
let func = Some(func_func::<P> as _);
Expand All @@ -46,7 +46,7 @@ impl AttrList {
from_glib_full(ffi::pango_attr_list_filter(
self.to_glib_none().0,
func,
super_callback0 as *const _ as usize as *mut _,
super_callback0 as *const _ as *mut _,
))
}
}
Expand Down
4 changes: 2 additions & 2 deletions pango/src/auto/fontset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub trait FontsetExt: IsA<Fontset> + sealed::Sealed + 'static {
) -> glib::ffi::gboolean {
let fontset = from_glib_borrow(fontset);
let font = from_glib_borrow(font);
let callback: *mut P = user_data as *const _ as usize as *mut P;
let callback = user_data as *mut P;
(*callback)(&fontset, &font).into_glib()
}
let func = Some(func_func::<P> as _);
Expand All @@ -43,7 +43,7 @@ pub trait FontsetExt: IsA<Fontset> + sealed::Sealed + 'static {
ffi::pango_fontset_foreach(
self.as_ref().to_glib_none().0,
func,
super_callback0 as *const _ as usize as *mut _,
super_callback0 as *const _ as *mut _,
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions pango/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions pango/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions pangocairo/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)
4 changes: 2 additions & 2 deletions pangocairo/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 133ee1d93c85)
from gir-files (https://github.com/gtk-rs/gir-files @ 326eb5f2d5d8)
Generated by gir (https://github.com/gtk-rs/gir @ a2f936b77195)
from gir-files (https://github.com/gtk-rs/gir-files @ 20031a537e40)

0 comments on commit a0d5234

Please sign in to comment.