Fix RangeError defect being happened using android toolchain. (#538)

* Fix RangeError defect being happened using android toolchain.

* Set proper type for `Tnfds`.

* Update comment.
This commit is contained in:
Eugene Kabanov 2024-04-25 19:08:53 +03:00 committed by GitHub
parent bb96f02ae8
commit 72f560f049
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View File

@ -220,7 +220,10 @@ proc selectInto2*[T](s: Selector[T], timeout: int,
verifySelectParams(timeout, -1, int(high(cint)))
let
maxEventsCount = min(len(s.pollfds), len(readyKeys))
maxEventsCount = culong(min(len(s.pollfds), len(readyKeys)))
# Without `culong` conversion, this code could fail with RangeError
# defect on explicit Tnfds(integer) conversion (probably related to
# combination of nim+clang (android toolchain)).
eventsCount =
if maxEventsCount > 0:
let res = handleEintr(poll(addr(s.pollfds[0]), Tnfds(maxEventsCount),

View File

@ -965,7 +965,7 @@ elif defined(macos) or defined(macosx):
events*: cshort
revents*: cshort
Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = cuint
Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = culong
const
POLLIN* = 0x0001