osproc improvement: check API consistency in order to prevent bug #6820
This commit is contained in:
parent
8aebd38514
commit
439b72b402
1 changed files with 8 additions and 0 deletions
|
|
@ -321,6 +321,8 @@ when not defined(useNimRtl):
|
||||||
elif not running(p): break
|
elif not running(p): break
|
||||||
close(p)
|
close(p)
|
||||||
|
|
||||||
|
template streamAccess(p) =
|
||||||
|
assert poParentStreams notin p.options, "API usage error: stream access not allowed when you use poParentStreams"
|
||||||
|
|
||||||
when defined(Windows) and not defined(useNimRtl):
|
when defined(Windows) and not defined(useNimRtl):
|
||||||
# We need to implement a handle stream for Windows:
|
# We need to implement a handle stream for Windows:
|
||||||
|
|
@ -581,12 +583,15 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
proc inputStream(p: Process): Stream =
|
proc inputStream(p: Process): Stream =
|
||||||
|
streamAccess(p)
|
||||||
result = newFileHandleStream(p.inHandle)
|
result = newFileHandleStream(p.inHandle)
|
||||||
|
|
||||||
proc outputStream(p: Process): Stream =
|
proc outputStream(p: Process): Stream =
|
||||||
|
streamAccess(p)
|
||||||
result = newFileHandleStream(p.outHandle)
|
result = newFileHandleStream(p.outHandle)
|
||||||
|
|
||||||
proc errorStream(p: Process): Stream =
|
proc errorStream(p: Process): Stream =
|
||||||
|
streamAccess(p)
|
||||||
result = newFileHandleStream(p.errHandle)
|
result = newFileHandleStream(p.errHandle)
|
||||||
|
|
||||||
proc execCmd(command: string): int =
|
proc execCmd(command: string): int =
|
||||||
|
|
@ -1152,16 +1157,19 @@ elif not defined(useNimRtl):
|
||||||
stream = newFileStream(f)
|
stream = newFileStream(f)
|
||||||
|
|
||||||
proc inputStream(p: Process): Stream =
|
proc inputStream(p: Process): Stream =
|
||||||
|
streamAccess(p)
|
||||||
if p.inStream == nil:
|
if p.inStream == nil:
|
||||||
createStream(p.inStream, p.inHandle, fmWrite)
|
createStream(p.inStream, p.inHandle, fmWrite)
|
||||||
return p.inStream
|
return p.inStream
|
||||||
|
|
||||||
proc outputStream(p: Process): Stream =
|
proc outputStream(p: Process): Stream =
|
||||||
|
streamAccess(p)
|
||||||
if p.outStream == nil:
|
if p.outStream == nil:
|
||||||
createStream(p.outStream, p.outHandle, fmRead)
|
createStream(p.outStream, p.outHandle, fmRead)
|
||||||
return p.outStream
|
return p.outStream
|
||||||
|
|
||||||
proc errorStream(p: Process): Stream =
|
proc errorStream(p: Process): Stream =
|
||||||
|
streamAccess(p)
|
||||||
if p.errStream == nil:
|
if p.errStream == nil:
|
||||||
createStream(p.errStream, p.errHandle, fmRead)
|
createStream(p.errStream, p.errHandle, fmRead)
|
||||||
return p.errStream
|
return p.errStream
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue