Skip to content

Commit 72f560f

Browse files
authored
Fix RangeError defect being happened using android toolchain. (#538)
* Fix RangeError defect being happened using android toolchain. * Set proper type for `Tnfds`. * Update comment.
1 parent bb96f02 commit 72f560f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

chronos/ioselects/ioselectors_poll.nim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ proc selectInto2*[T](s: Selector[T], timeout: int,
220220
verifySelectParams(timeout, -1, int(high(cint)))
221221
222222
let
223-
maxEventsCount = min(len(s.pollfds), len(readyKeys))
223+
maxEventsCount = culong(min(len(s.pollfds), len(readyKeys)))
224+
# Without `culong` conversion, this code could fail with RangeError
225+
# defect on explicit Tnfds(integer) conversion (probably related to
226+
# combination of nim+clang (android toolchain)).
224227
eventsCount =
225228
if maxEventsCount > 0:
226229
let res = handleEintr(poll(addr(s.pollfds[0]), Tnfds(maxEventsCount),

chronos/osdefs.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ elif defined(macos) or defined(macosx):
965965
events*: cshort
966966
revents*: cshort
967967
968-
Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = cuint
968+
Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = culong
969969
970970
const
971971
POLLIN* = 0x0001

0 commit comments

Comments
 (0)