diff options
author | Araq <rumpf_a@web.de> | 2017-11-28 02:19:39 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2017-11-28 02:19:39 +0100 |
commit | 439b72b40248e35628d19a66cc658718bb94424e (patch) | |
tree | e023928fc0e2e6570046b255aefab902da87fa48 | |
parent | 8aebd3851467dbef43c151600f787a8f6b35c71a (diff) | |
download | Nim-439b72b40248e35628d19a66cc658718bb94424e.tar.gz |
osproc improvement: check API consistency in order to prevent bug #6820
-rw-r--r-- | lib/pure/osproc.nim | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index cc4c26161..9865f114f 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -321,6 +321,8 @@ when not defined(useNimRtl): elif not running(p): break 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): # We need to implement a handle stream for Windows: @@ -581,12 +583,15 @@ when defined(Windows) and not defined(useNimRtl): return res proc inputStream(p: Process): Stream = + streamAccess(p) result = newFileHandleStream(p.inHandle) proc outputStream(p: Process): Stream = + streamAccess(p) result = newFileHandleStream(p.outHandle) proc errorStream(p: Process): Stream = + streamAccess(p) result = newFileHandleStream(p.errHandle) proc execCmd(command: string): int = @@ -1152,16 +1157,19 @@ elif not defined(useNimRtl): stream = newFileStream(f) proc inputStream(p: Process): Stream = + streamAccess(p) if p.inStream == nil: createStream(p.inStream, p.inHandle, fmWrite) return p.inStream proc outputStream(p: Process): Stream = + streamAccess(p) if p.outStream == nil: createStream(p.outStream, p.outHandle, fmRead) return p.outStream proc errorStream(p: Process): Stream = + streamAccess(p) if p.errStream == nil: createStream(p.errStream, p.errHandle, fmRead) return p.errStream |