[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 15:02:58 UTC 2010


The following commit has been merged in the master branch:
commit 5ab4fec24d58eb4e85d183cebdfaeee8619c62b9
Author: John Goerzen <jgoerzen at complete.org>
Date:   Mon Oct 10 08:36:34 2005 +0100

    checkpointing

diff --git a/MissingH/IO/Binary.hs b/MissingH/IO/Binary.hs
index 5862422..c9d4fff 100644
--- a/MissingH/IO/Binary.hs
+++ b/MissingH/IO/Binary.hs
@@ -100,14 +100,20 @@ instance BinaryConvertable String where
     toBuf = withCString
     fromBuf len func = 
         do fbuf <- mallocForeignPtrArray (len + 1)
-           withForeignPtr fbuf func
+           withForeignPtr fbuf handler
+        where handler ptr =
+                  do bytesread <- func
+                     peekCStringLen (ptr, bytesread)
     byteSize = length
 
 instance BinaryConvertable [Word8] where
     toBuf hslist func = withArray hslist (\ptr -> func (castPtr ptr))
     fromBuf len func =
         do (fbuf::(ForeignPtr Word8)) <- mallocForeignPtrArray (len + 1)
-           withForeignPtr fbuf (\ptr -> func (castPtr ptr))
+           withForeignPtr fbuf handler
+        where handler ptr =
+                  do bytesread <- func (castPtr ptr)
+                     peekArray bytesread ptr
     byteSize = length
 
 
@@ -142,23 +148,20 @@ bytes than the given length.
 hGetBufStr :: (HVIO a, BinaryConvertable b) => a -> Int -> IO b
 hGetBufStr f count = fromBuf count (
    fbuf <- mallocForeignPtrArray (count + 1)
-   withForeignPtr fbuf (\buf -> do
-                        bytesread <- hGetBuf f buf count
-                        haskstring <- peekCStringLen (buf, bytesread)
-                        return haskstring)
+   withForeignPtr fbuf (\buf -> vGetBuf f buf count)
 
 -- | An alias for 'hGetBufStr' 'stdin'
-getBufStr :: Int -> IO String
+getBufStr :: (BinaryConvertable b) => Int -> IO b
 getBufStr = hGetBufStr stdin
 
 {- | Like 'hGetBufStr', but guarantees that it will only return fewer than
 the requested number of bytes when EOF is encountered. -}
-hFullGetBufStr :: Handle -> Int -> IO String
+hFullGetBufStr :: (HBIO a, BinaryConvertable b) => a -> Int -> IO b
 hFullGetBufStr f 0 = return ""
 hFullGetBufStr f count = do
                          thisstr <- hGetBufStr f count
-                         if thisstr == "" -- EOF
-                            then return ""
+                         if (byteSize thisstr) == 0
+                            then return []
                             else do
                                  remainder <- hFullGetBufStr f (count - (length thisstr))
                                  return (thisstr ++ remainder)

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list