basement-0.0.16: Foundation scrap box of array & string

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | experimental
Portability | portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Basement.FinalPtr

Description

A smaller ForeignPtr reimplementation that work in any prim monad.

Here be dragon.

Synopsis

- data FinalPtr a
  - = FinalPtr (Ptr a)
  - | FinalForeign (ForeignPtr a)
- finalPtrSameMemory :: FinalPtr a -> FinalPtr b -> Bool
- castFinalPtr :: FinalPtr a -> FinalPtr b
- toFinalPtr :: PrimMonad prim => Ptr a -> (Ptr a -> IO ()) -> prim (FinalPtr a)
- toFinalPtrForeign :: ForeignPtr a -> FinalPtr a
- touchFinalPtr :: PrimMonad prim => FinalPtr p -> prim ()
- withFinalPtr :: PrimMonad prim => FinalPtr p -> (Ptr p -> prim a) -> prim a
- withUnsafeFinalPtr :: PrimMonad prim => FinalPtr p -> (Ptr p -> prim a) -> a
- withFinalPtrNoTouch :: FinalPtr p -> (Ptr p -> a) -> a

# Documentation

data FinalPtr a Source #

Create a pointer with an associated finalizer

Constructors

FinalPtr (Ptr a) |
FinalForeign (ForeignPtr a) |

#### Instances

Instances details

Show (FinalPtr a) Source # |
Instance details Defined in Basement.FinalPtr Methods showsPrec :: Int -> FinalPtr a -> ShowS Source # show :: FinalPtr a -> String Source # showList :: [FinalPtr a] -> ShowS Source #
Eq (FinalPtr a) Source # |
Instance details Defined in Basement.FinalPtr Methods (==) :: FinalPtr a -> FinalPtr a -> Bool Source # (/=) :: FinalPtr a -> FinalPtr a -> Bool Source #
Ord (FinalPtr a) Source # |

Instance details

Defined in Basement.FinalPtr

Methods

compare :: FinalPtr a -> FinalPtr a -> Ordering Source #

(<) :: FinalPtr a -> FinalPtr a -> Bool Source #

(<=) :: FinalPtr a -> FinalPtr a -> Bool Source #

(>) :: FinalPtr a -> FinalPtr a -> Bool Source #

(>=) :: FinalPtr a -> FinalPtr a -> Bool Source #

max :: FinalPtr a -> FinalPtr a -> FinalPtr a Source #

min :: FinalPtr a -> FinalPtr a -> FinalPtr a Source #

finalPtrSameMemory :: FinalPtr a -> FinalPtr b -> Bool Source #

Check if 2 final ptr points on the same memory bits

it stand to reason that provided a final ptr that is still being referenced and thus have the memory still valid, if 2 final ptrs have the same address, they should be the same final ptr

castFinalPtr :: FinalPtr a -> FinalPtr b Source #

Cast a finalized pointer from type a to type b

toFinalPtr :: PrimMonad prim => Ptr a -> (Ptr a -> IO ()) -> prim (FinalPtr a) Source #

create a new FinalPtr from a Pointer

toFinalPtrForeign :: ForeignPtr a -> FinalPtr a Source #

Create a new FinalPtr from a ForeignPtr

touchFinalPtr :: PrimMonad prim => FinalPtr p -> prim () Source #

withFinalPtr :: PrimMonad prim => FinalPtr p -> (Ptr p -> prim a) -> prim a Source #

Looks at the raw pointer inside a FinalPtr, making sure the data pointed by the pointer is not finalized during the call to `f`

withUnsafeFinalPtr :: PrimMonad prim => FinalPtr p -> (Ptr p -> prim a) -> a Source #

Unsafe version of `withFinalPtr`

withFinalPtrNoTouch :: FinalPtr p -> (Ptr p -> a) -> a Source #