[commit: ghc] master: IO Handles: update comments [skip ci] (1b6323b)
git at git.haskell.org
git at git.haskell.org
Thu Dec 17 17:42:40 UTC 2015
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/1b6323b3ad576ef1806170d8cea871038b51de5e/ghc
>---------------------------------------------------------------
commit 1b6323b3ad576ef1806170d8cea871038b51de5e
Author: Thomas Miedema <thomasmiedema at gmail.com>
Date: Mon Dec 14 17:00:27 2015 +0100
IO Handles: update comments [skip ci]
* hSetEcho, hGetEcho and hIsTerminalDevice are part of the Haskell2010
report (but not Haskell98)
* there are great `Note`s in GHC.IO.Handle.Types. Link to them.
>---------------------------------------------------------------
1b6323b3ad576ef1806170d8cea871038b51de5e
libraries/base/GHC/IO/Handle.hs | 2 +-
libraries/base/GHC/IO/Handle/Internals.hs | 12 ++++++++----
libraries/base/GHC/IO/Handle/Types.hs | 4 ++--
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/libraries/base/GHC/IO/Handle.hs b/libraries/base/GHC/IO/Handle.hs
index 750dbf7..c1d15a9 100644
--- a/libraries/base/GHC/IO/Handle.hs
+++ b/libraries/base/GHC/IO/Handle.hs
@@ -508,7 +508,7 @@ hIsSeekable handle =
_ -> IODevice.isSeekable haDevice
-- -----------------------------------------------------------------------------
--- Changing echo status (Non-standard GHC extensions)
+-- Changing echo status
-- | Set the echoing status of a handle connected to a terminal.
diff --git a/libraries/base/GHC/IO/Handle/Internals.hs b/libraries/base/GHC/IO/Handle/Internals.hs
index 581eb9b..5d8ddfd 100644
--- a/libraries/base/GHC/IO/Handle/Internals.hs
+++ b/libraries/base/GHC/IO/Handle/Internals.hs
@@ -480,15 +480,19 @@ flushCharBuffer h_ at Handle__{..} = do
ReadBuffer -> do
flushCharReadBuffer h_
WriteBuffer ->
+ -- Nothing to do here. Char buffer on a write Handle is always empty
+ -- between Handle operations.
+ -- See [note Buffer Flushing], GHC.IO.Handle.Types.
when (not (isEmptyBuffer cbuf)) $
error "internal IO library error: Char buffer non-empty"
-- -----------------------------------------------------------------------------
-- Writing data (flushing write buffers)
--- flushWriteBuffer flushes the buffer iff it contains pending write
--- data. Flushes both the Char and the byte buffer, leaving both
--- empty.
+-- flushWriteBuffer flushes the byte buffer iff it contains pending write
+-- data. Because the Char buffer on a write Handle is always empty between
+-- Handle operations (see [note Buffer Flushing], GHC.IO.Handle.Types),
+-- both buffers are empty after this.
flushWriteBuffer :: Handle__ -> IO ()
flushWriteBuffer h_ at Handle__{..} = do
buf <- readIORef haByteBuffer
@@ -519,7 +523,7 @@ writeCharBuffer h_ at Handle__{..} !cbuf = do
debugIO ("writeCharBuffer after encoding: cbuf=" ++ summaryBuffer cbuf' ++
" bbuf=" ++ summaryBuffer bbuf')
- -- flush if the write buffer is full
+ -- flush the byte buffer if it is full
if isFullBuffer bbuf'
-- or we made no progress
|| not (isEmptyBuffer cbuf') && bufL cbuf' == bufL cbuf
diff --git a/libraries/base/GHC/IO/Handle/Types.hs b/libraries/base/GHC/IO/Handle/Types.hs
index c784c5c..195054a 100644
--- a/libraries/base/GHC/IO/Handle/Types.hs
+++ b/libraries/base/GHC/IO/Handle/Types.hs
@@ -122,10 +122,10 @@ data Handle__
Handle__ {
haDevice :: !dev,
haType :: HandleType, -- type (read/write/append etc.)
- haByteBuffer :: !(IORef (Buffer Word8)),
+ haByteBuffer :: !(IORef (Buffer Word8)), -- See [note Buffering Implementation]
haBufferMode :: BufferMode,
haLastDecode :: !(IORef (dec_state, Buffer Word8)),
- haCharBuffer :: !(IORef (Buffer CharBufElem)), -- the current buffer
+ haCharBuffer :: !(IORef (Buffer CharBufElem)), -- See [note Buffering Implementation]
haBuffers :: !(IORef (BufferList CharBufElem)), -- spare buffers
haEncoder :: Maybe (TextEncoder enc_state),
haDecoder :: Maybe (TextDecoder dec_state),
More information about the ghc-commits
mailing list