| Safe Haskell | Safe | 
|---|---|
| Language | Haskell2010 | 
Ptr.Fun
Synopsis
- data FunPtr a
 - nullFunPtr :: FunPtr a
 - castFunPtr :: FunPtr a -> FunPtr b
 - castFunPtrToPtr :: FunPtr a -> Ptr b
 - castPtrToFunPtr :: Ptr a -> FunPtr b
 - freeHaskellFunPtr :: FunPtr a -> IO ()
 - type FinalizerPtr a = FunPtr (Ptr a -> IO ())
 - type FinalizerEnvPtr env a = FunPtr (Ptr env -> Ptr a -> IO ())
 - finalizerFree :: FinalizerPtr a
 
Documentation
A value of type  is a pointer to a function callable
 from foreign code.  The type FunPtr aa will normally be a foreign type,
 a function type with zero or more arguments where
- the argument types are marshallable foreign types,
   i.e. 
Char,Int,Double,Float,Bool,Int8,Int16,Int32,Int64,Word8,Word16,Word32,Word64,,Ptra,FunPtraor a renaming of any of these usingStablePtranewtype. - the return type is either a marshallable foreign type or has the form
   
whereIOttis a marshallable foreign type or(). 
A value of type  may be a pointer to a foreign function,
 either returned by another foreign function or imported with a
 a static address import likeFunPtr a
foreign import ccall "stdlib.h &free" p_free :: FunPtr (Ptr a -> IO ())
or a pointer to a Haskell function created using a wrapper stub
 declared to produce a FunPtr of the correct type.  For example:
type Compare = Int -> Int -> Bool foreign import ccall "wrapper" mkCompare :: Compare -> IO (FunPtr Compare)
Calls to wrapper stubs like mkCompare allocate storage, which
 should be released with freeHaskellFunPtr when no
 longer required.
To convert FunPtr values to corresponding Haskell functions, one
 can define a dynamic stub for the specific foreign type, e.g.
type IntFunction = CInt -> IO () foreign import ccall "dynamic" mkFun :: FunPtr IntFunction -> IntFunction
Instances
| NFData1 FunPtr | Since: deepseq-1.4.3.0  | 
Defined in Control.DeepSeq  | |
| Eq (FunPtr a) | |
| Ord (FunPtr a) | |
Defined in GHC.Ptr  | |
| Show (FunPtr a) | Since: base-2.1  | 
| Hashable (FunPtr a) | |
Defined in Data.Hashable.Class  | |
| Storable (FunPtr a) | Since: base-2.1  | 
Defined in Foreign.Storable  | |
| NFData (FunPtr a) | Since: deepseq-1.4.2.0  | 
Defined in Control.DeepSeq  | |
| Prim (FunPtr a) | |
Defined in Data.Primitive.Types Methods alignment# :: FunPtr a -> Int# # indexByteArray# :: ByteArray# -> Int# -> FunPtr a # readByteArray# :: MutableByteArray# s -> Int# -> State# s -> (#State# s, FunPtr a#) # writeByteArray# :: MutableByteArray# s -> Int# -> FunPtr a -> State# s -> State# s # setByteArray# :: MutableByteArray# s -> Int# -> Int# -> FunPtr a -> State# s -> State# s # indexOffAddr# :: Addr# -> Int# -> FunPtr a # readOffAddr# :: Addr# -> Int# -> State# s -> (#State# s, FunPtr a#) # writeOffAddr# :: Addr# -> Int# -> FunPtr a -> State# s -> State# s # setOffAddr# :: Addr# -> Int# -> Int# -> FunPtr a -> State# s -> State# s #  | |
nullFunPtr :: FunPtr a #
The constant nullFunPtr contains a
 distinguished value of FunPtr that is not
 associated with a valid memory location.
castFunPtrToPtr :: FunPtr a -> Ptr b #
castPtrToFunPtr :: Ptr a -> FunPtr b #
freeHaskellFunPtr :: FunPtr a -> IO () #
Release the storage associated with the given FunPtr, which
 must have been obtained from a wrapper stub.  This should be called
 whenever the return value from a foreign import wrapper function is
 no longer required; otherwise, the storage it uses will leak.
type FinalizerPtr a = FunPtr (Ptr a -> IO ()) #
A finalizer is represented as a pointer to a foreign function that, at finalisation time, gets as an argument a plain pointer variant of the foreign pointer that the finalizer is associated with.
Note that the foreign function must use the ccall calling convention.
finalizerFree :: FinalizerPtr a #
A pointer to a foreign function equivalent to free, which may be
 used as a finalizer (cf ForeignPtr) for storage
 allocated with malloc, mallocBytes, realloc or reallocBytes.