Skip to content

Commit a9c6b88

Browse files
authored
Document unsafe memory input risk with refc (#80)
nim-lang/Nim#25080
1 parent c3ac3f6 commit a9c6b88

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

faststreams/inputs.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ proc fileInput*(filename: string,
453453
return fileInput(file, offset, pageSize)
454454

455455
func unsafeMemoryInput*(mem: openArray[byte]): InputStreamHandle =
456+
## Unsafe memory input that relies on `mem` to remain available for the
457+
## duration of the usage of the input stream.
458+
##
459+
## One particular high-risk scenario is when using `--mm:refc` - when `mem`
460+
## refers to a local garbage-collected type like `seq`, the GC might claim
461+
## the instance even though scope-wise, it looks like it should stay alive.
462+
##
463+
## See also https://github.com/nim-lang/Nim/issues/25080
456464
let head = cast[ptr byte](mem)
457465

458466
makeHandle InputStream(

0 commit comments

Comments
 (0)