Skip to content

Commit e9e7a89

Browse files
committed
glib: Make sure to keep the original values alive in [T]::to_glib_none()
They're just borrowed to the C code so we need to make sure to keep them alive via a `PhantomData<&'a [T]>` at least.
1 parent 3cd48d2 commit e9e7a89

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

glib/src/boxed_inline.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,13 @@ macro_rules! glib_boxed_inline_wrapper {
216216

217217
#[doc(hidden)]
218218
impl<'a $(, $($generic: 'a + $($bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibContainerFromSlice<'a, *mut *const $ffi_name> for $name $(<$($generic),+>)? {
219-
type Storage = Option<Vec<*const $ffi_name>>;
219+
type Storage = (std::marker::PhantomData<&'a [Self]>, Option<Vec<*const $ffi_name>>);
220220

221221
fn to_glib_none_from_slice(t: &'a [Self]) -> (*mut *const $ffi_name, Self::Storage) {
222222
let mut v: Vec<_> = t.iter().map(|s| &s.inner as *const $ffi_name).collect();
223223
v.push(std::ptr::null_mut() as *const $ffi_name);
224224

225-
(v.as_mut_ptr(), Some(v))
225+
(v.as_mut_ptr(), (std::marker::PhantomData, Some(v)))
226226
}
227227

228228
fn to_glib_container_from_slice(t: &'a [Self]) -> (*mut *const $ffi_name, Self::Storage) {
@@ -236,7 +236,7 @@ macro_rules! glib_boxed_inline_wrapper {
236236
v_ptr
237237
};
238238

239-
(v_ptr, None)
239+
(v_ptr, (std::marker::PhantomData, None))
240240
}
241241

242242
fn to_glib_full_from_slice(t: &[Self]) -> *mut *const $ffi_name {
@@ -254,7 +254,7 @@ macro_rules! glib_boxed_inline_wrapper {
254254

255255
#[doc(hidden)]
256256
impl<'a $(, $($generic: 'a + $($bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibContainerFromSlice<'a, *const *const $ffi_name> for $name $(<$($generic),+>)? {
257-
type Storage = Option<Vec<*const $ffi_name>>;
257+
type Storage = (std::marker::PhantomData<&'a [Self]>, Option<Vec<*const $ffi_name>>);
258258

259259
fn to_glib_none_from_slice(t: &'a [Self]) -> (*const *const $ffi_name, Self::Storage) {
260260
let (ptr, stash) = $crate::translate::ToGlibContainerFromSlice::<'a, *mut *const $ffi_name>::to_glib_none_from_slice(t);

0 commit comments

Comments
 (0)