status-im / nim-faststreams

Nearly zero-overhead input/output streams for Nim
Apache License 2.0
125 stars 11 forks source link

Index error on simple example #56

Open Graveflo opened 4 months ago

Graveflo commented 4 months ago
import faststreams/[inputs, outputs]

let outp = memoryOutput(pageSize = 256)

proc fillBytes(x: var openArray[byte], os: OutputStream) =
  for i in 0 ..< 128:
    x[i] = 'A'.byte
  os.advance(128)

fillBytes(outp.getWritableBytes(256), outp)
outp.flush()
echo outp.getOutput(string)

the above gives this error:

nim-faststreams/faststreams/outputs.nim(917) getOutput
/usr/lib/nim/lib/system/fatal.nim(53) sysFatal
Error: unhandled exception: value out of range: -128 notin 0 .. 9223372036854775807 [RangeDefect]

seems to be caused by 426c88010e4d95bda23197414b7cca8c23017e7f

also, using devel nim:

Nim Compiler Version 2.1.9 [Linux: amd64]
Compiled at 2024-07-28
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 39629a1adcbcc822508acc3983f444328f90dd85
active boot switches: -d:release

also, preluding with ensureRunway seems to work around the issue