diff options
author | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2019-11-28 11:39:53 +0300 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-11-29 08:26:07 -0500 |
commit | e921c90fec6754414e97bfabaeeb4eaf0241472d (patch) | |
tree | 497076a6b06dcf143e9da889e73be2dc7e3ca1bc | |
parent | 7f695a20f5f9fe4952ca8cde45d73f3604a7cc29 (diff) | |
download | haskell-e921c90fec6754414e97bfabaeeb4eaf0241472d.tar.gz |
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.
-rw-r--r-- | libraries/base/Foreign/Marshal/Utils.hs | 32 |
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 -- ------------------------------------------- |