Skip to content

Commit

Permalink
wip: subprocess_launcher: Take owned fds
Browse files Browse the repository at this point in the history
Maybe it makes more sense to replace the older apis with the newer safe ones?
  • Loading branch information
A6GibKm committed Dec 28, 2022
1 parent 1b6180d commit 1200fdd
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions gio/src/subprocess_launcher.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Take a look at the license at the top of the repository in the LICENSE file.

#[cfg(any(unix, all(feature = "dox", unix)))]
use std::os::unix::io::IntoRawFd;
use std::os::unix::io::{IntoRawFd, OwnedFd};

#[cfg(any(unix, feature = "dox"))]
#[cfg(any(unix, feature = "dox"))]
Expand All @@ -20,7 +20,7 @@ impl SubprocessLauncher {
#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[doc(alias = "g_subprocess_launcher_take_fd")]
pub fn take_fd(&self, source_fd: impl IntoRawFd, target_fd: impl IntoRawFd) {
pub unsafe fn take_fd(&self, source_fd: impl IntoRawFd, target_fd: impl IntoRawFd) {
unsafe {
ffi::g_subprocess_launcher_take_fd(
self.to_glib_none().0,
Expand All @@ -30,30 +30,60 @@ impl SubprocessLauncher {
}
}

#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[doc(alias = "g_subprocess_launcher_take_fd")]
pub fn take_owned_fd(&self, source_fd: OwnedFd, target_fd: OwnedFd) {
unsafe { self.take_fd(source_fd, target_fd) }
}

#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[doc(alias = "g_subprocess_launcher_take_stderr_fd")]
pub fn take_stderr_fd(&self, fd: impl IntoRawFd) {
pub unsafe fn take_stderr_fd(&self, fd: impl IntoRawFd) {
unsafe {
ffi::g_subprocess_launcher_take_stderr_fd(self.to_glib_none().0, fd.into_raw_fd());
}
}

#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[doc(alias = "g_subprocess_launcher_take_stderr_fd")]
pub fn take_stderr_owned_fd(&self, fd: OwnedFd) {
unsafe {
self.take_stderr_fd(fd);
}
}

#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[doc(alias = "g_subprocess_launcher_take_stdin_fd")]
pub fn take_stdin_fd(&self, fd: impl IntoRawFd) {
pub unsafe fn take_stdin_fd(&self, fd: impl IntoRawFd) {
unsafe {
ffi::g_subprocess_launcher_take_stdin_fd(self.to_glib_none().0, fd.into_raw_fd());
}
}

#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[doc(alias = "g_subprocess_launcher_take_stdin_fd")]
pub fn take_stdin_owned_fd(&self, fd: OwnedFd) {
unsafe { self.take_stdin_fd(fd) }
}

#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[doc(alias = "g_subprocess_launcher_take_stdout_fd")]
pub fn take_stdout_fd(&self, fd: impl IntoRawFd) {
pub unsafe fn take_stdout_fd(&self, fd: impl IntoRawFd) {
unsafe {
ffi::g_subprocess_launcher_take_stdout_fd(self.to_glib_none().0, fd.into_raw_fd());
}
}

#[cfg(any(unix, feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(unix)))]
#[doc(alias = "g_subprocess_launcher_take_stdout_fd")]
pub fn take_stdout_owned_fd(&self, fd: OwnedFd) {
unsafe { self.take_stdout_fd(fd) }
}
}

0 comments on commit 1200fdd

Please sign in to comment.