regional-pointers-0.6.0.1: Regional memory pointers

MaintainerBas van Dijk <v.dijk.bas@gmail.com>

Foreign.Ptr.Region.Unsafe

Contents

Description

Unsafe functions for constructing regional pointers, retrieving the native Ptr from a regional pointer and for lifting operations on Ptrs to RegionalPtrs.

Synopsis

Unsafely constructing regional pointers

unsafeRegionalPtr :: MonadIO pr => Ptr α -> Finalizer -> RegionT s pr (RegionalPtr α (RegionT s pr))Source

Construct a regional pointer from a native pointer and an IO computation that finalizes the pointer (like free ptr) which is performed when the region terminates.

This function is unsafe because this library can't guarantee that the finalizer will actually finalize the pointer (suppose having return () as the finalizer). You have to verify the correct finalisation yourself.

Wrapping alloca- and malloc-like functions

wrapAlloca :: MonadControlIO pr => ((Ptr α -> IO (RegionT s pr β)) -> IO (RegionT s pr β)) -> (forall sl. LocalPtr α (LocalRegion sl s) -> RegionT (Local s) pr β) -> RegionT s pr βSource

wrapAlloca2 :: MonadControlIO pr => ((γ -> Ptr α -> IO (RegionT s pr β)) -> IO (RegionT s pr β)) -> (forall sl. γ -> LocalPtr α (LocalRegion sl s) -> RegionT (Local s) pr β) -> RegionT s pr βSource

wrapMalloc :: MonadControlIO pr => IO (Ptr α) -> RegionT s pr (RegionalPtr α (RegionT s pr))Source

Wrapping CStringLen operations

wrapPeekStringLen :: (Pointer pointer, AncestorRegion pr cr, MonadIO cr) => ((Ptr α, Int) -> IO String) -> (pointer α pr, Int) -> cr StringSource

wrapWithStringLen :: MonadControlIO pr => (((Ptr α, Int) -> IO (RegionT s pr β)) -> IO (RegionT s pr β)) -> (forall sl. (LocalPtr α (LocalRegion sl s), Int) -> RegionT (Local s) pr β) -> RegionT s pr βSource

Unsafe utility functions for lifting operations on Ptrs to RegionalPtrs

unsafePtr :: Pointer pointer => pointer α r -> Ptr αSource

Retrieve the native pointer from a regional pointer.

This function is unsafe because it allows you to both free the pointer before the region terminates and use the pointer outside the region when it is already freed.

unsafeWrap :: (MonadIO m, Pointer pointer) => (Ptr α -> IO β) -> pointer α r -> m βSource

unsafeWrap2 :: (MonadIO m, Pointer pointer) => (Ptr α -> γ -> IO β) -> pointer α r -> γ -> m βSource

unsafeWrap3 :: (MonadIO m, Pointer pointer) => (Ptr α -> γ -> δ -> IO β) -> pointer α r -> γ -> δ -> m βSource

unsafeWrap2flp :: (MonadIO m, Pointer pointer) => (γ -> Ptr α -> IO β) -> γ -> pointer α r -> m βSource