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 b.n = nl
template data*(bParam: ArrayBuf): openArray = template data*(bParam: ArrayBuf): openArray =
block: # TODO https://github.com/nim-lang/Nim/issues/24260
bParam.evalOnceAs(b) # TODO https://github.com/nim-lang/Nim/issues/24261
b.buf.toOpenArray(0, b.len() - 1) bParam.evalOnceAs(bArrayBufPrivate)
bArrayBufPrivate.buf.toOpenArray(0, bArrayBufPrivate.len() - 1)
template data*(bParam: var ArrayBuf): var openArray = template data*(bParam: var ArrayBuf): var openArray =
block: # TODO https://github.com/nim-lang/Nim/issues/24260
bParam.evalOnceAs(b) # TODO https://github.com/nim-lang/Nim/issues/24261
b.buf.toOpenArray(0, b.len() - 1) bParam.evalOnceAs(bArrayBufPrivate)
bArrayBufPrivate.buf.toOpenArray(0, bArrayBufPrivate.len() - 1)
iterator items*[N, T](b: ArrayBuf[N, T]): lent T = iterator items*[N, T](b: ArrayBuf[N, T]): lent T =
for i in 0 ..< b.len: for i in 0 ..< b.len: