-{-# OPTIONS -#include "HsBase.h" #-}
+{-# OPTIONS_GHC -#include "HsBase.h" #-}
-----------------------------------------------------------------------------
-- |
-- Module : Data.Array.IO
--
-- Maintainer : libraries@haskell.org
-- Stability : experimental
--- Portability : non-portable
+-- Portability : non-portable (uses Data.Array.MArray)
--
-- Mutable boxed and unboxed arrays in the IO monad.
--
let avail = w - r
copied <- if (count >= avail)
then do
- memcpy_ba_baoff ptr raw r (fromIntegral avail)
+ memcpy_ba_baoff ptr raw (fromIntegral r) (fromIntegral avail)
writeIORef ref buf{ bufWPtr=0, bufRPtr=0 }
return avail
else do
- memcpy_ba_baoff ptr raw r (fromIntegral count)
+ memcpy_ba_baoff ptr raw (fromIntegral r) (fromIntegral count)
writeIORef ref buf{ bufRPtr = r + count }
return count
if (size - w > count)
-- There's enough room in the buffer:
-- just copy the data in and update bufWPtr.
- then do memcpy_baoff_ba old_raw w raw (fromIntegral count)
+ then do memcpy_baoff_ba old_raw (fromIntegral w) raw (fromIntegral count)
writeIORef ref old_buf{ bufWPtr = w + count }
return ()
-- Internal Utils
foreign import ccall unsafe "__hscore_memcpy_dst_off"
- memcpy_baoff_ba :: RawBuffer -> Int -> RawBuffer -> CSize -> IO (Ptr ())
+ memcpy_baoff_ba :: RawBuffer -> CInt -> RawBuffer -> CSize -> IO (Ptr ())
foreign import ccall unsafe "__hscore_memcpy_src_off"
- memcpy_ba_baoff :: RawBuffer -> RawBuffer -> Int -> CSize -> IO (Ptr ())
+ memcpy_ba_baoff :: RawBuffer -> RawBuffer -> CInt -> CSize -> IO (Ptr ())
illegalBufferSize :: Handle -> String -> Int -> IO a
illegalBufferSize handle fn sz =
#else /* !__GLASGOW_HASKELL__ */
hGetArray :: Handle -> IOUArray Int Word8 -> Int -> IO Int
-hGetArray handle arr count
- | count < 0 || count > rangeSize (bounds arr)
- = illegalBufferSize handle "hGetArray" count
- | otherwise = get 0
+hGetArray handle arr count = do
+ bds <- getBounds arr
+ if count < 0 || count > rangeSize bds
+ then illegalBufferSize handle "hGetArray" count
+ else get 0
where
get i | i == count = return i
| otherwise = do
get (i+1)
hPutArray :: Handle -> IOUArray Int Word8 -> Int -> IO ()
-hPutArray handle arr count
- | count < 0 || count > rangeSize (bounds arr)
- = illegalBufferSize handle "hPutArray" count
- | otherwise = put 0
+hPutArray handle arr count = do
+ bds <- getBounds arr
+ if count < 0 || count > rangeSize bds
+ then illegalBufferSize handle "hPutArray" count
+ else put 0
where
put i | i == count = return ()
| otherwise = do