HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulebase-4.20.2.0Haskell2010

Foreign.Marshal.Utils

Utilities for primitive marshaling

  • 11 values
  • Packagebase-4.20.2.0
  • Exports11
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceUtils.hs

General marshalling utilities

0 declarations

Combined allocation and marshalling

valuewith :: Storable a => a -> (Ptr a -> IO b) -> IO b
#

with val f executes the computation f, passing as argument a pointer to a temporarily allocated block of memory into which val has been marshalled (the combination of alloca and poke).

The memory is freed when f terminates (either normally or via an exception), so the pointer passed to f must not be used after this.

valuenew :: Storable a => a -> IO (Ptr a)
#

Allocate a block of memory and marshal a value into it (the combination of malloc and poke). The size of the area allocated is determined by the sizeOf method from the instance of Storable for the appropriate type.

The memory may be deallocated using free or finalizerFree when no longer required.

Marshalling of Boolean values (non-zero corresponds to True)

valuetoBool :: (Eq a, Num a) => a -> Bool
#

Convert a Boolean in numeric representation to a Haskell value

Marshalling of Maybe values

Marshalling lists of storable objects

valuewithMany :: (a -> (b -> res) -> res) -> [a] -> ([b] -> res) -> res
#

Replicates a withXXX combinator over a list of objects, yielding a list of marshalled objects

Haskellish interface to memcpy and memmove

(argument order: destination, source)

valuecopyBytes
  1. :: Ptr a

    Destination

  2. -> Ptr a

    Source

  3. -> Int

    Size in bytes

  4. -> IO ()
#

Copies the given number of bytes from the second area (source) into the first (destination); the copied areas may not overlap

valuemoveBytes
  1. :: Ptr a

    Destination

  2. -> Ptr a

    Source

  3. -> Int

    Size in bytes

  4. -> IO ()
#

Copies the given number of bytes from the second area (source) into the first (destination); the copied areas may overlap

Filling up memory area with required values

valuefillBytes :: Ptr a -> Word8 -> Int -> IO ()
#

Fill a given number of bytes in memory area with a byte value.