about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/bindings/quickjs.nim4
-rw-r--r--src/buffer/buffer.nim6
-rw-r--r--src/display/client.nim4
-rw-r--r--src/encoding/decoderstream.nim22
-rw-r--r--src/encoding/encoderstream.nim2
-rw-r--r--src/ips/serialize.nim4
-rw-r--r--src/types/url.nim6
-rw-r--r--src/utils/twtstr.nim4
8 files changed, 31 insertions, 21 deletions
diff --git a/src/bindings/quickjs.nim b/src/bindings/quickjs.nim
index c84b54d9..c438ae21 100644
--- a/src/bindings/quickjs.nim
+++ b/src/bindings/quickjs.nim
@@ -41,10 +41,10 @@ when sizeof(int) < sizeof(int64):
     cast[pointer](v)
 
   template JS_MKVAL*(t, val: untyped): JSValue =
-    JSValue((cast[uint64](t) shl 32) or cast[uint32](val))
+    JSValue((cast[uint64](int64(t)) shl 32) or uint32(val))
 
   template JS_MKPTR*(t, p: untyped): JSValue =
-    JSValue((cast[uint64](t) shl 32) or cast[uint](p))
+    JSValue((cast[uint64](int64(t)) shl 32) or cast[uint](p))
 
   proc `==`*(a, b: JSValue): bool {.borrow.}
 else:
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim
index 7354d94b..9b464dfd 100644
--- a/src/buffer/buffer.nim
+++ b/src/buffer/buffer.nim
@@ -649,7 +649,7 @@ proc setupSource(buffer: Buffer): ConnectResult =
     #TODO clone should probably just fork() the buffer instead.
     let s = connectSocketStream(source.clonepid, blocking = false)
     buffer.istream = s
-    buffer.fd = cast[int](s.source.getFd())
+    buffer.fd = int(s.source.getFd())
     if buffer.istream == nil:
       result.code = ERROR_SOURCE_NOT_FOUND
       return
@@ -671,7 +671,7 @@ proc setupSource(buffer: Buffer): ConnectResult =
       buffer.contenttype = response.contenttype
     buffer.istream = response.body
     let fd = SocketStream(response.body).source.getFd()
-    buffer.fd = cast[int](fd)
+    buffer.fd = int(fd)
     result.needsAuth = response.status == 401 # Unauthorized
     result.redirect = response.redirect
     if "Set-Cookie" in response.headers.table:
@@ -1206,7 +1206,9 @@ proc handleError(buffer: Buffer, fd: int, err: OSErrorCode) =
 proc runBuffer(buffer: Buffer, rfd: int) =
   buffer.rfd = rfd
   while buffer.alive:
+    {.warning[CastSizes]:off.} # not our bug. TODO remove when fixed
     let events = buffer.selector.select(-1)
+    {.warning[CastSizes]:on.}
     for event in events:
       if Read in event.events:
         buffer.handleRead(event.fd)
diff --git a/src/display/client.nim b/src/display/client.nim
index 6b18e092..7dbf4713 100644
--- a/src/display/client.nim
+++ b/src/display/client.nim
@@ -370,7 +370,9 @@ proc inputLoop(client: Client) =
   selector.registerHandle(int(client.console.tty.getFileHandle()), {Read}, nil)
   let sigwinch = selector.registerSignal(int(SIGWINCH), nil)
   while true:
+    {.warning[CastSizes]:off.} # not our bug. TODO remove when fixed
     let events = client.selector.select(-1)
+    {.warning[CastSizes]:on.}
     for event in events:
       if Read in event.events:
         client.handleRead(event.fd)
