Address some review comments; Apply the same destructor fix to the output stream

This commit is contained in:
Zahary Karadjov 2020-04-17 00:22:35 +03:00
commit f3d1c8883f
No known key found for this signature in database
GPG key ID: C8936F8A3073D609
3 changed files with 10 additions and 10 deletions

View file

@ -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:

View file

@ -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