commit b3d3885b83bf70e259fb3e9f4545e5a250ccd3cb
parent fd24f6da73c219596b9167e8996a6e2f277f7d33
Author: Jose Lombera <jose@lombera.dev>
Date: Sat, 18 Jun 2022 20:35:30 -0500
rt: signal: change API to more sensible return types
Signed-off-by: Jose Lombera <jose@lombera.dev>
Diffstat:
4 files changed, 14 insertions(+), 36 deletions(-)
diff --git a/rt/+freebsd/signal.ha b/rt/+freebsd/signal.ha
@@ -3,46 +3,38 @@
// TODO: work when _NSIG != 32
-export fn sigemptyset(set: *sigset) int = {
+export fn sigemptyset(set: *sigset) void = {
for (let i = 0z; i < len(set.__bits); i += 1) {
set.__bits[i] = 0;
};
- return 0;
};
-export fn sigaddset(set: *sigset, signum: int) (int | errno) = {
+export fn sigaddset(set: *sigset, signum: int) (void | errno) = {
if (signum < 1 || signum > NSIG) {
return wrap_errno(EINVAL);
};
signum -= 1;
set.__bits[signum >> 5] |= (1 << signum): u32;
- return 0;
};
-export fn sigdelset(set: *sigset, signum: int) (int | errno) = {
+export fn sigdelset(set: *sigset, signum: int) (void | errno) = {
if (signum < 1 || signum > NSIG) {
return wrap_errno(EINVAL);
};
signum -= 1;
set.__bits[signum >> 5] &= ~(1 << signum: u32);
- return 0;
};
-export fn sigismember(set: *sigset, signum: int) (int | errno) = {
+export fn sigismember(set: *sigset, signum: int) (bool | errno) = {
if (signum < 1 || signum > NSIG) {
return wrap_errno(EINVAL);
};
signum -= 1;
- if ((set.__bits[signum >> 5] & (1 << signum: u32)) != 0) {
- return 1;
- } else {
- return 0;
- };
+ return (set.__bits[signum >> 5] & (1 << signum: u32)) != 0;
};
-export fn sigfillset(set: *sigset) (int | errno) = {
+export fn sigfillset(set: *sigset) (void | errno) = {
for (let i = 0z; i < len(set.__bits); i += 1) {
set.__bits[i] = ~0u32;
};
- return 0;
};
diff --git a/rt/+linux/signal.ha b/rt/+linux/signal.ha
@@ -3,45 +3,34 @@
// TODO: work when _NSIG != 64
-export fn sigemptyset(set: *sigset) int = {
- if (set.__val[0] == 0) {
- return 1;
- };
+export fn sigemptyset(set: *sigset) void = {
set.__val[0] = 0;
- return 0;
};
-export fn sigaddset(set: *sigset, signum: int) (int | errno) = {
+export fn sigaddset(set: *sigset, signum: int) (void | errno) = {
if (signum < 1 || signum > NSIG) {
return wrap_errno(EINVAL);
};
signum -= 1;
set.__val[0] |= (1 << signum): u64;
- return 0;
};
-export fn sigdelset(set: *sigset, signum: int) (int | errno) = {
+export fn sigdelset(set: *sigset, signum: int) (void | errno) = {
if (signum < 1 || signum > NSIG) {
return wrap_errno(EINVAL);
};
signum -= 1;
set.__val[0] &= ~(1 << signum: u64);
- return 0;
};
-export fn sigismember(set: *sigset, signum: int) (int | errno) = {
+export fn sigismember(set: *sigset, signum: int) (bool | errno) = {
if (signum < 1 || signum > NSIG) {
return wrap_errno(EINVAL);
};
signum -= 1;
- if ((set.__val[0] & (1 << signum: u64)) != 0) {
- return 1;
- } else {
- return 0;
- };
+ return (set.__val[0] & (1 << signum: u64)) != 0;
};
-export fn sigfillset(set: *sigset) (int | errno) = {
- set.__val[0] = 0xffffffffffffffff: u64;
- return 0;
+export fn sigfillset(set: *sigset) void = {
+ set.__val[0] = ~0u64;
};
diff --git a/rt/+test/signal.ha b/rt/+test/signal.ha
@@ -23,9 +23,6 @@
// It's ok to delete a signal that is not present in the set.
assert(!(sigdelset(&set, 10) is errno), "Unexpected error");
-
- // sigfillset() always succeeds.
- assert(!(sigfillset(&set) is errno), "Unexpected error");
};
// Test sigset operations fail for invalid signal numbers.
diff --git a/unix/signal/+linux.ha b/unix/signal/+linux.ha
@@ -130,7 +130,7 @@ export fn sigset_del(set: *sigset, items: signal...) void = {
// Returns true if the given signal is a member of this [[sigset]].
export fn sigset_member(set: *sigset, item: signal) bool = {
- return rt::sigismember(set, item)! == 1;
+ return rt::sigismember(set, item)!;
};
// Provides additional information about signal deliveries. Only the members