Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion async_postgres/async_backend.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion async_postgres/pg_bearssl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions async_postgres/pg_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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*(
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions async_postgres/pg_connection.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
22 changes: 11 additions & 11 deletions async_postgres/pg_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -1217,15 +1217,15 @@ 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.
buf.addInt32(int32(val.len))
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

Expand Down
8 changes: 4 additions & 4 deletions async_postgres/pg_replication.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions async_postgres/pg_types/accessors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions async_postgres/pg_types/core.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions async_postgres/pg_types/decoding.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)

Expand Down
Loading
Loading