Skip to content

Commit

Permalink
Fix cmpRunesIgnoreCase on system where sizeof(int) < 4. Fixes #23125. (
Browse files Browse the repository at this point in the history
…#23138)

Fixes an issue where importing the `strutils` module, or any other
importing the `strutils` module, ends up with a compile time error on
platforms where ints are less then 32-bit wide.

The fix follows the suggestions made in #23125.
  • Loading branch information
Abathargh authored Dec 28, 2023
1 parent 1324d2e commit 15c7b76
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/pure/unicode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,12 @@ proc cmpRunesIgnoreCase*(a, b: openArray[char]): int {.rtl, extern: "nuc$1".} =
# slow path:
fastRuneAt(a, i, ar)
fastRuneAt(b, j, br)
result = RuneImpl(toLower(ar)) - RuneImpl(toLower(br))
when sizeof(int) < 4:
const lo = low(int).int32
const hi = high(int).int32
result = clamp(RuneImpl(toLower(ar)) - RuneImpl(toLower(br)), lo, hi).int
else:
result = RuneImpl(toLower(ar)) - RuneImpl(toLower(br))
if result != 0: return
result = a.len - b.len

Expand Down

0 comments on commit 15c7b76

Please sign in to comment.