summaryrefslogtreecommitdiff
path: root/libraries/base/Foreign/Marshal/Utils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/base/Foreign/Marshal/Utils.hs')
-rw-r--r--libraries/base/Foreign/Marshal/Utils.hs32
1 files changed, 21 insertions, 11 deletions
diff --git a/libraries/base/Foreign/Marshal/Utils.hs b/libraries/base/Foreign/Marshal/Utils.hs
index 30e80035fa..f6bec7aacb 100644
--- a/libraries/base/Foreign/Marshal/Utils.hs
+++ b/libraries/base/Foreign/Marshal/Utils.hs
@@ -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
-- -------------------------------------------