diff --git a/gtk4/src/file_chooser.rs b/gtk4/src/file_chooser.rs index deaa2af927a6..8bdb2b43c310 100644 --- a/gtk4/src/file_chooser.rs +++ b/gtk4/src/file_chooser.rs @@ -16,40 +16,45 @@ mod sealed { pub trait FileChooserExtManual: sealed::Sealed + IsA + 'static { #[doc(alias = "gtk_file_chooser_add_choice")] fn add_choice(&self, id: impl IntoGStr, label: impl IntoGStr, options: &[(&str, &str)]) { - unsafe { - let (options_ids, options_labels) = if options.is_empty() { - (std::ptr::null(), std::ptr::null()) - } else { - let stashes_ids = options - .iter() - .map(|o| o.0.to_glib_none()) - .collect::>(); - let stashes_labels = options - .iter() - .map(|o| o.1.to_glib_none()) - .collect::>(); - ( - stashes_ids - .iter() - .map(|o| o.0) - .collect::>() - .as_ptr(), - stashes_labels - .iter() - .map(|o| o.0) - .collect::>() - .as_ptr(), - ) - }; - + if options.is_empty() { + id.run_with_gstr(|id| { + label.run_with_gstr(|label| unsafe { + ffi::gtk_file_chooser_add_choice( + self.as_ref().to_glib_none().0, + id.as_ptr(), + label.as_ptr(), + mut_override(std::ptr::null()), + mut_override(std::ptr::null()), + ); + }); + }); + } else { + let stashes_ids = options + .iter() + .map(|o| o.0.to_glib_none()) + .collect::>(); + let stashes_labels = options + .iter() + .map(|o| o.1.to_glib_none()) + .collect::>(); + let options_ids = stashes_ids + .iter() + .map(|o| o.0) + .chain(std::iter::once(std::ptr::null())) + .collect::>(); + let options_labels = stashes_labels + .iter() + .map(|o| o.0) + .chain(std::iter::once(std::ptr::null())) + .collect::>(); id.run_with_gstr(|id| { - label.run_with_gstr(|label| { + label.run_with_gstr(|label| unsafe { ffi::gtk_file_chooser_add_choice( self.as_ref().to_glib_none().0, id.as_ptr(), label.as_ptr(), - mut_override(options_ids), - mut_override(options_labels), + mut_override(options_ids.as_ptr()), + mut_override(options_labels.as_ptr()), ); }); });