Skip to content

Commit f1cb9ed

Browse files
authored
Merge pull request #1375 from sdroege/from-glib-ptr-borrow-reference
glib: Use a reference to a pointer of correct mutability for from_gli…
2 parents dc264f6 + 99d8abf commit f1cb9ed

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

glib/src/boxed.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ macro_rules! glib_boxed_wrapper {
4747

4848
#[doc = "Borrows the underlying C value."]
4949
#[inline]
50-
pub unsafe fn from_glib_ptr_borrow<'a>(ptr: *const *const $ffi_name) -> &'a Self {
51-
&*(ptr as *const Self)
50+
pub unsafe fn from_glib_ptr_borrow(ptr: &*mut $ffi_name) -> &Self {
51+
&*(ptr as *const *mut $ffi_name as *const Self)
5252
}
5353

5454
#[doc = "Borrows the underlying C value mutably."]
5555
#[inline]
56-
pub unsafe fn from_glib_ptr_borrow_mut<'a>(ptr: *mut *mut $ffi_name) -> &'a mut Self {
57-
&mut *(ptr as *mut Self)
56+
pub unsafe fn from_glib_ptr_borrow_mut(ptr: &mut *mut $ffi_name) -> &mut Self {
57+
&mut *(ptr as *mut *mut $ffi_name as *mut Self)
5858
}
5959
}
6060

@@ -354,7 +354,7 @@ macro_rules! glib_boxed_wrapper {
354354
debug_assert_eq!(std::mem::size_of::<Self>(), std::mem::size_of::<$crate::ffi::gpointer>());
355355
let value = &*(value as *const $crate::Value as *const $crate::gobject_ffi::GValue);
356356
debug_assert!(!value.data[0].v_pointer.is_null());
357-
<$name $(<$($generic),+>)?>::from_glib_ptr_borrow(&value.data[0].v_pointer as *const $crate::ffi::gpointer as *const *const $ffi_name)
357+
<$name $(<$($generic),+>)?>::from_glib_ptr_borrow(&*(&value.data[0].v_pointer as *const $crate::ffi::gpointer as *const *mut $ffi_name))
358358
}
359359
}
360360

glib/src/match_info.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ impl MatchInfo<'_> {
3434
#[doc = "Return the inner pointer to the underlying C value."]
3535
#[inline]
3636
pub fn as_ptr(&self) -> *mut ffi::GMatchInfo {
37-
unsafe { *(self as *const Self as *const *const ffi::GMatchInfo) as *mut ffi::GMatchInfo }
37+
self.inner.as_ptr()
3838
}
3939
#[doc = "Borrows the underlying C value."]
4040
#[inline]
41-
pub unsafe fn from_glib_ptr_borrow<'a>(ptr: *const *const ffi::GMatchInfo) -> &'a Self {
42-
&*(ptr as *const Self)
41+
pub unsafe fn from_glib_ptr_borrow(ptr: &*mut ffi::GMatchInfo) -> &Self {
42+
&*(ptr as *const *mut ffi::GMatchInfo as *const Self)
4343
}
4444
}
4545

@@ -201,8 +201,8 @@ unsafe impl<'a, 'input: 'a> crate::value::FromValue<'a> for &'a MatchInfo<'input
201201
let value = &*(value as *const crate::Value as *const crate::gobject_ffi::GValue);
202202
debug_assert!(!value.data[0].v_pointer.is_null());
203203
<MatchInfo<'input>>::from_glib_ptr_borrow(
204-
&value.data[0].v_pointer as *const crate::ffi::gpointer
205-
as *const *const ffi::GMatchInfo,
204+
&*(&value.data[0].v_pointer as *const crate::ffi::gpointer
205+
as *const *mut ffi::GMatchInfo),
206206
)
207207
}
208208
}

glib/src/object.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub unsafe trait ObjectType:
4747
fn as_object_ref(&self) -> &ObjectRef;
4848
fn as_ptr(&self) -> *mut Self::GlibType;
4949

50-
unsafe fn from_glib_ptr_borrow<'a>(ptr: *const *const Self::GlibType) -> &'a Self;
50+
unsafe fn from_glib_ptr_borrow(ptr: &*mut Self::GlibType) -> &Self;
5151
}
5252

5353
// rustdoc-stripper-ignore-next
@@ -730,8 +730,8 @@ macro_rules! glib_object_wrapper {
730730
}
731731

732732
#[inline]
733-
unsafe fn from_glib_ptr_borrow<'a>(ptr: *const *const Self::GlibType) -> &'a Self {
734-
&*(ptr as *const Self)
733+
unsafe fn from_glib_ptr_borrow(ptr: &*mut Self::GlibType) -> &Self {
734+
&*(ptr as *const *mut $ffi_name as *const Self)
735735
}
736736
}
737737

@@ -1071,7 +1071,7 @@ macro_rules! glib_object_wrapper {
10711071
let value = &*(value as *const $crate::Value as *const $crate::gobject_ffi::GValue);
10721072
debug_assert!(!value.data[0].v_pointer.is_null());
10731073
debug_assert_ne!((*(value.data[0].v_pointer as *const $crate::gobject_ffi::GObject)).ref_count, 0);
1074-
<$name $(<$($generic),+>)? as $crate::object::ObjectType>::from_glib_ptr_borrow(&value.data[0].v_pointer as *const $crate::ffi::gpointer as *const *const $ffi_name)
1074+
<$name $(<$($generic),+>)? as $crate::object::ObjectType>::from_glib_ptr_borrow(&*(&value.data[0].v_pointer as *const $crate::ffi::gpointer as *const *mut $ffi_name))
10751075
}
10761076
}
10771077

glib/src/shared.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ macro_rules! glib_shared_wrapper {
4545

4646
#[doc = "Borrows the underlying C value."]
4747
#[inline]
48-
pub unsafe fn from_glib_ptr_borrow<'a>(ptr: *const *const $ffi_name) -> &'a Self {
49-
&*(ptr as *const Self)
48+
pub unsafe fn from_glib_ptr_borrow(ptr: &*mut $ffi_name) -> &Self {
49+
&*(ptr as *const *mut $ffi_name as *const Self)
5050
}
5151
}
5252

@@ -374,7 +374,7 @@ macro_rules! glib_shared_wrapper {
374374
debug_assert_eq!(std::mem::size_of::<Self>(), std::mem::size_of::<$crate::ffi::gpointer>());
375375
let value = &*(value as *const $crate::Value as *const $crate::gobject_ffi::GValue);
376376
debug_assert!(!value.data[0].v_pointer.is_null());
377-
<$name $(<$($generic),+>)?>::from_glib_ptr_borrow(&value.data[0].v_pointer as *const $crate::ffi::gpointer as *const *const $ffi_name)
377+
<$name $(<$($generic),+>)?>::from_glib_ptr_borrow(&*(&value.data[0].v_pointer as *const $crate::ffi::gpointer as *const *mut $ffi_name))
378378
}
379379
}
380380

glib/src/value_array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ unsafe impl<'a> crate::value::FromValue<'a> for &'a ValueArray {
179179
let value = &*(value as *const Value as *const gobject_ffi::GValue);
180180
debug_assert!(!value.data[0].v_pointer.is_null());
181181
<ValueArray>::from_glib_ptr_borrow(
182-
&value.data[0].v_pointer as *const ffi::gpointer
183-
as *const *const gobject_ffi::GValueArray,
182+
&*(&value.data[0].v_pointer as *const ffi::gpointer
183+
as *const *mut gobject_ffi::GValueArray),
184184
)
185185
}
186186
}

0 commit comments

Comments
 (0)