summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/IO/Handle/Internals.hs
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2009-08-05 13:40:36 +0000
committerSimon Marlow <marlowsd@gmail.com>2009-08-05 13:40:36 +0000
commited6de50646d1967e269b5a4f10835c76fdd714e2 (patch)
tree2badf76997791a9270d485b8efc49bbcca7e6a15 /libraries/base/GHC/IO/Handle/Internals.hs
parentbcbe9e78dc8093aebf6dd8415a7245d27b5ca9d3 (diff)
downloadhaskell-ed6de50646d1967e269b5a4f10835c76fdd714e2.tar.gz
Tweak the BufferedIO class to enable a memory-mapped file implementation
We have to eliminate the assumption that an empty write buffer can be constructed by setting the buffer pointers to zero: this isn't necessarily the case when the buffer corresponds to a memory-mapped file, or other in-memory device implementation.
Diffstat (limited to 'libraries/base/GHC/IO/Handle/Internals.hs')
-rw-r--r--libraries/base/GHC/IO/Handle/Internals.hs7
1 files changed, 4 insertions, 3 deletions
diff --git a/libraries/base/GHC/IO/Handle/Internals.hs b/libraries/base/GHC/IO/Handle/Internals.hs
index 0de07f437f..403407f0d9 100644
--- a/libraries/base/GHC/IO/Handle/Internals.hs
+++ b/libraries/base/GHC/IO/Handle/Internals.hs
@@ -205,7 +205,8 @@ checkWritableHandle act h_@Handle__{..}
buf <- readIORef haCharBuffer
writeIORef haCharBuffer buf{ bufState = WriteBuffer }
buf <- readIORef haByteBuffer
- writeIORef haByteBuffer buf{ bufState = WriteBuffer }
+ buf' <- Buffered.emptyWriteBuffer haDevice buf
+ writeIORef haByteBuffer buf'
act h_
_other -> act h_
@@ -705,8 +706,8 @@ writeTextDevice h_@Handle__{..} cbuf = do
debugIO ("writeTextDevice after encoding: cbuf=" ++ summaryBuffer cbuf' ++
" bbuf=" ++ summaryBuffer bbuf')
- Buffered.flushWriteBuffer haDevice bbuf'
- writeIORef haByteBuffer bbuf{bufL=0,bufR=0}
+ bbuf' <- Buffered.flushWriteBuffer haDevice bbuf'
+ writeIORef haByteBuffer bbuf'
if not (isEmptyBuffer cbuf')
then writeTextDevice h_ cbuf'
else return ()