Foreign

module Foreign
base Foreign
A collection of data types, classes, and functions for interfacing with another programming language.
module Data.Text.Foreign
text Data.Text.Foreign
Support for using Text data with native code via the Haskell foreign function interface.
data Foreign
template-haskell Language.Haskell.TH.Syntax, template-haskell Language.Haskell.TH
module Foreign.ForeignPtr
base Foreign.ForeignPtr
The ForeignPtr type and operations. This module is part of the Foreign Function Interface (FFI) and will usually be imported via the Foreign module.
data ForeignPtr a
base Foreign.ForeignPtr
The type ForeignPtr represents references to objects that are maintained in a foreign language, i.e., that are not part of the data structures usually managed by the Haskell storage manager. The essential difference between ForeignPtrs and vanilla memory references of type Ptr a is that the former may be associated with finalizers. A finalizer is a routine that is invoked when the Haskell storage manager detects that - within the Haskell heap and stack - there are no more references left that are pointing to the ForeignPtr. Typically, the finalizer will, then, invoke routines in the foreign language that free the resources bound by the foreign object. The ForeignPtr is parameterised in the same way as Ptr. The type argument of ForeignPtr should normally be an instance of class Storable.
ForeignD :: Foreign -> Dec
template-haskell Language.Haskell.TH.Syntax, template-haskell Language.Haskell.TH
> { foreign import ... } > { foreign export ... }
keyword foreign
keyword
package foreign-storable-asymmetric
package
Utilities useful for working with unioned data structures, where you want to use a different peek and poke. This is particularly useful for use with the ioctl package if you have an ioctl that provides output of a different type to the input. Version 0.0.1
addForeignPtrFinalizer :: FinalizerPtr a -> ForeignPtr a -> IO ()
base Foreign.ForeignPtr
This function adds a finalizer to the given foreign object. The finalizer will run before all other finalizers for the same object which have already been registered.
addForeignPtrFinalizer :: ForeignPtr a -> IO () -> IO ()
base Foreign.Concurrent
This function adds a finalizer to the given ForeignPtr. The finalizer will run after the last reference to the foreign object is dropped, but before all previously registered finalizers for the same object.
addForeignPtrFinalizerEnv :: FinalizerEnvPtr env a -> Ptr env -> ForeignPtr a -> IO ()
base Foreign.ForeignPtr
Like addForeignPtrFinalizerEnv but allows the finalizer to be passed an additional environment parameter to be passed to the finalizer. The environment passed to the finalizer is fixed by the second argument to addForeignPtrFinalizerEnv
castForeignPtr :: ForeignPtr a -> ForeignPtr b
base Foreign.ForeignPtr
This function casts a ForeignPtr parameterised by one type into another type.
finalizeForeignPtr :: ForeignPtr a -> IO ()
base Foreign.ForeignPtr
Causes the finalizers associated with a foreign pointer to be run immediately.
mallocForeignPtr :: Storable a => IO (ForeignPtr a)
base Foreign.ForeignPtr
Allocate some memory and return a ForeignPtr to it. The memory will be released automatically when the ForeignPtr is discarded. mallocForeignPtr is equivalent to > do { p <- malloc; newForeignPtr finalizerFree p } although it may be implemented differently internally: you may not assume that the memory returned by mallocForeignPtr has been allocated with Foreign.Marshal.Alloc.malloc. GHC notes: mallocForeignPtr has a heavily optimised implementation in GHC. It uses pinned memory in the garbage collected heap, so the ForeignPtr does not require a finalizer to free the memory. Use of mallocForeignPtr and associated functions is strongly recommended in preference to newForeignPtr with a finalizer.
mallocForeignPtrArray :: Storable a => Int -> IO (ForeignPtr a)
base Foreign.ForeignPtr
This function is similar to Foreign.Marshal.Array.mallocArray, but yields a memory area that has a finalizer attached that releases the memory area. As with mallocForeignPtr, it is not guaranteed that the block of memory was allocated by Foreign.Marshal.Alloc.malloc.
mallocForeignPtrArray0 :: Storable a => Int -> IO (ForeignPtr a)
base Foreign.ForeignPtr
This function is similar to Foreign.Marshal.Array.mallocArray0, but yields a memory area that has a finalizer attached that releases the memory area. As with mallocForeignPtr, it is not guaranteed that the block of memory was allocated by Foreign.Marshal.Alloc.malloc.
mallocForeignPtrBytes :: Int -> IO (ForeignPtr a)
base Foreign.ForeignPtr
This function is similar to mallocForeignPtr, except that the size of the memory required is given explicitly as a number of bytes.
newForeignPtr :: FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
base Foreign.ForeignPtr
Turns a plain memory reference into a foreign pointer, and associates a finalizer with the reference. The finalizer will be executed after the last reference to the foreign object is dropped. There is no guarantee of promptness, however the finalizer will be executed before the program exits.
newForeignPtr :: Ptr a -> IO () -> IO (ForeignPtr a)
base Foreign.Concurrent
Turns a plain memory reference into a foreign object by associating a finalizer - given by the monadic operation - with the reference. The finalizer will be executed after the last reference to the foreign object is dropped. There is no guarantee of promptness, and in fact there is no guarantee that the finalizer will eventually run at all.
newForeignPtr_ :: Ptr a -> IO (ForeignPtr a)
base Foreign.ForeignPtr
Turns a plain memory reference into a foreign pointer that may be associated with finalizers by using addForeignPtrFinalizer.

Show more results