From b0e45d3e92cc59f6d436642e7488a1ec3972b1f0 Mon Sep 17 00:00:00 2001 From: tompro Date: Sat, 24 Feb 2024 12:23:49 +0100 Subject: [PATCH] ref --- src/kernel/src/errno.rs | 2 +- src/kernel/src/signal/mod.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/kernel/src/errno.rs b/src/kernel/src/errno.rs index c569feb12..87d404f65 100644 --- a/src/kernel/src/errno.rs +++ b/src/kernel/src/errno.rs @@ -14,7 +14,7 @@ macro_rules! error_numbers { }; )* - pub fn strerror_impl(num: NonZeroI32) -> &'static str { + fn strerror_impl(num: NonZeroI32) -> &'static str { match num { $( $name => $desc, )* _ => todo!("strerror {num}", num = num.get()), diff --git a/src/kernel/src/signal/mod.rs b/src/kernel/src/signal/mod.rs index 302743fde..2d5e03248 100644 --- a/src/kernel/src/signal/mod.rs +++ b/src/kernel/src/signal/mod.rs @@ -11,7 +11,7 @@ mod set; pub struct Signal(NonZeroI32); impl Signal { - pub fn new(raw: i32) -> Option { + pub const fn new(raw: i32) -> Option { match raw { 1..=SIG_MAXSIG => Some(Signal(unsafe { NonZeroI32::new_unchecked(raw) })), _ => None, @@ -27,13 +27,13 @@ macro_rules! signals { ($($name:ident($num:expr),)*) => { $( #[allow(dead_code)] - pub const $name: Signal = Signal(unsafe { - assert!($num > 0 && $num <= SIG_MAXSIG); - NonZeroI32::new_unchecked($num) - }); + pub const $name: Signal = match Signal::new($num) { + Some(sig) => sig, + None => panic!(), + }; )* - pub fn strsignal_impl(sig: Signal) -> Cow<'static, str> { + fn strsignal_impl(sig: Signal) -> Cow<'static, str> { match sig.0.get() { $( $num => Cow::Borrowed(stringify!($name)), )* _ => format!("{sig}", sig = sig.get()).into(),