gstreamer: Use from_glib_ptr_borrow() instead of manual pointer operations

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1749>
This commit is contained in:
Sebastian Dröge 2025-07-03 17:46:02 +03:00
parent 04c524a20b
commit b96e0438ae
4 changed files with 8 additions and 11 deletions

View file

@ -8,7 +8,7 @@ use std::{
ptr, slice, ptr, slice,
}; };
use glib::translate::*; use glib::{prelude::*, translate::*};
use crate::{ffi, AllocationParams, Allocator, MemoryFlags}; use crate::{ffi, AllocationParams, Allocator, MemoryFlags};
@ -126,7 +126,7 @@ impl MemoryRef {
if self.0.allocator.is_null() { if self.0.allocator.is_null() {
None None
} else { } else {
Some(&*(&self.0.allocator as *const *mut ffi::GstAllocator as *const Allocator)) Some(Allocator::from_glib_ptr_borrow(&self.0.allocator))
} }
} }
} }
@ -970,7 +970,7 @@ impl MemoryRefTrace {
if self.0.allocator.is_null() { if self.0.allocator.is_null() {
None None
} else { } else {
Some(&*(&self.0.allocator as *const *mut ffi::GstAllocator as *const Allocator)) Some(Allocator::from_glib_ptr_borrow(&self.0.allocator))
} }
} }
} }

View file

@ -28,7 +28,7 @@ impl MessageRef {
if (*self.as_ptr()).src.is_null() { if (*self.as_ptr()).src.is_null() {
None None
} else { } else {
Some(&*(&(*self.as_ptr()).src as *const *mut ffi::GstObject as *const Object)) Some(Object::from_glib_ptr_borrow(&(*self.as_ptr()).src))
} }
} }
} }

View file

@ -29,7 +29,7 @@ impl PadTemplate {
pub fn caps(&self) -> &Caps { pub fn caps(&self) -> &Caps {
unsafe { unsafe {
let templ = &*(self.as_ptr() as *const ffi::GstPadTemplate); let templ = &*(self.as_ptr() as *const ffi::GstPadTemplate);
&*(&templ.caps as *const *mut ffi::GstCaps as *const Caps) Caps::from_glib_ptr_borrow(&templ.caps)
} }
} }
@ -41,9 +41,9 @@ impl PadTemplate {
unsafe { unsafe {
let templ = &*(self.as_ptr() as *const ffi::GstPadTemplate); let templ = &*(self.as_ptr() as *const ffi::GstPadTemplate);
if !templ.ABI.abi.documentation_caps.is_null() { if !templ.ABI.abi.documentation_caps.is_null() {
&*(&templ.ABI.abi.documentation_caps as *const *mut ffi::GstCaps as *const Caps) Caps::from_glib_ptr_borrow(&templ.ABI.abi.documentation_caps)
} else { } else {
&*(&templ.caps as *const *mut ffi::GstCaps as *const Caps) self.caps()
} }
} }
} }

View file

@ -277,10 +277,7 @@ impl ParamSpecArray {
if (*ptr).element_spec.is_null() { if (*ptr).element_spec.is_null() {
None None
} else { } else {
Some( Some(glib::ParamSpec::from_glib_ptr_borrow(&(*ptr).element_spec))
&*(&(*ptr).element_spec as *const *mut glib::gobject_ffi::GParamSpec
as *const glib::ParamSpec),
)
} }
} }
} }