Skip to content

Commit 355b398

Browse files
A6GibKmsdroege
authored andcommitted
Port launch_uris_as_manager_with_fds to safe-io
1 parent 8bb8354 commit 355b398

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

gio/src/desktop_app_info.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#[cfg(all(unix, feature = "v2_58"))]
44
use std::boxed::Box as Box_;
55
#[cfg(all(unix, feature = "v2_58"))]
6-
use std::os::unix::io::AsRawFd;
6+
use std::os::unix::io::{AsFd, AsRawFd};
77
#[cfg(all(unix, feature = "v2_58"))]
88
use std::ptr;
99

@@ -48,21 +48,16 @@ impl DesktopAppInfo {
4848
pub trait DesktopAppInfoExtManual: IsA<DesktopAppInfo> {
4949
#[cfg_attr(docsrs, doc(cfg(all(feature = "v2_58", unix))))]
5050
#[doc(alias = "g_desktop_app_info_launch_uris_as_manager_with_fds")]
51-
fn launch_uris_as_manager_with_fds<
52-
P: IsA<AppLaunchContext>,
53-
T: AsRawFd,
54-
U: AsRawFd,
55-
V: AsRawFd,
56-
>(
51+
fn launch_uris_as_manager_with_fds<P: IsA<AppLaunchContext>>(
5752
&self,
5853
uris: &[&str],
5954
launch_context: Option<&P>,
6055
spawn_flags: glib::SpawnFlags,
6156
user_setup: Option<Box_<dyn FnOnce() + 'static>>,
6257
pid_callback: Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))>,
63-
stdin_fd: &mut T,
64-
stdout_fd: &mut U,
65-
stderr_fd: &mut V,
58+
stdin_fd: Option<impl AsFd>,
59+
stdout_fd: Option<impl AsFd>,
60+
stderr_fd: Option<impl AsFd>,
6661
) -> Result<(), Error> {
6762
let user_setup_data: Box_<Option<Box_<dyn FnOnce() + 'static>>> = Box_::new(user_setup);
6863
unsafe extern "C" fn user_setup_func(user_data: glib::ffi::gpointer) {
@@ -99,6 +94,10 @@ pub trait DesktopAppInfoExtManual: IsA<DesktopAppInfo> {
9994
let super_callback0: Box_<Option<Box_<dyn FnOnce() + 'static>>> = user_setup_data;
10095
let super_callback1: &Option<&mut dyn (FnMut(&DesktopAppInfo, glib::Pid))> =
10196
&pid_callback_data;
97+
98+
let stdin_raw_fd = stdin_fd.map_or(-1, |fd| fd.as_fd().as_raw_fd());
99+
let stdout_raw_fd = stdout_fd.map_or(-1, |fd| fd.as_fd().as_raw_fd());
100+
let stderr_raw_fd = stderr_fd.map_or(-1, |fd| fd.as_fd().as_raw_fd());
102101
unsafe {
103102
let mut error = ptr::null_mut();
104103
let _ = ffi::g_desktop_app_info_launch_uris_as_manager_with_fds(
@@ -110,9 +109,9 @@ pub trait DesktopAppInfoExtManual: IsA<DesktopAppInfo> {
110109
Box_::into_raw(super_callback0) as *mut _,
111110
pid_callback,
112111
super_callback1 as *const _ as *mut _,
113-
stdin_fd.as_raw_fd(),
114-
stdout_fd.as_raw_fd(),
115-
stderr_fd.as_raw_fd(),
112+
stdin_raw_fd,
113+
stdout_raw_fd,
114+
stderr_raw_fd,
116115
&mut error,
117116
);
118117
if error.is_null() {

0 commit comments

Comments
 (0)