Skip to content

Commit

Permalink
Fix sysrand for Android (and some other POSIX platforms) (#1391)
Browse files Browse the repository at this point in the history
## Summary
Fixes a bug that caused the compiler to fail to compile anything with
e.g.  `--os:android`  (and some uncommon POSIX platforms) when it uses 
`sysrand`  in any way, such as when importing  `random` .  `koch`  was
affected so one couldn't bootstrap nimskull in android as the host
platform.

## Details
There's two POSIX constants used in  `sysrand.nim`  that are not
actually constants for some platforms like Android.  `EINTR`  and 
`EAGAIN`  are required to be constants at compile time because they're
used in a  `case of`  but the condition is so simple that we can replace
it by an  `if`  statement.

They're technically constants in all platforms, but on the C side (taken
from  `errno.h` ), not in nimskull, and the latter is oblivious to the
content of those header files.
  • Loading branch information
starsiderfox authored Jul 31, 2024
1 parent 4fed1a6 commit f84f175
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/std/sysrand.nim
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ elif defined(linux) and not defined(emscripten):
elif readBytes > 0:
inc(result, readBytes)
else:
case osLastError().int
of EINTR, EAGAIN:
let err = osLastError().int
if err == EINTR or err == EAGAIN:
discard
else:
result = -1
Expand Down

0 comments on commit f84f175

Please sign in to comment.