From 45b0e9d1579b06aedfe4ffe39e832ec5e88f9377 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Tue, 8 Oct 2024 11:20:07 +0200 Subject: [PATCH] arraybuf: fix dangling pointer and name workaround (#237) https://github.com/nim-lang/Nim/issues/24260 https://github.com/nim-lang/Nim/issues/24261 --- stew/arraybuf.nim | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/stew/arraybuf.nim b/stew/arraybuf.nim index 63d1f2f..c0f1b93 100644 --- a/stew/arraybuf.nim +++ b/stew/arraybuf.nim @@ -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: