From 1200fdd3f6817df1842d40ae4233ccd4ba86d043 Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval R Date: Wed, 28 Dec 2022 10:28:31 +0100 Subject: [PATCH] wip: subprocess_launcher: Take owned fds Maybe it makes more sense to replace the older apis with the newer safe ones? --- gio/src/subprocess_launcher.rs | 40 +++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/gio/src/subprocess_launcher.rs b/gio/src/subprocess_launcher.rs index cf4caa5f083b..560967d9132a 100644 --- a/gio/src/subprocess_launcher.rs +++ b/gio/src/subprocess_launcher.rs @@ -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"))] @@ -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, @@ -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) } + } }