From 9df5abfab1f315d87bdacf226380d532318e9bfb Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Mon, 9 Aug 2021 13:28:43 -0600 Subject: Optionally implement TryFrom in libc_enum! This saves code in several separate places that need to do this separately. At the same time, remove a few uses of mem::transmute that were implementing TryFrom or similar functionality. Issue #373 --- src/sys/signal.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src/sys/signal.rs') diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 0911cfaa..8698d14f 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -6,7 +6,6 @@ use crate::{Error, Result}; use crate::errno::Errno; use crate::unistd::Pid; -use std::convert::TryFrom; use std::mem; use std::fmt; use std::str::FromStr; @@ -71,6 +70,7 @@ libc_enum!{ target_os = "redox")))] SIGINFO, } + impl TryFrom } impl FromStr for Signal { @@ -335,8 +335,6 @@ const SIGNALS: [Signal; 31] = [ SIGEMT, SIGINFO]; -pub const NSIG: libc::c_int = 32; - #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct SignalIterator { next: usize, @@ -362,18 +360,6 @@ impl Signal { } } -impl TryFrom for Signal { - type Error = Error; - - fn try_from(signum: libc::c_int) -> Result { - if 0 < signum && signum < NSIG { - Ok(unsafe { mem::transmute(signum) }) - } else { - Err(Error::from(Errno::EINVAL)) - } - } -} - pub const SIGIOT : Signal = SIGABRT; pub const SIGPOLL : Signal = SIGIO; pub const SIGUNUSED : Signal = SIGSYS; @@ -489,6 +475,8 @@ impl SigSet { /// signal mask becomes pending, and returns the accepted signal. #[cfg(not(target_os = "redox"))] // RedoxFS does not yet support sigwait pub fn wait(&self) -> Result { + use std::convert::TryFrom; + let mut signum = mem::MaybeUninit::uninit(); let res = unsafe { libc::sigwait(&self.sigset as *const libc::sigset_t, signum.as_mut_ptr()) }; -- cgit v1.2.3