Fix a bug affecting Snappy (crash when using fileInputs)
This commit is contained in:
parent
26a5d82150
commit
b234a99e56
1 changed files with 6 additions and 12 deletions
|
|
@ -106,10 +106,14 @@ proc endPos*(s: InputStream): int =
|
||||||
return s.bufferEndPos
|
return s.bufferEndPos
|
||||||
|
|
||||||
proc syncRead(s: InputStream): bool =
|
proc syncRead(s: InputStream): bool =
|
||||||
|
if s.vtable == nil or s.vtable.readSync == nil:
|
||||||
|
return true
|
||||||
|
|
||||||
let bytesRead = s.vtable.readSync(s, s.bufferStart, s.bufferSize)
|
let bytesRead = s.vtable.readSync(s, s.bufferStart, s.bufferSize)
|
||||||
if bytesRead == 0:
|
if bytesRead == 0:
|
||||||
# TODO close the input device
|
# TODO close the input device
|
||||||
s.inputDevice = nil
|
s.inputDevice = nil
|
||||||
|
s.vtable = nil
|
||||||
return true
|
return true
|
||||||
else:
|
else:
|
||||||
s.bufferEnd = offset(s.bufferStart, bytesRead)
|
s.bufferEnd = offset(s.bufferStart, bytesRead)
|
||||||
|
|
@ -120,7 +124,7 @@ proc ensureBytes*(s: InputStream, n: int): bool =
|
||||||
if distance(s.head, s.bufferEnd) >= n:
|
if distance(s.head, s.bufferEnd) >= n:
|
||||||
return true
|
return true
|
||||||
|
|
||||||
if s.inputDevice == nil:
|
if s.vtable == nil:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|
@ -130,14 +134,8 @@ proc eof*(s: InputStream): bool =
|
||||||
if s.head != s.bufferEnd:
|
if s.head != s.bufferEnd:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if s.inputDevice == nil:
|
|
||||||
return true
|
|
||||||
|
|
||||||
return s.syncRead()
|
return s.syncRead()
|
||||||
|
|
||||||
#proc eob*(s: InputStream): bool {.inline.} =
|
|
||||||
# s.head != s.bufferEnd
|
|
||||||
|
|
||||||
proc peek*(s: InputStream): byte {.inline.} =
|
proc peek*(s: InputStream): byte {.inline.} =
|
||||||
doAssert s.head != s.bufferEnd
|
doAssert s.head != s.bufferEnd
|
||||||
return s.head[]
|
return s.head[]
|
||||||
|
|
@ -150,8 +148,7 @@ when debugHelpers:
|
||||||
proc advance*(s: InputStream) =
|
proc advance*(s: InputStream) =
|
||||||
if s.head != s.bufferEnd:
|
if s.head != s.bufferEnd:
|
||||||
s.head = offset(s.head, 1)
|
s.head = offset(s.head, 1)
|
||||||
elif s.inputDevice != nil:
|
discard s.syncRead()
|
||||||
discard s.syncRead()
|
|
||||||
|
|
||||||
proc read*(s: InputStream): byte =
|
proc read*(s: InputStream): byte =
|
||||||
result = s.peek()
|
result = s.peek()
|
||||||
|
|
@ -203,9 +200,6 @@ template pos*(s: AsciiInputStream|Utf8InputStream): int =
|
||||||
template eof*(s: AsciiInputStream|Utf8InputStream): bool =
|
template eof*(s: AsciiInputStream|Utf8InputStream): bool =
|
||||||
InputStream(s).eof
|
InputStream(s).eof
|
||||||
|
|
||||||
#template eob*(s: AsciiInputStream|Utf8InputStream): bool =
|
|
||||||
# InputStream(s).eob
|
|
||||||
|
|
||||||
template close*(s: AsciiInputStream|Utf8InputStream) =
|
template close*(s: AsciiInputStream|Utf8InputStream) =
|
||||||
close InputStream(s)
|
close InputStream(s)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue