Skip to content

Commit

Permalink
arraybuf: fix dangling pointer and name workaround (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck authored Oct 8, 2024
1 parent 763147c commit 45b0e9d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions stew/arraybuf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ template setLen*(b: var ArrayBuf, newLenParam: int) =
b.n = nl

template data*(bParam: ArrayBuf): openArray =
block:
bParam.evalOnceAs(b)
b.buf.toOpenArray(0, b.len() - 1)
# TODO https://github.com/nim-lang/Nim/issues/24260
# TODO https://github.com/nim-lang/Nim/issues/24261
bParam.evalOnceAs(bArrayBufPrivate)
bArrayBufPrivate.buf.toOpenArray(0, bArrayBufPrivate.len() - 1)

template data*(bParam: var ArrayBuf): var openArray =
block:
bParam.evalOnceAs(b)
b.buf.toOpenArray(0, b.len() - 1)
# TODO https://github.com/nim-lang/Nim/issues/24260
# TODO https://github.com/nim-lang/Nim/issues/24261
bParam.evalOnceAs(bArrayBufPrivate)
bArrayBufPrivate.buf.toOpenArray(0, bArrayBufPrivate.len() - 1)

iterator items*[N, T](b: ArrayBuf[N, T]): lent T =
for i in 0 ..< b.len:
Expand Down

0 comments on commit 45b0e9d

Please sign in to comment.