mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 02:51:10 +00:00
gstreamer: Use a reference to a pointer of correct mutability for from_glib_ptr_borrow()
This hopefully makes it easier to use and harder to get the returned lifetime wrong. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1436>
This commit is contained in:
parent
238768f525
commit
fe1fe5b114
1 changed files with 7 additions and 8 deletions
|
@ -30,10 +30,12 @@ macro_rules! mini_object_wrapper (
|
||||||
|
|
||||||
impl $name {
|
impl $name {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn from_glib_ptr_borrow<'a>(
|
pub unsafe fn from_glib_ptr_borrow(
|
||||||
ptr: *const *const $ffi_name,
|
ptr: &*mut $ffi_name,
|
||||||
) -> &'a Self {
|
) -> &Self {
|
||||||
&*(ptr as *const $name)
|
debug_assert_eq!(std::mem::size_of::<$name>(), std::mem::size_of::<$crate::glib::ffi::gpointer>());
|
||||||
|
debug_assert!(!ptr.is_null());
|
||||||
|
&*(ptr as *const *mut $ffi_name as *const $name)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -548,11 +550,8 @@ macro_rules! mini_object_wrapper (
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn from_value(value: &'a $crate::glib::Value) -> Self {
|
unsafe fn from_value(value: &'a $crate::glib::Value) -> Self {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
assert_eq!(std::mem::size_of::<$name>(), std::mem::size_of::<$crate::glib::ffi::gpointer>());
|
|
||||||
let value = &*(value as *const $crate::glib::Value as *const $crate::glib::gobject_ffi::GValue);
|
let value = &*(value as *const $crate::glib::Value as *const $crate::glib::gobject_ffi::GValue);
|
||||||
let ptr = &value.data[0].v_pointer as *const $crate::glib::ffi::gpointer as *const *const $ffi_name;
|
$name::from_glib_ptr_borrow(&*(&value.data[0].v_pointer as *const $crate::glib::ffi::gpointer as *const *mut $ffi_name))
|
||||||
debug_assert!(!(*ptr).is_null());
|
|
||||||
&*(ptr as *const $name)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue