Simplify various raw pointer casts everywhere

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1353>
This commit is contained in:
Sebastian Dröge 2023-11-29 11:24:47 +02:00
parent 897c7dfd39
commit ca8309a5dd
15 changed files with 36 additions and 50 deletions

View file

@ -180,7 +180,7 @@ impl AudioMeta {
#[doc(alias = "get_info")] #[doc(alias = "get_info")]
#[inline] #[inline]
pub fn info(&self) -> crate::AudioInfo { pub fn info(&self) -> crate::AudioInfo {
unsafe { from_glib_none(&self.0.info as *const _ as *mut ffi::GstAudioInfo) } unsafe { from_glib_none(&self.0.info as *const _) }
} }
#[doc(alias = "get_samples")] #[doc(alias = "get_samples")]

View file

@ -31,7 +31,7 @@ impl AudioRingBufferSpec {
#[doc(alias = "get_audio_info")] #[doc(alias = "get_audio_info")]
#[inline] #[inline]
pub fn audio_info(&self) -> AudioInfo { pub fn audio_info(&self) -> AudioInfo {
unsafe { AudioInfo::from_glib_none(mut_override(&self.0.info)) } unsafe { AudioInfo::from_glib_none(&self.0.info as *const ffi::GstAudioInfo) }
} }
#[doc(alias = "get_latency_time")] #[doc(alias = "get_latency_time")]

View file

@ -135,7 +135,7 @@ pub trait AudioSinkImplExt: sealed::Sealed + ObjectSubclass {
Some(f) => f, Some(f) => f,
None => return Ok(-1), None => return Ok(-1),
}; };
let buffer_ptr = buffer.as_ptr() as *const _ as *mut _; let buffer_ptr = buffer.as_ptr() as glib::ffi::gpointer;
let ret = f( let ret = f(
self.obj().unsafe_cast_ref::<AudioSink>().to_glib_none().0, self.obj().unsafe_cast_ref::<AudioSink>().to_glib_none().0,
buffer_ptr, buffer_ptr,

View file

@ -40,7 +40,7 @@ impl GLSyncMeta {
pub fn set_sync_point(&self, context: &impl IsA<GLContext>) { pub fn set_sync_point(&self, context: &impl IsA<GLContext>) {
unsafe { unsafe {
ffi::gst_gl_sync_meta_set_sync_point( ffi::gst_gl_sync_meta_set_sync_point(
&self.0 as *const _ as *mut _, mut_override(&self.0),
context.as_ref().to_glib_none().0, context.as_ref().to_glib_none().0,
); );
} }
@ -49,10 +49,7 @@ impl GLSyncMeta {
#[doc(alias = "gst_gl_sync_meta_wait")] #[doc(alias = "gst_gl_sync_meta_wait")]
pub fn wait(&self, context: &impl IsA<GLContext>) { pub fn wait(&self, context: &impl IsA<GLContext>) {
unsafe { unsafe {
ffi::gst_gl_sync_meta_wait( ffi::gst_gl_sync_meta_wait(mut_override(&self.0), context.as_ref().to_glib_none().0);
&self.0 as *const _ as *mut _,
context.as_ref().to_glib_none().0,
);
} }
} }
@ -60,7 +57,7 @@ impl GLSyncMeta {
pub fn wait_cpu(&self, context: &impl IsA<GLContext>) { pub fn wait_cpu(&self, context: &impl IsA<GLContext>) {
unsafe { unsafe {
ffi::gst_gl_sync_meta_wait_cpu( ffi::gst_gl_sync_meta_wait_cpu(
&self.0 as *const _ as *mut _, mut_override(&self.0),
context.as_ref().to_glib_none().0, context.as_ref().to_glib_none().0,
); );
} }

View file

@ -133,7 +133,7 @@ pub trait VideoAggregatorImplExt: sealed::Sealed + ObjectSubclass {
None None
} else { } else {
Some(( Some((
from_glib_none(mut_override(&info as *const ffi::GstVideoInfo)), from_glib_none(&info as *const ffi::GstVideoInfo),
from_glib(at_least_one_alpha), from_glib(at_least_one_alpha),
)) ))
} }

View file

@ -124,7 +124,7 @@ impl VideoBufferPoolConfig for gst::BufferPoolConfigRef {
unsafe { unsafe {
ffi::gst_buffer_pool_config_set_video_alignment( ffi::gst_buffer_pool_config_set_video_alignment(
self.as_mut().as_mut_ptr(), self.as_mut().as_mut_ptr(),
&align.0 as *const _ as *mut _, mut_override(&align.0),
) )
} }
} }

View file

@ -97,8 +97,7 @@ impl<'a, T: VideoCodecStateContext<'a>> VideoCodecState<'a, T> {
#[inline] #[inline]
pub fn info(&self) -> VideoInfo { pub fn info(&self) -> VideoInfo {
unsafe { unsafe {
let ptr = &((*self.as_mut_ptr()).info) as *const _ as usize as *mut _; VideoInfo::from_glib_none(&((*self.as_mut_ptr()).info) as *const ffi::GstVideoInfo)
VideoInfo::from_glib_none(ptr)
} }
} }

View file

@ -288,12 +288,11 @@ impl<O: IsA<VideoDecoder>> VideoDecoderExtManual for O {}
impl HasStreamLock for VideoDecoder { impl HasStreamLock for VideoDecoder {
fn stream_lock(&self) -> *mut glib::ffi::GRecMutex { fn stream_lock(&self) -> *mut glib::ffi::GRecMutex {
let decoder_sys: *const ffi::GstVideoDecoder = self.to_glib_none().0; let decoder_sys: *const ffi::GstVideoDecoder = self.to_glib_none().0;
unsafe { &(*decoder_sys).stream_lock as *const _ as usize as *mut _ } unsafe { mut_override(&(*decoder_sys).stream_lock) }
} }
fn element_as_ptr(&self) -> *const gst::ffi::GstElement { fn element_as_ptr(&self) -> *const gst::ffi::GstElement {
let decoder_sys: *const ffi::GstVideoDecoder = self.to_glib_none().0; self.as_ptr() as *mut gst::ffi::GstElement
decoder_sys as *const gst::ffi::GstElement
} }
} }

View file

@ -231,11 +231,10 @@ impl<O: IsA<VideoEncoder>> VideoEncoderExtManual for O {}
impl HasStreamLock for VideoEncoder { impl HasStreamLock for VideoEncoder {
fn stream_lock(&self) -> *mut glib::ffi::GRecMutex { fn stream_lock(&self) -> *mut glib::ffi::GRecMutex {
let encoder_sys: *const ffi::GstVideoEncoder = self.to_glib_none().0; let encoder_sys: *const ffi::GstVideoEncoder = self.to_glib_none().0;
unsafe { &(*encoder_sys).stream_lock as *const _ as usize as *mut _ } unsafe { mut_override(&(*encoder_sys).stream_lock) }
} }
fn element_as_ptr(&self) -> *const gst::ffi::GstElement { fn element_as_ptr(&self) -> *const gst::ffi::GstElement {
let encoder_sys: *const ffi::GstVideoEncoder = self.to_glib_none().0; self.as_ptr() as *const gst::ffi::GstElement
encoder_sys as *const gst::ffi::GstElement
} }
} }

View file

@ -584,7 +584,7 @@ impl VideoInfo {
#[doc(alias = "gst_video_info_to_caps")] #[doc(alias = "gst_video_info_to_caps")]
pub fn to_caps(&self) -> Result<gst::Caps, glib::error::BoolError> { pub fn to_caps(&self) -> Result<gst::Caps, glib::error::BoolError> {
unsafe { unsafe {
let result = from_glib_full(ffi::gst_video_info_to_caps(&self.0 as *const _ as *mut _)); let result = from_glib_full(ffi::gst_video_info_to_caps(mut_override(&self.0)));
match result { match result {
Some(c) => Ok(c), Some(c) => Ok(c),
None => Err(glib::bool_error!("Failed to create caps from VideoInfo")), None => Err(glib::bool_error!("Failed to create caps from VideoInfo")),
@ -802,7 +802,7 @@ impl VideoInfo {
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
if from_glib(ffi::gst_video_info_convert( if from_glib(ffi::gst_video_info_convert(
&self.0 as *const _ as *mut _, mut_override(&self.0),
src_val.format().into_glib(), src_val.format().into_glib(),
src_val.into_raw_value(), src_val.into_raw_value(),
U::default_format().into_glib(), U::default_format().into_glib(),
@ -824,7 +824,7 @@ impl VideoInfo {
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
if from_glib(ffi::gst_video_info_convert( if from_glib(ffi::gst_video_info_convert(
&self.0 as *const _ as *mut _, mut_override(&self.0),
src_val.format().into_glib(), src_val.format().into_glib(),
src_val.into_raw_value(), src_val.into_raw_value(),
dest_fmt.into_glib(), dest_fmt.into_glib(),

View file

@ -2,7 +2,7 @@
use std::{fmt, ptr}; use std::{fmt, ptr};
use glib::translate::{from_glib, from_glib_none, FromGlib, IntoGlib, IntoGlibPtr, ToGlibPtr}; use glib::translate::*;
use gst::prelude::*; use gst::prelude::*;
#[repr(transparent)] #[repr(transparent)]
@ -182,10 +182,7 @@ impl VideoMeta {
unsafe { unsafe {
glib::result_from_gboolean!( glib::result_from_gboolean!(
ffi::gst_video_meta_get_plane_size( ffi::gst_video_meta_get_plane_size(mut_override(&self.0), &mut plane_size,),
&self.0 as *const _ as usize as *mut _,
&mut plane_size,
),
"Failed to get plane size" "Failed to get plane size"
)?; )?;
} }
@ -202,10 +199,7 @@ impl VideoMeta {
unsafe { unsafe {
glib::result_from_gboolean!( glib::result_from_gboolean!(
ffi::gst_video_meta_get_plane_height( ffi::gst_video_meta_get_plane_height(mut_override(&self.0), &mut plane_height,),
&self.0 as *const _ as usize as *mut _,
&mut plane_height,
),
"Failed to get plane height" "Failed to get plane height"
)?; )?;
} }

View file

@ -2,9 +2,7 @@
use std::{fmt, marker::PhantomData, mem, ops, ops::ControlFlow, ptr, slice, u64, usize}; use std::{fmt, marker::PhantomData, mem, ops, ops::ControlFlow, ptr, slice, u64, usize};
use glib::translate::{ use glib::translate::*;
from_glib, from_glib_full, FromGlib, FromGlibPtrFull, IntoGlib, IntoGlibPtr,
};
use crate::{meta::*, BufferCursor, BufferFlags, BufferRefCursor, ClockTime, Memory, MemoryRef}; use crate::{meta::*, BufferCursor, BufferFlags, BufferRefCursor, ClockTime, Memory, MemoryRef};
@ -475,7 +473,7 @@ impl BufferRef {
meta: *mut *mut ffi::GstMeta, meta: *mut *mut ffi::GstMeta,
user_data: glib::ffi::gpointer, user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let func = user_data as *const _ as usize as *mut F; let func = user_data as *mut F;
let res = (*func)(Meta::from_ptr(BufferRef::from_ptr(buffer), *meta)); let res = (*func)(Meta::from_ptr(BufferRef::from_ptr(buffer), *meta));
matches!(res, ControlFlow::Continue(_)).into_glib() matches!(res, ControlFlow::Continue(_)).into_glib()
@ -485,9 +483,9 @@ impl BufferRef {
let func_ptr: &F = &func; let func_ptr: &F = &func;
from_glib(ffi::gst_buffer_foreach_meta( from_glib(ffi::gst_buffer_foreach_meta(
self.as_ptr() as *mut _, mut_override(self.as_ptr()),
Some(trampoline::<F>), Some(trampoline::<F>),
func_ptr as *const _ as usize as *mut _, func_ptr as *const _ as *mut _,
)) ))
} }
} }
@ -510,7 +508,7 @@ impl BufferRef {
meta: *mut *mut ffi::GstMeta, meta: *mut *mut ffi::GstMeta,
user_data: glib::ffi::gpointer, user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let func = user_data as *const _ as usize as *mut F; let func = user_data as *mut F;
let res = (*func)(Meta::from_mut_ptr(BufferRef::from_mut_ptr(buffer), *meta)); let res = (*func)(Meta::from_mut_ptr(BufferRef::from_mut_ptr(buffer), *meta));
let (cont, action) = match res { let (cont, action) = match res {
@ -529,9 +527,9 @@ impl BufferRef {
let func_ptr: &F = &func; let func_ptr: &F = &func;
from_glib(ffi::gst_buffer_foreach_meta( from_glib(ffi::gst_buffer_foreach_meta(
self.as_ptr() as *mut _, mut_override(self.as_ptr()),
Some(trampoline::<F>), Some(trampoline::<F>),
func_ptr as *const _ as usize as *mut _, func_ptr as *const _ as *mut _,
)) ))
} }
} }

View file

@ -109,7 +109,7 @@ impl BufferListRef {
idx: u32, idx: u32,
user_data: glib::ffi::gpointer, user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let func = user_data as *const _ as usize as *mut F; let func = user_data as *mut F;
let res = (*func)(&Buffer::from_glib_borrow(*buffer), idx); let res = (*func)(&Buffer::from_glib_borrow(*buffer), idx);
matches!(res, ControlFlow::Continue(_)).into_glib() matches!(res, ControlFlow::Continue(_)).into_glib()
@ -121,7 +121,7 @@ impl BufferListRef {
from_glib(ffi::gst_buffer_list_foreach( from_glib(ffi::gst_buffer_list_foreach(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
Some(trampoline::<F>), Some(trampoline::<F>),
func_ptr as *const _ as usize as *mut _, func_ptr as *const _ as *mut _,
)) ))
} }
} }
@ -138,7 +138,7 @@ impl BufferListRef {
idx: u32, idx: u32,
user_data: glib::ffi::gpointer, user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let func = user_data as *const _ as usize as *mut F; let func = user_data as *mut F;
let res = (*func)( let res = (*func)(
Buffer::from_glib_full(ptr::replace( Buffer::from_glib_full(ptr::replace(
buffer as *mut *const ffi::GstBuffer, buffer as *mut *const ffi::GstBuffer,
@ -170,7 +170,7 @@ impl BufferListRef {
from_glib(ffi::gst_buffer_list_foreach( from_glib(ffi::gst_buffer_list_foreach(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
Some(trampoline::<F>), Some(trampoline::<F>),
func_ptr as *const _ as usize as *mut _, func_ptr as *const _ as *mut _,
)) ))
} }
} }

View file

@ -17,7 +17,7 @@ impl Registry {
user_data: glib::ffi::gpointer, user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let feature = from_glib_borrow(feature); let feature = from_glib_borrow(feature);
let callback: *mut P = user_data as *const _ as usize as *mut P; let callback = user_data as *mut P;
let res = (*callback)(&feature); let res = (*callback)(&feature);
res.into_glib() res.into_glib()
} }
@ -28,7 +28,7 @@ impl Registry {
self.to_glib_none().0, self.to_glib_none().0,
filter, filter,
first.into_glib(), first.into_glib(),
super_callback0 as *const _ as usize as *mut _, super_callback0 as *const _ as *mut _,
)) ))
} }
} }
@ -77,7 +77,7 @@ impl Registry {
user_data: glib::ffi::gpointer, user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let plugin = from_glib_borrow(plugin); let plugin = from_glib_borrow(plugin);
let callback: *mut P = user_data as *const _ as usize as *mut P; let callback = user_data as *const _ as *mut P;
let res = (*callback)(&plugin); let res = (*callback)(&plugin);
res.into_glib() res.into_glib()
} }
@ -88,7 +88,7 @@ impl Registry {
self.to_glib_none().0, self.to_glib_none().0,
filter, filter,
first.into_glib(), first.into_glib(),
super_callback0 as *const _ as usize as *mut _, super_callback0 as *const _ as *mut _,
)) ))
} }
} }

View file

@ -2,7 +2,7 @@
use std::{fmt, ptr}; use std::{fmt, ptr};
use glib::translate::{from_glib_full, from_glib_none, mut_override, IntoGlibPtr, ToGlibPtr}; use glib::translate::{from_glib_full, from_glib_none, IntoGlibPtr, ToGlibPtr};
use crate::{ use crate::{
format::FormattedValueIntrinsic, Buffer, BufferList, BufferListRef, BufferRef, Caps, CapsRef, format::FormattedValueIntrinsic, Buffer, BufferList, BufferListRef, BufferRef, Caps, CapsRef,
@ -73,7 +73,7 @@ impl<'a> SampleBuilder<'a> {
self.buffer.to_glib_none().0, self.buffer.to_glib_none().0,
self.caps.to_glib_none().0, self.caps.to_glib_none().0,
self.segment.to_glib_none().0, self.segment.to_glib_none().0,
mut_override(info), info,
)); ));
if let Some(buffer_list) = self.buffer_list { if let Some(buffer_list) = self.buffer_list {