Commit e921c90f authored by Ömer Sinan Ağacan's avatar Ömer Sinan Ağacan Committed by Marge Bot

Improve few Foreign.Marshal.Utils docs

In copyBytes and moveBytes mention which argument is source and which is
destination.

Also fixes some of the crazy indentation in the module and cleans
trailing whitespace.
parent 7f695a20
......@@ -6,7 +6,7 @@
-- Module : Foreign.Marshal.Utils
-- Copyright : (c) The FFI task force 2001
-- License : BSD-style (see the file libraries/base/LICENSE)
--
--
-- Maintainer : ffi@haskell.org
-- Stability : provisional
-- Portability : portable
......@@ -72,8 +72,8 @@ import GHC.Base
-- 'Foreign.Marshal.Alloc.finalizerFree' when no longer required.
--
new :: Storable a => a -> IO (Ptr a)
new val =
do
new val =
do
ptr <- malloc
poke ptr val
return ptr
......@@ -122,12 +122,12 @@ maybeNew = maybe (return nullPtr)
-- |Converts a @withXXX@ combinator into one marshalling a value wrapped
-- into a 'Maybe', using 'nullPtr' to represent 'Nothing'.
--
maybeWith :: ( a -> (Ptr b -> IO c) -> IO c)
maybeWith :: ( a -> (Ptr b -> IO c) -> IO c)
-> (Maybe a -> (Ptr b -> IO c) -> IO c)
maybeWith = maybe ($ nullPtr)
-- |Convert a peek combinator into a one returning 'Nothing' if applied to a
-- 'nullPtr'
-- 'nullPtr'
--
maybePeek :: (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek peek ptr | ptr == nullPtr = return Nothing
......@@ -155,16 +155,26 @@ withMany withFoo (x:xs) f = withFoo x $ \x' ->
-- |Copies the given number of bytes from the second area (source) into the
-- first (destination); the copied areas may /not/ overlap
--
copyBytes :: Ptr a -> Ptr a -> Int -> IO ()
copyBytes dest src size = do _ <- memcpy dest src (fromIntegral size)
return ()
copyBytes
:: Ptr a -- ^ Destination
-> Ptr a -- ^ Source
-> Int -- ^ Size in bytes
-> IO ()
copyBytes dest src size = do
_ <- memcpy dest src (fromIntegral size)
return ()
-- |Copies the given number of bytes from the second area (source) into the
-- first (destination); the copied areas /may/ overlap
--
moveBytes :: Ptr a -> Ptr a -> Int -> IO ()
moveBytes dest src size = do _ <- memmove dest src (fromIntegral size)
return ()
moveBytes
:: Ptr a -- ^ Destination
-> Ptr a -- ^ Source
-> Int -- ^ Size in bytes
-> IO ()
moveBytes dest src size = do
_ <- memmove dest src (fromIntegral size)
return ()
-- Filling up memory area with required values
-- -------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment