summaryrefslogtreecommitdiff
path: root/libraries/base/Foreign
diff options
context:
space:
mode:
authorJosh Meredith <joshmeredith2008@gmail.com>2019-12-04 23:39:28 +1100
committerJosh Meredith <joshmeredith2008@gmail.com>2019-12-04 23:39:28 +1100
commita8435165b84c32fd2ebdd1281dd6ee077e07ad5a (patch)
tree791936d014aeaa26174c2dcbef34c14f3329dd04 /libraries/base/Foreign
parent7805441b4d5e22eb63a501e1e40383d10380dc92 (diff)
parentf03a41d4bf9418ee028ecb51654c928b2da74edd (diff)
downloadhaskell-wip/binary-readerT.tar.gz
Merge branch 'master' into wip/binary-readerTwip/binary-readerT
Diffstat (limited to 'libraries/base/Foreign')
-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
-- -------------------------------------------