@@ -503,7 +505,7 @@ proc launchClient*(client: Client, pages: seq[string], ctype: Option[string],
     else:
       dump = true
   client.ssock = initServerSocket(false, false)
-  client.fd = cast[int](client.ssock.sock.getFd())
+  client.fd = int(client.ssock.sock.getFd())
   let selector = newSelector[Container]()
   selector.registerHandle(client.fd, {Read}, nil)
   let efd = int(client.dispatcher.forkserver.estream.fd)
diff --git a/src/encoding/decoderstream.nim b/src/encoding/decoderstream.nim
index 8bfd4d10..62e69f7f 100644
--- a/src/encoding/decoderstream.nim
+++ b/src/encoding/decoderstream.nim
@@ -76,7 +76,7 @@ template append_codepoint(stream: DecoderStream, c: uint32, oq: ptr UncheckedArr
     append_codepoint_buf stream, c
 
 template append_codepoint(stream: DecoderStream, c: char, oq: ptr UncheckedArray[uint32], olen: int, n: var int) =
-  stream.append_codepoint cast[uint32](c), oq, olen, n
+  stream.append_codepoint uint32(c), oq, olen, n
 
 proc handleError(stream: DecoderStream, oq: ptr UncheckedArray[uint32], olen: int, n: var int) =
   case stream.errormode
@@ -100,29 +100,29 @@ proc decodeUTF8(stream: DecoderStream, iq: var seq[uint8], oq: ptr UncheckedArra
         stream.append_codepoint uint32(b), oq, olen, n
       of 0xC2u8 .. 0xDFu8:
         needed = 1
-        c = cast[uint32](b) and 0x1F
+        c = uint32(b) and 0x1F
       of 0xE0u8:
         bounds.a = 0xA0
         needed = 2
-        c = cast[uint32](b) and 0xF
+        c = uint32(b) and 0xF
       of 0xEDu8:
         bounds.b = 0x9F
         needed = 2
-        c = cast[uint32](b) and 0xF
+        c = uint32(b) and 0xF
       of 0xE1u8 .. 0xECu8, 0xEEu8 .. 0xEFu8:
         needed = 2
-        c = cast[uint32](b) and 0xF
+        c = uint32(b) and 0xF
       of 0xF0u8:
         bounds.a = 0x90
         needed = 3
-        c = cast[uint32](b) and 0x7
+        c = uint32(b) and 0x7
       of 0xF4u8:
         bounds.b = 0x8F
         needed = 3
-        c = cast[uint32](b) and 0x7
+        c = uint32(b) and 0x7
       of 0xF1u8 .. 0xF3u8:
         needed = 3
-        c = cast[uint32](b) and 0x7
+        c = uint32(b) and 0x7
       else:
         stream.handleError(oq, olen, n)
         if stream.isend: # fatal error
@@ -173,7 +173,7 @@ proc gb18RangesCodepoint(p: uint32): uint32 =
     # is found.
     # We want the last that is <=, so decrease index by one.
     let i = upperBound(Gb18030RangesDecode, p, func(a: tuple[p, ucs: uint16], b: uint32): int =
-      cmp(cast[uint32](a.p), b))
+      cmp(uint32(a.p), b))
     let elem = Gb18030RangesDecode[i - 1]
     offset = elem.p
     c = elem.ucs
@@ -618,7 +618,7 @@ proc decodeXUserDefined(stream: DecoderStream, iq: var seq[uint8],
     if c in Ascii:
       stream.append_codepoint c, oq, olen, n
     else:
-      let c = 0xF780 + cast[uint32](c) - 0x80
+      let c = 0xF780 + uint32(c) - 0x80
       stream.append_codepoint c, oq, olen, n
 
 proc decodeSingleByte(stream: DecoderStream, iq: var seq[uint8],
@@ -633,7 +633,7 @@ proc decodeSingleByte(stream: DecoderStream, iq: var seq[uint8],
       if p == 0u16:
         stream.handleError(oq, olen, n)
       else:
-        stream.append_codepoint cast[uint32](p), oq, olen, n
+        stream.append_codepoint uint32(p), oq, olen, n
 
 proc decodeReplacement(stream: DecoderStream, oq: ptr UncheckedArray[uint32], olen: int, n: var int) =
   if not stream.replreported:
diff --git a/src/encoding/encoderstream.nim b/src/encoding/encoderstream.nim
index 56d4c3da..397d43d8 100644
--- a/src/encoding/encoderstream.nim
+++ b/src/encoding/encoderstream.nim
@@ -98,7 +98,7 @@ proc gb18030RangesPointer(c: uint32): uint32 =
     # is found.
     # We want the last that is <=, so decrease index by one.
     let i = upperBound(Gb18030RangesEncode, c, func(a: tuple[ucs, p: uint16], b: uint32): int =
-      cmp(cast[uint32](a.ucs), b))
+      cmp(uint32(a.ucs), b))
     let elem = Gb18030RangesEncode[i - 1]
     offset = elem.ucs
     p = elem.p
diff --git a/src/ips/serialize.nim b/src/ips/serialize.nim
index 54b44a41..9898c0cd 100644
--- a/src/ips/serialize.nim
+++ b/src/ips/serialize.nim
@@ -92,7 +92,9 @@ func slen*(n: SomeNumber): int =
   return sizeof(n)
 
 proc swrite*[T: enum](stream: Stream, x: T) =
-  stream.swrite(cast[int](x))
+  static:
+    doAssert sizeof(int) >= sizeof(T)
+  stream.swrite(int(x))
 
 proc sread*[T: enum](stream: Stream, x: var T) =
   var i: int
diff --git a/src/types/url.nim b/src/types/url.nim
index b8b4913a..727d7b84 100644
--- a/src/types/url.nim
+++ b/src/types/url.nim
@@ -798,7 +798,11 @@ func serializeip(ipv6: array[8, uint16]): string =
         result &= ':'
       ignore0 = true
       continue
-    result &= toHex(ipv6[i])
+    const HexChars = "0123456789abcdef"
+    var x = ipv6[i]
+    while x != 0:
+      result &= HexChars[x mod 0x10]
+      x = x div 0x10
     if i != high(ipv6):
       result &= ':'
 
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 0c37439a..c7ba2db6 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -967,8 +967,8 @@ const DoubleWidthTable = (func(): PropertyTable =
   var ptab = makePropertyTable(DoubleWidthRanges, Combining)
   # Control chars return a width of 2, and are displayed as ^{letter}.
   for c in Controls:
-    let i = cast[uint16](c) div 8
-    case cast[uint16](c) mod 8
+    let i = uint16(c) div 8
+    case uint16(c) mod 8
     of 0: ptab[i] = ptab[i] or 0x01
     of 1: ptab[i] = ptab[i] or 0x02
     of 2: ptab[i] = ptab[i] or 0x04