From f3d1c8883f3e449134529f262b252e6b173b8e0f Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Fri, 17 Apr 2020 00:22:35 +0300 Subject: [PATCH] Address some review comments; Apply the same destructor fix to the output stream --- faststreams.nimble | 2 +- faststreams/input_stream.nim | 13 +++++++------ faststreams/output_stream.nim | 5 ++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/faststreams.nimble b/faststreams.nimble index 5f3a5b0..7fa698d 100644 --- a/faststreams.nimble +++ b/faststreams.nimble @@ -7,7 +7,7 @@ description = "Nearly zero-overhead input/output streams for Nim" license = "Apache License 2.0" skipDirs = @["tests"] -requires "nim >= 0.17.0", +requires "nim >= 1.2.0", "stew", "chronos" diff --git a/faststreams/input_stream.nim b/faststreams/input_stream.nim index 1278c65..d2aa8ce 100644 --- a/faststreams/input_stream.nim +++ b/faststreams/input_stream.nim @@ -53,17 +53,18 @@ const # The goal is to make perfect page-aligned allocations # defaultPageSize = 4096 - nimAllocatorMetadataSize -proc close*(s: var InputStream) {.raises: [IOError, Defect].} = - if s != nil: - if s.vtable != nil and s.vtable.closeSync != nil: - s.vtable.closeSync(s) - s = nil - proc preventFurtherReading(s: InputStream) = s.vtable = nil s.head = nil s.bufferEnd = nil +proc close*(s: InputStream) {.raises: [IOError, Defect].} = + if s != nil: + if s.vtable != nil and s.vtable.closeSync != nil: + s.vtable.closeSync(s) + + s.preventFurtherReading() + proc `=destroy`*(h: var InputStreamHandle) {.raises: [Defect].} = if h.s != nil: if h.s.vtable != nil and h.s.vtable.closeSync != nil: diff --git a/faststreams/output_stream.nim b/faststreams/output_stream.nim index 4b30438..8b33962 100644 --- a/faststreams/output_stream.nim +++ b/faststreams/output_stream.nim @@ -67,11 +67,10 @@ const # The goal is to make perfect page-aligned allocations defaultPageSize = 4096 - nimAllocatorMetadataSize - 1 # 1 byte for the null terminator -proc close*(s: var OutputStream) {.raises: [IOError, Defect].} = +proc close*(s: OutputStream) {.raises: [IOError, Defect].} = if s != nil: if s.vtable != nil and s.vtable.closeSync != nil: s.vtable.closeSync(s) - s = nil proc `=destroy`*(h: var OutputStreamHandle) {.raises: [Defect].} = if h.s != nil: @@ -83,7 +82,7 @@ proc `=destroy`*(h: var OutputStreamHandle) {.raises: [Defect].} = # If the user wanted to handle the error, they would have called # `close` manually. discard # TODO - h.s = nil + # h.s = nil converter implicitDeref*(h: OutputStreamHandle): OutputStream = h.s