diff options
| -rw-r--r-- | adapter/img/canvas.nim | 2 | ||||
| -rw-r--r-- | adapter/img/nanosvg.nim | 2 | ||||
| -rw-r--r-- | src/io/dynstream.nim | 4 | ||||
| -rw-r--r-- | src/io/packetreader.nim | 4 | ||||
| -rw-r--r-- | src/io/packetwriter.nim | 2 | ||||
| -rw-r--r-- | src/server/loader.nim | 2 | ||||
| -rw-r--r-- | src/types/path.nim | 2 | ||||
| -rw-r--r-- | src/utils/luwrap.nim | 2 | ||||
| -rw-r--r-- | src/utils/myaddr.nim | 23 |
9 files changed, 24 insertions, 19 deletions
diff --git a/adapter/img/canvas.nim b/adapter/img/canvas.nim index e1d76340..792124f7 100644 --- a/adapter/img/canvas.nim +++ b/adapter/img/canvas.nim @@ -75,7 +75,7 @@ proc loadUnifont(unifont: string): Bitmap = cint(unifont.len), addr width, addr height, addr comp, 4) let len = width * height let bitmap = Bitmap( - px: cast[seq[RGBAColorBE]](newSeqUninitialized[uint32](len)), + px: cast[seq[RGBAColorBE]](newSeqUninit[uint32](len)), width: int(width), height: int(height) ) diff --git a/adapter/img/nanosvg.nim b/adapter/img/nanosvg.nim index dd3df266..8ca8b7d9 100644 --- a/adapter/img/nanosvg.nim +++ b/adapter/img/nanosvg.nim @@ -60,7 +60,7 @@ proc main() = if hdr.until(':') == "Cha-Image-Info-Only" and v == "1": return let r = nsvgCreateRasterizer() - var obuf = newSeqUninitialized[uint8](width * height * 4) + var obuf = newSeqUninit[uint8](width * height * 4) r.nsvgRasterize(image, 0, 0, 1, addr obuf[0], width, height, width * 4) discard os.writeDataLoop(obuf) r.nsvgDeleteRasterizer() diff --git a/src/io/dynstream.nim b/src/io/dynstream.nim index 89d9dac7..786a414b 100644 --- a/src/io/dynstream.nim +++ b/src/io/dynstream.nim @@ -341,7 +341,7 @@ proc sendMsg*(s: SocketStream; buffer: openArray[uint8]; var iov = IOVec(iov_base: unsafeAddr buffer[0], iov_len: csize_t(buffer.len)) let fdSize = sizeof(cint) * fds.len let controlLen = CMSG_SPACE(csize_t(fdSize)) - var cmsgBuf = newSeqUninitialized[uint8](controlLen) + var cmsgBuf = newSeqUninit[uint8](controlLen) var hdr = Tmsghdr( msg_iov: addr iov, msg_iovlen: 1, @@ -362,7 +362,7 @@ proc recvMsg*(s: SocketStream; buffer: var openArray[uint8]; var iov = IOVec(iov_base: addr buffer[0], iov_len: csize_t(buffer.len)) let fdbufSize = sizeof(cint) * fdbuf.len let controlLen = CMSG_SPACE(csize_t(fdbufSize)) - var cmsgBuf = newSeqUninitialized[uint8](controlLen) + var cmsgBuf = newSeqUninit[uint8](controlLen) var hdr = Tmsghdr( msg_iov: addr iov, msg_iovlen: 1, diff --git a/src/io/packetreader.nim b/src/io/packetreader.nim index fb9eef10..22a10811 100644 --- a/src/io/packetreader.nim +++ b/src/io/packetreader.nim @@ -29,8 +29,8 @@ proc sread*(r: var PacketReader; c: var CellColor) proc initReader*(stream: DynStream; len, nfds: int): PacketReader = assert len != 0 or nfds != 0 var r = PacketReader( - buffer: newSeqUninitialized[uint8](len), - fds: newSeqUninitialized[cint](nfds), + buffer: newSeqUninit[uint8](len), + fds: newSeqUninit[cint](nfds), bufIdx: 0 ) if not stream.readDataLoop(r.buffer): diff --git a/src/io/packetwriter.nim b/src/io/packetwriter.nim index 6c99ae8a..0c31b602 100644 --- a/src/io/packetwriter.nim +++ b/src/io/packetwriter.nim @@ -41,7 +41,7 @@ const InitLen = sizeof(int) * 2 const SizeInit = max(64, InitLen) proc initPacketWriter*(): PacketWriter = return PacketWriter( - buffer: newSeqUninitialized[uint8](SizeInit), + buffer: newSeqUninit[uint8](SizeInit), bufLen: InitLen ) diff --git a/src/server/loader.nim b/src/server/loader.nim index 624d49ca..54e75629 100644 --- a/src/server/loader.nim +++ b/src/server/loader.nim @@ -222,7 +222,7 @@ template isEmpty(output: OutputHandle): bool = output.currentBuffer == nil and not output.suspended proc newLoaderBuffer(size = LoaderBufferPageSize): LoaderBuffer = - return LoaderBuffer(page: newSeqUninitialized[uint8](size)) + return LoaderBuffer(page: newSeqUninit[uint8](size)) proc newLoaderBuffer(s: openArray[char]): LoaderBuffer = let buffer = newLoaderBuffer(s.len) diff --git a/src/types/path.nim b/src/types/path.nim index dba83a26..966eeb32 100644 --- a/src/types/path.nim +++ b/src/types/path.nim @@ -118,7 +118,7 @@ proc newIdentityMatrix*(n: int): Matrix = proc newMatrixUninitialized(w, h: int): Matrix = return Matrix( - me: newSeqUninitialized[float64](w * h), + me: newSeqUninit[float64](w * h), w: w, h: h ) diff --git a/src/utils/luwrap.nim b/src/utils/luwrap.nim index ca5fe410..0d778ac6 100644 --- a/src/utils/luwrap.nim +++ b/src/utils/luwrap.nim @@ -20,7 +20,7 @@ proc normalize*(rs: seq[uint32]; form = UNICODE_NFC): seq[uint32] = raise newException(Defect, "Unicode normalization failed") if out_len == 0: return - var rs = newSeqUninitialized[uint32](out_len) + var rs = newSeqUninit[uint32](out_len) copyMem(addr rs[0], outbuf, out_len * sizeof(uint32)) dealloc(outbuf) return rs diff --git a/src/utils/myaddr.nim b/src/utils/myaddr.nim index 6eee071f..425662c3 100644 --- a/src/utils/myaddr.nim +++ b/src/utils/myaddr.nim @@ -1,18 +1,23 @@ # Before 2.0, `addr' only worked on mutable types, and `unsafeAddr' # was needed to take the address of immutable ones. # -# This was changed in 2.0 for some incomprehensible reason, so now to -# write code that compiles on both versions you have to take care that -# you use the right overload without compiler help. +# This was changed in 2.0 for some incomprehensible reason, even though +# it's still a useful distinction (it catches bugs). # # This module fixes the above problem; it is automatically included # in every file by nim.cfg. +# +# Additionally, this adds a backport of newSeqUninit which is exactly +# the same as newSeqUninitialized but with a different name. + +const msg = "expression has no address; maybe use `unsafeAddr'" -when NimMajor >= 2: - const msg = "expression has no address; maybe use `unsafeAddr'" +template addr(x: auto): auto {.used, error: msg.} = + discard - template addr(x: auto): auto {.used, error: msg.} = - discard +template addr(x: var auto): auto {.used.} = + system.addr x - template addr(x: var auto): auto {.used.} = - system.addr x +when not declared(newSeqUninit): + template newSeqUninit[T](len: int): seq[T] = + newSeqUninitialized[T](len) |