Skip to content

Commit b8c5eb6

Browse files
committed
wip: subprocess_launcher: Take owned fds
Maybe it makes more sense to replace the older apis with the newer safe ones?
1 parent d7727a4 commit b8c5eb6

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

gio/src/subprocess_launcher.rs

Lines changed: 35 additions & 5 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(feature = "dox", unix)))]
4-
use std::os::unix::io::IntoRawFd;
4+
use std::os::unix::io::{IntoRawFd, OwnedFd};
55

66
#[cfg(any(unix, feature = "dox"))]
77
#[cfg(any(unix, feature = "dox"))]
@@ -20,7 +20,7 @@ impl SubprocessLauncher {
2020
#[cfg(any(unix, feature = "dox"))]
2121
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
2222
#[doc(alias = "g_subprocess_launcher_take_fd")]
23-
pub fn take_fd(&self, source_fd: impl IntoRawFd, target_fd: impl IntoRawFd) {
23+
pub unsafe fn take_fd(&self, source_fd: impl IntoRawFd, target_fd: impl IntoRawFd) {
2424
unsafe {
2525
ffi::g_subprocess_launcher_take_fd(
2626
self.to_glib_none().0,
@@ -30,30 +30,60 @@ impl SubprocessLauncher {
3030
}
3131
}
3232

33+
#[cfg(any(unix, feature = "dox"))]
34+
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
35+
#[doc(alias = "g_subprocess_launcher_take_fd")]
36+
pub fn take_owned_fd(&self, source_fd: OwnedFd, target_fd: OwnedFd) {
37+
unsafe { self.take_fd(source_fd, target_fd) }
38+
}
39+
3340
#[cfg(any(unix, feature = "dox"))]
3441
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
3542
#[doc(alias = "g_subprocess_launcher_take_stderr_fd")]
36-
pub fn take_stderr_fd(&self, fd: impl IntoRawFd) {
43+
pub unsafe fn take_stderr_fd(&self, fd: impl IntoRawFd) {
3744
unsafe {
3845
ffi::g_subprocess_launcher_take_stderr_fd(self.to_glib_none().0, fd.into_raw_fd());
3946
}
4047
}
4148

49+
#[cfg(any(unix, feature = "dox"))]
50+
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
51+
#[doc(alias = "g_subprocess_launcher_take_stderr_fd")]
52+
pub fn take_stderr_owned_fd(&self, fd: OwnedFd) {
53+
unsafe {
54+
self.take_stderr_fd(fd);
55+
}
56+
}
57+
4258
#[cfg(any(unix, feature = "dox"))]
4359
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
4460
#[doc(alias = "g_subprocess_launcher_take_stdin_fd")]
45-
pub fn take_stdin_fd(&self, fd: impl IntoRawFd) {
61+
pub unsafe fn take_stdin_fd(&self, fd: impl IntoRawFd) {
4662
unsafe {
4763
ffi::g_subprocess_launcher_take_stdin_fd(self.to_glib_none().0, fd.into_raw_fd());
4864
}
4965
}
5066

67+
#[cfg(any(unix, feature = "dox"))]
68+
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
69+
#[doc(alias = "g_subprocess_launcher_take_stdin_fd")]
70+
pub fn take_stdin_owned_fd(&self, fd: OwnedFd) {
71+
unsafe { self.take_stdin_fd(fd) }
72+
}
73+
5174
#[cfg(any(unix, feature = "dox"))]
5275
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
5376
#[doc(alias = "g_subprocess_launcher_take_stdout_fd")]
54-
pub fn take_stdout_fd(&self, fd: impl IntoRawFd) {
77+
pub unsafe fn take_stdout_fd(&self, fd: impl IntoRawFd) {
5578
unsafe {
5679
ffi::g_subprocess_launcher_take_stdout_fd(self.to_glib_none().0, fd.into_raw_fd());
5780
}
5881
}
82+
83+
#[cfg(any(unix, feature = "dox"))]
84+
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
85+
#[doc(alias = "g_subprocess_launcher_take_stdout_fd")]
86+
pub fn take_stdout_owned_fd(&self, fd: OwnedFd) {
87+
unsafe { self.take_stdout_fd(fd) }
88+
}
5989
}

0 commit comments

Comments
 (0)