Address some review comments; Apply the same destructor fix to the output stream
This commit is contained in:
parent
6ce0472ec0
commit
f3d1c8883f
3 changed files with 10 additions and 10 deletions
|
|
@ -7,7 +7,7 @@ description = "Nearly zero-overhead input/output streams for Nim"
|
||||||
license = "Apache License 2.0"
|
license = "Apache License 2.0"
|
||||||
skipDirs = @["tests"]
|
skipDirs = @["tests"]
|
||||||
|
|
||||||
requires "nim >= 0.17.0",
|
requires "nim >= 1.2.0",
|
||||||
"stew",
|
"stew",
|
||||||
"chronos"
|
"chronos"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,17 +53,18 @@ const
|
||||||
# The goal is to make perfect page-aligned allocations
|
# The goal is to make perfect page-aligned allocations
|
||||||
# defaultPageSize = 4096 - nimAllocatorMetadataSize
|
# 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) =
|
proc preventFurtherReading(s: InputStream) =
|
||||||
s.vtable = nil
|
s.vtable = nil
|
||||||
s.head = nil
|
s.head = nil
|
||||||
s.bufferEnd = 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].} =
|
proc `=destroy`*(h: var InputStreamHandle) {.raises: [Defect].} =
|
||||||
if h.s != nil:
|
if h.s != nil:
|
||||||
if h.s.vtable != nil and h.s.vtable.closeSync != nil:
|
if h.s.vtable != nil and h.s.vtable.closeSync != nil:
|
||||||
|
|
|
||||||
|
|
@ -67,11 +67,10 @@ const
|
||||||
# The goal is to make perfect page-aligned allocations
|
# The goal is to make perfect page-aligned allocations
|
||||||
defaultPageSize = 4096 - nimAllocatorMetadataSize - 1 # 1 byte for the null terminator
|
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 != nil:
|
||||||
if s.vtable != nil and s.vtable.closeSync != nil:
|
if s.vtable != nil and s.vtable.closeSync != nil:
|
||||||
s.vtable.closeSync(s)
|
s.vtable.closeSync(s)
|
||||||
s = nil
|
|
||||||
|
|
||||||
proc `=destroy`*(h: var OutputStreamHandle) {.raises: [Defect].} =
|
proc `=destroy`*(h: var OutputStreamHandle) {.raises: [Defect].} =
|
||||||
if h.s != nil:
|
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
|
# If the user wanted to handle the error, they would have called
|
||||||
# `close` manually.
|
# `close` manually.
|
||||||
discard # TODO
|
discard # TODO
|
||||||
h.s = nil
|
# h.s = nil
|
||||||
|
|
||||||
converter implicitDeref*(h: OutputStreamHandle): OutputStream =
|
converter implicitDeref*(h: OutputStreamHandle): OutputStream =
|
||||||
h.s
|
h.s
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue