diff --git a/async_postgres/async_backend.nim b/async_postgres/async_backend.nim index 135c8ba..734e8df 100644 --- a/async_postgres/async_backend.nim +++ b/async_postgres/async_backend.nim @@ -189,7 +189,7 @@ elif hasAsyncDispatch: ## On asyncdispatch this is a **no-op** — the future is neither cancelled ## nor awaited. asyncdispatch has no cancellation primitive. Callers must ## not assume the future has stopped: any buffer it holds via - ## `unsafeAddr` remains live, and any socket write it scheduled will + ## `addr` remains live, and any socket write it scheduled will ## still complete. Do not reuse the affected resource (socket, buffer) ## after calling this under asyncdispatch. chronos cancels the future ## properly. diff --git a/async_postgres/pg_bearssl.nim b/async_postgres/pg_bearssl.nim index f8a359c..82434d6 100644 --- a/async_postgres/pg_bearssl.nim +++ b/async_postgres/pg_bearssl.nim @@ -142,7 +142,7 @@ when hasChronos: var dnBuf: seq[byte] var decoder: X509DecoderContext initX509Decoder(decoder, addr dnBuf) - x509DecoderPush(decoder, unsafeAddr item.data[0], uint(item.data.len)) + x509DecoderPush(decoder, addr item.data[0], uint(item.data.len)) if x509DecoderLastError(decoder) != 0: continue diff --git a/async_postgres/pg_client.nim b/async_postgres/pg_client.nim index 555f11f..887aa0b 100644 --- a/async_postgres/pg_client.nim +++ b/async_postgres/pg_client.nim @@ -407,9 +407,9 @@ template appendInlineParam( let oldLen = data.len data.setLen(oldLen + int(p.len)) if p.len <= PgInlineBufSize: - copyMem(addr data[oldLen], unsafeAddr p.inlineBuf[0], int(p.len)) + copyMem(addr data[oldLen], addr p.inlineBuf[0], int(p.len)) else: - copyMem(addr data[oldLen], unsafeAddr p.overflow[0], int(p.len)) + copyMem(addr data[oldLen], addr p.overflow[0], int(p.len)) ranges.add((dataOff, p.len)) proc flattenInline( @@ -1612,7 +1612,7 @@ proc copyIn*( ## Converts to bytes internally; avoids manual toOpenArrayByte. var bytes = newSeq[byte](data.len) if data.len > 0: - copyMem(addr bytes[0], unsafeAddr data[0], data.len) + copyMem(addr bytes[0], addr data[0], data.len) copyIn(conn, sql, bytes, timeout) proc copyIn*( @@ -1631,7 +1631,7 @@ proc copyIn*( var offset = 0 for chunk in data: if chunk.len > 0: - copyMem(addr combined[offset], unsafeAddr chunk[0], chunk.len) + copyMem(addr combined[offset], addr chunk[0], chunk.len) offset += chunk.len copyIn(conn, sql, combined, timeout) @@ -2699,7 +2699,7 @@ proc executeImpl( when hasChronos: # Abnormal path (recv error, cancellation, failed stored write): # ensure sendFut never escapes as an unhandled Future and that no - # in-flight write still holds unsafeAddr conn.sendBuf[0]. + # in-flight write still holds addr conn.sendBuf[0]. if not sendFut.finished: try: await cancelAndWait(sendFut) diff --git a/async_postgres/pg_connection.nim b/async_postgres/pg_connection.nim index a51014e..022317b 100644 --- a/async_postgres/pg_connection.nim +++ b/async_postgres/pg_connection.nim @@ -797,7 +797,7 @@ when hasAsyncDispatch: var fut = newFuture[void]("sendRawBytes") fut.complete() return fut - sendRawData(socket, unsafeAddr data[0], data.len) + sendRawData(socket, addr data[0], data.len) proc compactRecvBuf(conn: PgConnection) {.inline.} = ## Shift unconsumed data to the front of recvBuf, reclaiming space consumed @@ -847,7 +847,7 @@ proc fillRecvBuf*( raise newException(PgConnectionError, "Connection closed by server") let oldLen = conn.recvBuf.len conn.recvBuf.setLen(oldLen + data.len) - copyMem(addr conn.recvBuf[oldLen], unsafeAddr data[0], data.len) + copyMem(addr conn.recvBuf[oldLen], addr data[0], data.len) proc nextMessage*( conn: PgConnection, rowData: RowData = nil, rowCount: ptr int32 = nil @@ -909,10 +909,10 @@ proc sendBufMsg*(conn: PgConnection): Future[void] {.async.} = ## Safe because conn.state == csBusy prevents concurrent access to sendBuf. when hasChronos: if conn.sendBuf.len > 0: - await conn.writer.write(unsafeAddr conn.sendBuf[0], conn.sendBuf.len) + await conn.writer.write(addr conn.sendBuf[0], conn.sendBuf.len) elif hasAsyncDispatch: if conn.sendBuf.len > 0: - await conn.socket.sendRawData(unsafeAddr conn.sendBuf[0], conn.sendBuf.len) + await conn.socket.sendRawData(addr conn.sendBuf[0], conn.sendBuf.len) proc closeTransport(conn: PgConnection) {.async.} = ## Close transport resources without sending Terminate. diff --git a/async_postgres/pg_protocol.nim b/async_postgres/pg_protocol.nim index 9d4ed22..e70c3c9 100644 --- a/async_postgres/pg_protocol.nim +++ b/async_postgres/pg_protocol.nim @@ -373,7 +373,7 @@ proc addCString*(buf: var seq[byte], s: string) = let oldLen = buf.len buf.setLen(oldLen + s.len + 1) if s.len > 0: - copyMem(addr buf[oldLen], unsafeAddr s[0], s.len) + copyMem(addr buf[oldLen], addr s[0], s.len) buf[oldLen + s.len] = 0'u8 proc decodeInt16*(buf: openArray[byte], offset: int): int16 = @@ -406,7 +406,7 @@ proc decodeCString*(buf: openArray[byte], offset: int): (string, int) = let slen = i - offset var s = newString(slen) if slen > 0: - copyMem(addr s[0], unsafeAddr buf[offset], slen) + copyMem(addr s[0], addr buf[offset], slen) inc i # skip null terminator result = (s, i - offset) @@ -477,7 +477,7 @@ proc encodeQuery*(sql: string): seq[byte] = proc addFixedMsg(buf: var seq[byte], msg: array[5, byte]) {.inline.} = let oldLen = buf.len buf.setLen(oldLen + 5) - copyMem(addr buf[oldLen], unsafeAddr msg[0], 5) + copyMem(addr buf[oldLen], addr msg[0], 5) proc addParse*( buf: var seq[byte], @@ -525,7 +525,7 @@ proc addBind*( if data.len > 0: let oldLen = buf.len buf.setLen(oldLen + data.len) - copyMem(addr buf[oldLen], unsafeAddr data[0], data.len) + copyMem(addr buf[oldLen], addr data[0], data.len) # Result format codes buf.addInt16(int16(resultFormats.len)) for f in resultFormats: @@ -578,7 +578,7 @@ proc addBindRaw*( ) let oldLen = buf.len buf.setLen(oldLen + r.len) - copyMem(addr buf[oldLen], unsafeAddr paramData[r.off], r.len) + copyMem(addr buf[oldLen], addr paramData[r.off], r.len) buf.addInt16(int16(resultFormats.len)) for f in resultFormats: buf.addInt16(f) @@ -685,7 +685,7 @@ proc encodeCopyData*(buf: var seq[byte], data: openArray[byte]) = buf[oldLen + 3] = byte((msgLen shr 8) and 0xFF) buf[oldLen + 4] = byte(msgLen and 0xFF) if data.len > 0: - copyMem(addr buf[oldLen + 5], unsafeAddr data[0], data.len) + copyMem(addr buf[oldLen + 5], addr data[0], data.len) proc encodeCopyDone*(): seq[byte] = ## Encode a standalone CopyDone message. @@ -973,7 +973,7 @@ proc clone*(row: Row): Row = rd.cellIndex[i * 2] = 0'i32 rd.cellIndex[i * 2 + 1] = 0'i32 else: - copyMem(addr rd.buf[pos], unsafeAddr src.buf[srcOff], int(clen)) + copyMem(addr rd.buf[pos], addr src.buf[srcOff], int(clen)) rd.cellIndex[i * 2] = int32(pos) rd.cellIndex[i * 2 + 1] = clen pos += int(clen) @@ -1016,7 +1016,7 @@ proc parseDataRowInto*(body: openArray[byte], rd: RowData) = let dataLen = body.len - 2 rd.buf.setLen(bufBase + dataLen) if dataLen > 0: - copyMem(addr rd.buf[bufBase], unsafeAddr body[2], dataLen) + copyMem(addr rd.buf[bufBase], addr body[2], dataLen) # Walk the copied buffer to build cellIndex var pos = bufBase # current position in rd.buf let bufEnd = bufBase + dataLen @@ -1166,7 +1166,7 @@ proc addCopyBinaryHeader*(buf: var seq[byte]) = ## Append the PostgreSQL binary COPY header (signature + flags + extension area). let oldLen = buf.len buf.setLen(oldLen + pgCopyBinaryHeader.len) - copyMem(addr buf[oldLen], unsafeAddr pgCopyBinaryHeader[0], pgCopyBinaryHeader.len) + copyMem(addr buf[oldLen], addr pgCopyBinaryHeader[0], pgCopyBinaryHeader.len) proc addCopyBinaryTrailer*(buf: var seq[byte]) = ## Append the binary COPY trailer (int16 = -1). @@ -1217,7 +1217,7 @@ proc addCopyFieldText*(buf: var seq[byte], val: openArray[byte]) = if val.len > 0: let oldLen = buf.len buf.setLen(oldLen + val.len) - copyMem(addr buf[oldLen], unsafeAddr val[0], val.len) + copyMem(addr buf[oldLen], addr val[0], val.len) proc addCopyFieldString*(buf: var seq[byte], val: string) = ## Append a string field in binary COPY format. @@ -1225,7 +1225,7 @@ proc addCopyFieldString*(buf: var seq[byte], val: string) = if val.len > 0: let oldLen = buf.len buf.setLen(oldLen + val.len) - copyMem(addr buf[oldLen], unsafeAddr val[0], val.len) + copyMem(addr buf[oldLen], addr val[0], val.len) # Replication protocol helpers diff --git a/async_postgres/pg_replication.nim b/async_postgres/pg_replication.nim index d57557e..4a6d749 100644 --- a/async_postgres/pg_replication.nim +++ b/async_postgres/pg_replication.nim @@ -187,7 +187,7 @@ proc toString*(field: TupleField): string = ## Convert a TupleField's data to a string by copying the bytes. result = newString(field.data.len) if field.data.len > 0: - copyMem(addr result[0], unsafeAddr field.data[0], field.data.len) + copyMem(addr result[0], addr field.data[0], field.data.len) template toUInt64*(lsn: Lsn): uint64 = ## Get the raw uint64 value of an LSN. @@ -240,7 +240,7 @@ proc decodeCStringAt(buf: openArray[byte], offset: int): (string, int) = let slen = i - offset var s = newString(slen) if slen > 0: - copyMem(addr s[0], unsafeAddr buf[offset], slen) + copyMem(addr s[0], addr buf[offset], slen) inc i # skip null (s, i) @@ -263,7 +263,7 @@ proc decodeTuple(buf: openArray[byte], offset: int): (seq[TupleField], int) = pos += 4 var data = newSeq[byte](dataLen) if dataLen > 0: - copyMem(addr data[0], unsafeAddr buf[pos], dataLen) + copyMem(addr data[0], addr buf[pos], dataLen) pos += int(dataLen) fields[i] = TupleField(kind: if kind == 't': tdkText else: tdkBinary, data: data) else: @@ -389,7 +389,7 @@ proc parsePgOutputMessage*(data: openArray[byte]): PgOutputMessage = pos += 4 if contentLen > 0: msg.content = newSeq[byte](contentLen) - copyMem(addr msg.content[0], unsafeAddr data[pos], contentLen) + copyMem(addr msg.content[0], addr data[pos], contentLen) PgOutputMessage(kind: pomkMessage, message: msg) else: raise newException(ProtocolError, "Unknown pgoutput message type: " & msgType) diff --git a/async_postgres/pg_types/accessors.nim b/async_postgres/pg_types/accessors.nim index 1d49724..9759af2 100644 --- a/async_postgres/pg_types/accessors.nim +++ b/async_postgres/pg_types/accessors.nim @@ -15,7 +15,7 @@ proc cellInfo*(row: Row, col: int): tuple[off: int, len: int] {.inline.} = template bufView*(row: Row, off, clen: int): openArray[char] = ## Zero-copy char view into row.data.buf for parseutils. - cast[ptr UncheckedArray[char]](unsafeAddr row.data.buf[off]).toOpenArray(0, clen - 1) + cast[ptr UncheckedArray[char]](addr row.data.buf[off]).toOpenArray(0, clen - 1) proc len*(row: Row): int {.inline.} = ## Return the number of columns in this row. @@ -169,7 +169,7 @@ proc getStr*(row: Row, col: int): string = discard # text, varchar, bytea: fall through to raw copy result = newString(clen) if clen > 0: - copyMem(addr result[0], unsafeAddr row.data.buf[off], clen) + copyMem(addr result[0], addr row.data.buf[off], clen) proc getInt*(row: Row, col: int): int32 = ## Get a column value as int32. Handles binary int2/int4 directly. Raises `PgTypeError` on NULL. @@ -365,7 +365,7 @@ proc getBytes*(row: Row, col: int): seq[byte] = # Binary format: raw bytes, no hex encoding result = newSeq[byte](clen) if clen > 0: - copyMem(addr result[0], unsafeAddr row.data.buf[off], clen) + copyMem(addr result[0], addr row.data.buf[off], clen) return # Text format: bytea uses hex encoding \xDEADBEEF if clen >= 2 and row.data.buf[off] == byte('\\') and row.data.buf[off + 1] == byte( @@ -381,7 +381,7 @@ proc getBytes*(row: Row, col: int): seq[byte] = else: result = newSeq[byte](clen) if clen > 0: - copyMem(addr result[0], unsafeAddr row.data.buf[off], clen) + copyMem(addr result[0], addr row.data.buf[off], clen) proc getTimestamp*(row: Row, col: int): DateTime = ## Get a column value as DateTime. Handles binary timestamp format. @@ -959,7 +959,7 @@ proc getStrArray*(row: Row, col: int): seq[string] = raise newException(PgTypeError, "NULL element in string array") result[i] = newString(e.len) if e.len > 0: - copyMem(addr result[i][0], unsafeAddr row.data.buf[off + e.off], e.len) + copyMem(addr result[i][0], addr row.data.buf[off + e.off], e.len) return let s = row.getStr(col) let elems = parseTextArray(s) @@ -1239,7 +1239,7 @@ proc getBytesArray*(row: Row, col: int): seq[seq[byte]] = raise newException(PgTypeError, "NULL element in bytea array") result[i] = newSeq[byte](e.len) if e.len > 0: - copyMem(addr result[i][0], unsafeAddr row.data.buf[off + e.off], e.len) + copyMem(addr result[i][0], addr row.data.buf[off + e.off], e.len) return let s = row.getStr(col) let elems = parseTextArray(s) @@ -1522,7 +1522,7 @@ template genStringArrayDecoder(getProc: untyped, T: typedesc, typeName: static s raise newException(PgTypeError, "NULL element in " & typeName & " array") var s = newString(e.len) if e.len > 0: - copyMem(addr s[0], unsafeAddr row.data.buf[off + e.off], e.len) + copyMem(addr s[0], addr row.data.buf[off + e.off], e.len) result[i] = T(s) return let s = row.getStr(col) @@ -1718,7 +1718,7 @@ proc getStrArrayElemOpt*(row: Row, col: int): seq[Option[string]] = else: var s = newString(e.len) if e.len > 0: - copyMem(addr s[0], unsafeAddr row.data.buf[off + e.off], e.len) + copyMem(addr s[0], addr row.data.buf[off + e.off], e.len) result[i] = some(s) return let s = row.getStr(col) diff --git a/async_postgres/pg_types/core.nim b/async_postgres/pg_types/core.nim index 6f96ce0..60a1964 100644 --- a/async_postgres/pg_types/core.nim +++ b/async_postgres/pg_types/core.nim @@ -924,13 +924,13 @@ proc toBytes*(s: string): seq[byte] = ## Converts a string to a sequence of bytes. result = newSeq[byte](s.len) if s.len > 0: - copyMem(addr result[0], unsafeAddr s[0], s.len) + copyMem(addr result[0], addr s[0], s.len) proc toString*(s: seq[byte]): string = ## Converts a sequence of bytes to a string. result = newString(s.len) if s.len > 0: - copyMem(addr result[0], unsafeAddr s[0], s.len) + copyMem(addr result[0], addr s[0], s.len) proc toBE16*(v: int16): array[2, byte] = [byte((v shr 8) and 0xFF), byte(v and 0xFF)] diff --git a/async_postgres/pg_types/decoding.nim b/async_postgres/pg_types/decoding.nim index 43d5224..9825685 100644 --- a/async_postgres/pg_types/decoding.nim +++ b/async_postgres/pg_types/decoding.nim @@ -18,7 +18,7 @@ proc decodeHstoreBinary*(data: openArray[byte]): PgHstore = raise newException(PgTypeError, "hstore binary: truncated key data") var key = newString(keyLen) if keyLen > 0: - copyMem(addr key[0], unsafeAddr data[pos], keyLen) + copyMem(addr key[0], addr data[pos], keyLen) pos += keyLen if pos + 4 > data.len: raise newException(PgTypeError, "hstore binary: truncated value length") @@ -31,7 +31,7 @@ proc decodeHstoreBinary*(data: openArray[byte]): PgHstore = raise newException(PgTypeError, "hstore binary: truncated value data") var val = newString(valLen) if valLen > 0: - copyMem(addr val[0], unsafeAddr data[pos], valLen) + copyMem(addr val[0], addr data[pos], valLen) pos += valLen result[key] = some(val) diff --git a/async_postgres/pg_types/encoding.nim b/async_postgres/pg_types/encoding.nim index b297c71..ec6d90f 100644 --- a/async_postgres/pg_types/encoding.nim +++ b/async_postgres/pg_types/encoding.nim @@ -63,10 +63,10 @@ proc toPgParamInline*(v: string): PgParamInline = if v.len == 0: discard elif v.len <= PgInlineBufSize: - copyMem(addr result.inlineBuf[0], unsafeAddr v[0], v.len) + copyMem(addr result.inlineBuf[0], addr v[0], v.len) else: result.overflow = newSeq[byte](v.len) - copyMem(addr result.overflow[0], unsafeAddr v[0], v.len) + copyMem(addr result.overflow[0], addr v[0], v.len) proc toPgParamInline*(v: seq[byte]): PgParamInline = result.oid = OidBytea @@ -75,7 +75,7 @@ proc toPgParamInline*(v: seq[byte]): PgParamInline = if v.len == 0: discard elif v.len <= PgInlineBufSize: - copyMem(addr result.inlineBuf[0], unsafeAddr v[0], v.len) + copyMem(addr result.inlineBuf[0], addr v[0], v.len) else: result.overflow = v @@ -89,10 +89,10 @@ proc toPgParamInline*(v: PgUuid): PgParamInline = if s.len == 0: discard elif s.len <= PgInlineBufSize: - copyMem(addr result.inlineBuf[0], unsafeAddr s[0], s.len) + copyMem(addr result.inlineBuf[0], addr s[0], s.len) else: result.overflow = newSeq[byte](s.len) - copyMem(addr result.overflow[0], unsafeAddr s[0], s.len) + copyMem(addr result.overflow[0], addr s[0], s.len) proc toPgParamInline*(v: PgMoney): PgParamInline = result.oid = OidMoney @@ -265,26 +265,26 @@ proc encodeBinaryArray*(elemOid: int32, elements: seq[seq[byte]]): seq[byte] = result = newSeq[byte](headerSize + dataSize) # ndim = 1 let ndim = toBE32(1'i32) - copyMem(addr result[0], unsafeAddr ndim[0], 4) + copyMem(addr result[0], addr ndim[0], 4) # has_null = 0 let hasNull = toBE32(0'i32) - copyMem(addr result[4], unsafeAddr hasNull[0], 4) + copyMem(addr result[4], addr hasNull[0], 4) # elem_oid let oid = toBE32(elemOid) - copyMem(addr result[8], unsafeAddr oid[0], 4) + copyMem(addr result[8], addr oid[0], 4) # dim_len let dimLen = toBE32(int32(elements.len)) - copyMem(addr result[12], unsafeAddr dimLen[0], 4) + copyMem(addr result[12], addr dimLen[0], 4) # lower_bound = 1 let lb = toBE32(1'i32) - copyMem(addr result[16], unsafeAddr lb[0], 4) + copyMem(addr result[16], addr lb[0], 4) var pos = headerSize for e in elements: let eLen = toBE32(int32(e.len)) - copyMem(addr result[pos], unsafeAddr eLen[0], 4) + copyMem(addr result[pos], addr eLen[0], 4) pos += 4 if e.len > 0: - copyMem(addr result[pos], unsafeAddr e[0], e.len) + copyMem(addr result[pos], addr e[0], e.len) pos += e.len proc encodeBinaryArray*(elemOid: int32, elements: seq[Option[seq[byte]]]): seq[byte] = @@ -309,28 +309,28 @@ proc encodeBinaryArray*(elemOid: int32, elements: seq[Option[seq[byte]]]): seq[b dataSize += 4 + ev.len result = newSeq[byte](headerSize + dataSize) let ndim = toBE32(1'i32) - copyMem(addr result[0], unsafeAddr ndim[0], 4) + copyMem(addr result[0], addr ndim[0], 4) let hasNull = toBE32(if anyNull: 1'i32 else: 0'i32) - copyMem(addr result[4], unsafeAddr hasNull[0], 4) + copyMem(addr result[4], addr hasNull[0], 4) let oid = toBE32(elemOid) - copyMem(addr result[8], unsafeAddr oid[0], 4) + copyMem(addr result[8], addr oid[0], 4) let dimLen = toBE32(int32(elements.len)) - copyMem(addr result[12], unsafeAddr dimLen[0], 4) + copyMem(addr result[12], addr dimLen[0], 4) let lb = toBE32(1'i32) - copyMem(addr result[16], unsafeAddr lb[0], 4) + copyMem(addr result[16], addr lb[0], 4) var pos = headerSize for e in elements: if e.isNone: let eLen = toBE32(-1'i32) - copyMem(addr result[pos], unsafeAddr eLen[0], 4) + copyMem(addr result[pos], addr eLen[0], 4) pos += 4 else: let ev = e.get let eLen = toBE32(int32(ev.len)) - copyMem(addr result[pos], unsafeAddr eLen[0], 4) + copyMem(addr result[pos], addr eLen[0], 4) pos += 4 if ev.len > 0: - copyMem(addr result[pos], unsafeAddr ev[0], ev.len) + copyMem(addr result[pos], addr ev[0], ev.len) pos += ev.len proc encodeBinaryArrayEmpty*(elemOid: int32): seq[byte] = @@ -339,13 +339,13 @@ proc encodeBinaryArrayEmpty*(elemOid: int32): seq[byte] = result = newSeq[byte](12) # ndim = 0 let ndim = toBE32(0'i32) - copyMem(addr result[0], unsafeAddr ndim[0], 4) + copyMem(addr result[0], addr ndim[0], 4) # has_null = 0 let hasNull = toBE32(0'i32) - copyMem(addr result[4], unsafeAddr hasNull[0], 4) + copyMem(addr result[4], addr hasNull[0], 4) # elem_oid let oid = toBE32(elemOid) - copyMem(addr result[8], unsafeAddr oid[0], 4) + copyMem(addr result[8], addr oid[0], 4) proc toPgParam*(v: seq[int16]): PgParam = if v.len == 0: @@ -683,11 +683,11 @@ proc toPgBinaryParam*(v: PgUuid): PgParam = proc toPgBinaryParam*(v: PgInterval): PgParam = var data = newSeq[byte](16) let usBytes = toBE64(v.microseconds) - copyMem(addr data[0], unsafeAddr usBytes[0], 8) + copyMem(addr data[0], addr usBytes[0], 8) let dayBytes = toBE32(v.days) - copyMem(addr data[8], unsafeAddr dayBytes[0], 4) + copyMem(addr data[8], addr dayBytes[0], 4) let monBytes = toBE32(v.months) - copyMem(addr data[12], unsafeAddr monBytes[0], 4) + copyMem(addr data[12], addr monBytes[0], 4) PgParam(oid: OidInterval, format: 1, value: some(data)) proc toPgBinaryParam*(v: PgInet): PgParam = @@ -888,9 +888,9 @@ proc encodePointBinary*(p: PgPoint): seq[byte] = ## Encode a point as 16 bytes (two float64 big-endian). result = newSeq[byte](16) let xBytes = toBE64(cast[int64](p.x)) - copyMem(addr result[0], unsafeAddr xBytes[0], 8) + copyMem(addr result[0], addr xBytes[0], 8) let yBytes = toBE64(cast[int64](p.y)) - copyMem(addr result[8], unsafeAddr yBytes[0], 8) + copyMem(addr result[8], addr yBytes[0], 8) proc toPgBinaryParam*(v: PgPoint): PgParam = ## Binary format: 16 bytes (two float64 big-endian). @@ -900,29 +900,29 @@ proc toPgBinaryParam*(v: PgLine): PgParam = ## Binary format: 24 bytes (three float64 big-endian: A, B, C). var data = newSeq[byte](24) let aBytes = toBE64(cast[int64](v.a)) - copyMem(addr data[0], unsafeAddr aBytes[0], 8) + copyMem(addr data[0], addr aBytes[0], 8) let bBytes = toBE64(cast[int64](v.b)) - copyMem(addr data[8], unsafeAddr bBytes[0], 8) + copyMem(addr data[8], addr bBytes[0], 8) let cBytes = toBE64(cast[int64](v.c)) - copyMem(addr data[16], unsafeAddr cBytes[0], 8) + copyMem(addr data[16], addr cBytes[0], 8) PgParam(oid: OidLine, format: 1, value: some(data)) proc toPgBinaryParam*(v: PgLseg): PgParam = ## Binary format: 32 bytes (two points). var data = newSeq[byte](32) let p1 = encodePointBinary(v.p1) - copyMem(addr data[0], unsafeAddr p1[0], 16) + copyMem(addr data[0], addr p1[0], 16) let p2 = encodePointBinary(v.p2) - copyMem(addr data[16], unsafeAddr p2[0], 16) + copyMem(addr data[16], addr p2[0], 16) PgParam(oid: OidLseg, format: 1, value: some(data)) proc toPgBinaryParam*(v: PgBox): PgParam = ## Binary format: 32 bytes (high point, low point). var data = newSeq[byte](32) let hi = encodePointBinary(v.high) - copyMem(addr data[0], unsafeAddr hi[0], 16) + copyMem(addr data[0], addr hi[0], 16) let lo = encodePointBinary(v.low) - copyMem(addr data[16], unsafeAddr lo[0], 16) + copyMem(addr data[16], addr lo[0], 16) PgParam(oid: OidBox, format: 1, value: some(data)) proc toPgBinaryParam*(v: PgPath): PgParam = @@ -930,29 +930,29 @@ proc toPgBinaryParam*(v: PgPath): PgParam = var data = newSeq[byte](1 + 4 + v.points.len * 16) data[0] = if v.closed: 1'u8 else: 0'u8 let npts = toBE32(int32(v.points.len)) - copyMem(addr data[1], unsafeAddr npts[0], 4) + copyMem(addr data[1], addr npts[0], 4) for i, p in v.points: let pb = encodePointBinary(p) - copyMem(addr data[5 + i * 16], unsafeAddr pb[0], 16) + copyMem(addr data[5 + i * 16], addr pb[0], 16) PgParam(oid: OidPath, format: 1, value: some(data)) proc toPgBinaryParam*(v: PgPolygon): PgParam = ## Binary format: npts(4) + points(npts \* 16). var data = newSeq[byte](4 + v.points.len * 16) let npts = toBE32(int32(v.points.len)) - copyMem(addr data[0], unsafeAddr npts[0], 4) + copyMem(addr data[0], addr npts[0], 4) for i, p in v.points: let pb = encodePointBinary(p) - copyMem(addr data[4 + i * 16], unsafeAddr pb[0], 16) + copyMem(addr data[4 + i * 16], addr pb[0], 16) PgParam(oid: OidPolygon, format: 1, value: some(data)) proc toPgBinaryParam*(v: PgCircle): PgParam = ## Binary format: 24 bytes (center point + radius float64). var data = newSeq[byte](24) let cp = encodePointBinary(v.center) - copyMem(addr data[0], unsafeAddr cp[0], 16) + copyMem(addr data[0], addr cp[0], 16) let rBytes = toBE64(cast[int64](v.radius)) - copyMem(addr data[16], unsafeAddr rBytes[0], 8) + copyMem(addr data[16], addr rBytes[0], 8) PgParam(oid: OidCircle, format: 1, value: some(data)) proc toPgBinaryParam*(v: JsonNode): PgParam = @@ -1008,25 +1008,25 @@ proc encodeHstoreBinary*(v: PgHstore): seq[byte] = size += val.get.len result = newSeq[byte](size) let np = toBE32(int32(v.len)) - copyMem(addr result[0], unsafeAddr np[0], 4) + copyMem(addr result[0], addr np[0], 4) var pos = 4 for k, val in v.pairs: let kLen = toBE32(int32(k.len)) - copyMem(addr result[pos], unsafeAddr kLen[0], 4) + copyMem(addr result[pos], addr kLen[0], 4) pos += 4 if k.len > 0: - copyMem(addr result[pos], unsafeAddr k[0], k.len) + copyMem(addr result[pos], addr k[0], k.len) pos += k.len if val.isSome: let vLen = toBE32(int32(val.get.len)) - copyMem(addr result[pos], unsafeAddr vLen[0], 4) + copyMem(addr result[pos], addr vLen[0], 4) pos += 4 if val.get.len > 0: - copyMem(addr result[pos], unsafeAddr val.get[0], val.get.len) + copyMem(addr result[pos], addr val.get[0], val.get.len) pos += val.get.len else: let nullLen = toBE32(-1'i32) - copyMem(addr result[pos], unsafeAddr nullLen[0], 4) + copyMem(addr result[pos], addr nullLen[0], 4) pos += 4 proc toPgBinaryParam*(v: PgHstore, oid: int32): PgParam = @@ -1158,7 +1158,7 @@ proc addBind*( if data.len > 0: let oldLen = buf.len buf.setLen(oldLen + data.len) - copyMem(addr buf[oldLen], unsafeAddr data[0], data.len) + copyMem(addr buf[oldLen], addr data[0], data.len) # Result format codes buf.addInt16(int16(resultFormats.len)) for f in resultFormats: @@ -1249,14 +1249,14 @@ proc writeParamValue*(buf: var seq[byte], v: string) = if v.len > 0: let o = buf.len buf.setLen(o + v.len) - copyMem(addr buf[o], unsafeAddr v[0], v.len) + copyMem(addr buf[o], addr v[0], v.len) proc writeParamValue*(buf: var seq[byte], v: seq[byte]) = buf.addInt32(int32(v.len)) if v.len > 0: let o = buf.len buf.setLen(o + v.len) - copyMem(addr buf[o], unsafeAddr v[0], v.len) + copyMem(addr buf[o], addr v[0], v.len) proc writeParamValue*(buf: var seq[byte], v: PgNumeric) = writeParamValue(buf, $v) diff --git a/async_postgres/pg_types/ranges.nim b/async_postgres/pg_types/ranges.nim index 4b99b4b..2bf0b1f 100644 --- a/async_postgres/pg_types/ranges.nim +++ b/async_postgres/pg_types/ranges.nim @@ -339,17 +339,17 @@ proc encodeRangeBinaryImpl(r: RangeBinaryInput): seq[byte] = var pos = 1 if r.hasLower: let lb = toBE32(int32(r.lowerData.len)) - copyMem(addr result[pos], unsafeAddr lb[0], 4) + copyMem(addr result[pos], addr lb[0], 4) pos += 4 if r.lowerData.len > 0: - copyMem(addr result[pos], unsafeAddr r.lowerData[0], r.lowerData.len) + copyMem(addr result[pos], addr r.lowerData[0], r.lowerData.len) pos += r.lowerData.len if r.hasUpper: let ub = toBE32(int32(r.upperData.len)) - copyMem(addr result[pos], unsafeAddr ub[0], 4) + copyMem(addr result[pos], addr ub[0], 4) pos += 4 if r.upperData.len > 0: - copyMem(addr result[pos], unsafeAddr r.upperData[0], r.upperData.len) + copyMem(addr result[pos], addr r.upperData[0], r.upperData.len) # toPgParam for range types (text format) @@ -735,14 +735,14 @@ proc encodeMultirangeBinaryImpl(rangeData: seq[seq[byte]]): seq[byte] = size += 4 + rd.len result = newSeq[byte](size) let cnt = toBE32(int32(rangeData.len)) - copyMem(addr result[0], unsafeAddr cnt[0], 4) + copyMem(addr result[0], addr cnt[0], 4) var pos = 4 for rd in rangeData: let rl = toBE32(int32(rd.len)) - copyMem(addr result[pos], unsafeAddr rl[0], 4) + copyMem(addr result[pos], addr rl[0], 4) pos += 4 if rd.len > 0: - copyMem(addr result[pos], unsafeAddr rd[0], rd.len) + copyMem(addr result[pos], addr rd[0], rd.len) pos += rd.len # Multirange toPgParam (text format) diff --git a/async_postgres/pg_types/user_types.nim b/async_postgres/pg_types/user_types.nim index f4881b5..e7c8cf4 100644 --- a/async_postgres/pg_types/user_types.nim +++ b/async_postgres/pg_types/user_types.nim @@ -157,7 +157,7 @@ proc getEnumArray*[T: enum](row: Row, col: int): seq[T] = raise newException(PgTypeError, "NULL element in enum array") var s = newString(e.len) if e.len > 0: - copyMem(addr s[0], unsafeAddr row.data.buf[off + e.off], e.len) + copyMem(addr s[0], addr row.data.buf[off + e.off], e.len) result[i] = parseEnum[T](s) return let s = row.getStr(col) @@ -187,7 +187,7 @@ proc getEnumArrayElemOpt*[T: enum](row: Row, col: int): seq[Option[T]] = else: var s = newString(e.len) if e.len > 0: - copyMem(addr s[0], unsafeAddr row.data.buf[off + e.off], e.len) + copyMem(addr s[0], addr row.data.buf[off + e.off], e.len) result[i] = some(parseEnum[T](s)) return let s = row.getStr(col) @@ -263,23 +263,23 @@ proc encodeBinaryComposite*( size += f.data.get.len result = newSeq[byte](size) let nf = toBE32(int32(fields.len)) - copyMem(addr result[0], unsafeAddr nf[0], 4) + copyMem(addr result[0], addr nf[0], 4) var pos = 4 for f in fields: let oid = toBE32(f.oid) - copyMem(addr result[pos], unsafeAddr oid[0], 4) + copyMem(addr result[pos], addr oid[0], 4) pos += 4 if f.data.isNone: let nl = toBE32(-1'i32) - copyMem(addr result[pos], unsafeAddr nl[0], 4) + copyMem(addr result[pos], addr nl[0], 4) pos += 4 else: let data = f.data.get let dl = toBE32(int32(data.len)) - copyMem(addr result[pos], unsafeAddr dl[0], 4) + copyMem(addr result[pos], addr dl[0], 4) pos += 4 if data.len > 0: - copyMem(addr result[pos], unsafeAddr data[0], data.len) + copyMem(addr result[pos], addr data[0], data.len) pos += data.len proc compositeFieldToText(val: string): string = @@ -366,7 +366,7 @@ template decodeBinaryField(val, buf: untyped, fOff, fEnd, fLen: int) = when typeof(val) is string: val = newString(fLen) if fLen > 0: - copyMem(addr val[0], unsafeAddr buf[fOff], fLen) + copyMem(addr val[0], addr buf[fOff], fLen) elif typeof(val) is int16: val = fromBE16(buf.toOpenArray(fOff, fEnd)) elif typeof(val) is int32: @@ -382,7 +382,7 @@ template decodeBinaryField(val, buf: untyped, fOff, fEnd, fLen: int) = else: var s = newString(fLen) if fLen > 0: - copyMem(addr s[0], unsafeAddr buf[fOff], fLen) + copyMem(addr s[0], addr buf[fOff], fLen) val = compositeFieldFromText[typeof(val)](s) proc getComposite*[T: object](row: Row, col: int): T = diff --git a/tests/test_e2e.nim b/tests/test_e2e.nim index 7b534bf..e1a04bb 100644 --- a/tests/test_e2e.nim +++ b/tests/test_e2e.nim @@ -55,7 +55,7 @@ proc toBytes(s: string): seq[byte] = proc toString(b: seq[byte]): string = result = newString(b.len) if b.len > 0: - copyMem(addr result[0], unsafeAddr b[0], b.len) + copyMem(addr result[0], addr b[0], b.len) suite "E2E: Basic Connection": test "plain connection and close": diff --git a/tests/test_largeobject.nim b/tests/test_largeobject.nim index 9f18a6f..09c0084 100644 --- a/tests/test_largeobject.nim +++ b/tests/test_largeobject.nim @@ -28,7 +28,7 @@ proc toBytes(s: string): seq[byte] = proc toString(b: seq[byte]): string = result = newString(b.len) if b.len > 0: - copyMem(addr result[0], unsafeAddr b[0], b.len) + copyMem(addr result[0], addr b[0], b.len) suite "Large Object: create and unlink": test "loCreate and loUnlink": diff --git a/tests/test_rowdata.nim b/tests/test_rowdata.nim index 78b5af3..28c3b4c 100644 --- a/tests/test_rowdata.nim +++ b/tests/test_rowdata.nim @@ -22,7 +22,7 @@ proc getCell(rd: RowData, rowIdx, col: int): string = if clen <= 0: return "" result = newString(clen) - copyMem(addr result[0], unsafeAddr rd.buf[off], clen) + copyMem(addr result[0], addr rd.buf[off], clen) proc isCellNull(rd: RowData, rowIdx, col: int): bool = let idx = (rowIdx * int(rd.numCols) + col) * 2 diff --git a/tests/test_ssl.nim b/tests/test_ssl.nim index 59cabd4..13fda91 100644 --- a/tests/test_ssl.nim +++ b/tests/test_ssl.nim @@ -77,13 +77,13 @@ elif hasAsyncDispatch: let data = await client.recv(n - offset) if data.len == 0: raise newException(CatchableError, "Connection closed prematurely") - copyMem(addr result[offset], unsafeAddr data[0], data.len) + copyMem(addr result[offset], addr data[0], data.len) offset += data.len proc sendBytes(client: MockClient, data: seq[byte]) {.async.} = if data.len > 0: var str = newString(data.len) - copyMem(addr str[0], unsafeAddr data[0], data.len) + copyMem(addr str[0], addr data[0], data.len) await client.send(str) proc drainStartupMessage(client: MockClient): Future[void] {.async.} = diff --git a/tests/test_types.nim b/tests/test_types.nim index 233bbbe..d27054f 100644 --- a/tests/test_types.nim +++ b/tests/test_types.nim @@ -2463,11 +2463,11 @@ suite "PgInterval": test "getInterval binary format": var data = newSeq[byte](16) let usBytes = toBE64(14706123456'i64) - copyMem(addr data[0], unsafeAddr usBytes[0], 8) + copyMem(addr data[0], addr usBytes[0], 8) let dayBytes = toBE32(3'i32) - copyMem(addr data[8], unsafeAddr dayBytes[0], 4) + copyMem(addr data[8], addr dayBytes[0], 4) let monBytes = toBE32(14'i32) - copyMem(addr data[12], unsafeAddr monBytes[0], 4) + copyMem(addr data[12], addr monBytes[0], 4) let fields = @[mkField(OidInterval, 1)] let row = mkRow(@[some(data)], fields) let v = row.getInterval(0) @@ -2501,11 +2501,11 @@ suite "PgInterval": test "getIntervalOpt binary some": var data = newSeq[byte](16) let usBytes = toBE64(1_000_000'i64) - copyMem(addr data[0], unsafeAddr usBytes[0], 8) + copyMem(addr data[0], addr usBytes[0], 8) let dayBytes = toBE32(0'i32) - copyMem(addr data[8], unsafeAddr dayBytes[0], 4) + copyMem(addr data[8], addr dayBytes[0], 4) let monBytes = toBE32(0'i32) - copyMem(addr data[12], unsafeAddr monBytes[0], 4) + copyMem(addr data[12], addr monBytes[0], 4) let fields = @[mkField(OidInterval, 1)] let row = mkRow(@[some(data)], fields) let v = row.getIntervalOpt(0) @@ -5864,7 +5864,7 @@ proc inlinePayload(p: PgParamInline): seq[byte] = return @[] if p.len <= PgInlineBufSize: result = newSeq[byte](p.len) - copyMem(addr result[0], unsafeAddr p.inlineBuf[0], p.len) + copyMem(addr result[0], addr p.inlineBuf[0], p.len) else: result = p.overflow