arraybuf: fix dangling pointer and name workaround (#237)

https://github.com/nim-lang/Nim/issues/24260
https://github.com/nim-lang/Nim/issues/24261
This commit is contained in:
Jacek Sieka 2024-10-08 11:20:07 +02:00 committed by GitHub
parent 763147cf82
commit 45b0e9d157
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 6 deletions

View File

@ -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: