Skip to content

Commit 80f8f49

Browse files
committed
subprocess_launcher: Take owned fds
1 parent 0e0e54e commit 80f8f49

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

gio/src/subprocess_launcher.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

33
#[cfg(any(unix, all(docsrs, unix)))]
4-
use std::os::unix::io::IntoRawFd;
4+
use std::os::unix::io::{IntoRawFd, OwnedFd};
55

66
#[cfg(unix)]
77
use glib::translate::*;
@@ -19,40 +19,41 @@ impl SubprocessLauncher {
1919
#[cfg(unix)]
2020
#[cfg_attr(docsrs, doc(cfg(unix)))]
2121
#[doc(alias = "g_subprocess_launcher_take_fd")]
22-
pub fn take_fd(&self, source_fd: impl IntoRawFd, target_fd: impl IntoRawFd) {
22+
pub fn take_fd(&self, source_fd: Option<OwnedFd>, target_fd: Option<OwnedFd>) {
23+
let source_raw_fd = source_fd.map_or(-1, |fd| fd.into_raw_fd());
24+
let target_raw_fd = target_fd.map_or(-1, |fd| fd.into_raw_fd());
2325
unsafe {
24-
ffi::g_subprocess_launcher_take_fd(
25-
self.to_glib_none().0,
26-
source_fd.into_raw_fd(),
27-
target_fd.into_raw_fd(),
28-
);
26+
ffi::g_subprocess_launcher_take_fd(self.to_glib_none().0, source_raw_fd, target_raw_fd);
2927
}
3028
}
3129

3230
#[cfg(unix)]
3331
#[cfg_attr(docsrs, doc(cfg(unix)))]
3432
#[doc(alias = "g_subprocess_launcher_take_stderr_fd")]
35-
pub fn take_stderr_fd(&self, fd: impl IntoRawFd) {
33+
pub fn take_stderr_fd(&self, fd: Option<OwnedFd>) {
3634
unsafe {
37-
ffi::g_subprocess_launcher_take_stderr_fd(self.to_glib_none().0, fd.into_raw_fd());
35+
let raw_fd = fd.map_or(-1, |fd| fd.into_raw_fd());
36+
ffi::g_subprocess_launcher_take_stderr_fd(self.to_glib_none().0, raw_fd);
3837
}
3938
}
4039

4140
#[cfg(unix)]
4241
#[cfg_attr(docsrs, doc(cfg(unix)))]
4342
#[doc(alias = "g_subprocess_launcher_take_stdin_fd")]
44-
pub fn take_stdin_fd(&self, fd: impl IntoRawFd) {
43+
pub fn take_stdin_fd(&self, fd: Option<OwnedFd>) {
44+
let raw_fd = fd.map_or(-1, |fd| fd.into_raw_fd());
4545
unsafe {
46-
ffi::g_subprocess_launcher_take_stdin_fd(self.to_glib_none().0, fd.into_raw_fd());
46+
ffi::g_subprocess_launcher_take_stdin_fd(self.to_glib_none().0, raw_fd);
4747
}
4848
}
4949

5050
#[cfg(unix)]
5151
#[cfg_attr(docsrs, doc(cfg(unix)))]
5252
#[doc(alias = "g_subprocess_launcher_take_stdout_fd")]
53-
pub fn take_stdout_fd(&self, fd: impl IntoRawFd) {
53+
pub fn take_stdout_fd(&self, fd: Option<OwnedFd>) {
54+
let raw_fd = fd.map_or(-1, |fd| fd.into_raw_fd());
5455
unsafe {
55-
ffi::g_subprocess_launcher_take_stdout_fd(self.to_glib_none().0, fd.into_raw_fd());
56+
ffi::g_subprocess_launcher_take_stdout_fd(self.to_glib_none().0, raw_fd);
5657
}
5758
}
5859
}

0 commit comments

Comments
 (0)