-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Regional memory pointers -- -- The library allows you to allocate memory in a region yielding a -- regional pointer to it. When the region terminates all pointers are -- automatically freed. Most importantly, a pointer can't be returned -- from the region. So it's impossible to reference unallocated memory. -- -- The primary technique used in this package is called "Lightweight -- monadic regions" which was invented by Oleg Kiselyov and Chung-chieh -- Shan. See: -- -- http://okmij.org/ftp/Haskell/regions.html#light-weight -- -- This technique is implemented in the regions package which is -- re-exported from this library. -- -- This library provides wrappers around all the Ptr functions -- from the Foreign.* modules from base. @package regional-pointers @version 0.1 -- | Unsafe functions for retrieving the actual Ptr from a regional -- pointer and for lifting operations on Ptrs to RegionalPtrs. module Foreign.Ptr.Region.Unsafe unsafePtr :: RegionalPtr α r -> Ptr α unsafeWrap :: (MonadIO m) => (Ptr α -> IO β) -> (RegionalPtr α r -> m β) unsafeWrap2 :: (MonadIO m) => (Ptr α -> γ -> IO β) -> (RegionalPtr α r -> γ -> m β) unsafeWrap3 :: (MonadIO m) => (Ptr α -> γ -> δ -> IO β) -> (RegionalPtr α r -> γ -> δ -> m β) module Foreign.Ptr.Region -- | Represents memory of size number of bytes which may be -- marshalled to or from Haskell values of type α. Before you -- can use the memory you have to allocate it using open. newtype Memory α Memory :: Int -> Memory α size :: Memory α -> Int -- | Handy type synonym for a regional handle to memory. This should -- provide a safer replacement for Foreign.Ptr.Ptr type RegionalPtr α r = RegionalHandle (Memory α) r mapRegionalPtr :: (Ptr α -> Ptr β) -> (RegionalPtr α r -> RegionalPtr β r) -- | Wraps: Foreign.Ptr.castPtr castPtr :: RegionalPtr α r -> RegionalPtr β r -- | Wraps: Foreign.Ptr.plusPtr plusPtr :: RegionalPtr α r -> Int -> RegionalPtr β r -- | Wraps: Foreign.Ptr.alignPtr alignPtr :: RegionalPtr α r -> Int -> RegionalPtr α r -- | Wraps: Foreign.Ptr.minusPtr minusPtr :: RegionalPtr α r -> RegionalPtr β r -> Int module Foreign.Marshal.Alloc.Region -- | Convenience function which allocates sufficient memory to hold values -- of type α, applies the given continuation function to the -- resulting regional pointer and runs the resulting region. -- -- This should provide a safer replacement for: -- Foreign.Marshal.Alloc.alloca. -- -- Note that: alloca = allocaBytes $ sizeOf (undefined -- :: α) alloca :: (Storable α, MonadCatchIO pr) => (forall s. RegionalPtr α (RegionT s pr) -> RegionT s pr β) -> pr β -- | Convenience function which allocates the given number of bytes, -- applies the given continuation function to the resulting regional -- pointer and runs the resulting region. -- -- This should provide a safer replacement for: -- Foreign.Marshal.Alloc.allocaBytes. -- -- Note that: allocaBytes = with . Memory allocaBytes :: (MonadCatchIO pr) => Int -> (forall s. RegionalPtr α (RegionT s pr) -> RegionT s pr β) -> pr β -- | Convenience function which allocates sufficient memory to hold values -- of type α and returns a regional pointer to them. -- -- This should provide a safer replacement for: -- Foreign.Marshal.Alloc.malloc. -- -- Note that: malloc = mallocBytes $ sizeOf (undefined -- :: α) malloc :: (Storable α, MonadCatchIO pr) => RegionT s pr (RegionalPtr α (RegionT s pr)) -- | Convenience function which allocates the given number of bytes and -- returns a regional pointer to them. -- -- This should provide a safer replacement for: -- Foreign.Marshal.Alloc.mallocBytes. -- -- Note that: mallocBytes = open . Memory mallocBytes :: (MonadCatchIO pr) => Int -> RegionT s pr (RegionalPtr α (RegionT s pr)) module Foreign.Marshal.Array.Region mallocArray :: (Storable α, MonadCatchIO pr) => Int -> RegionT s pr (RegionalPtr α (RegionT s pr)) mallocArray0 :: (Storable α, MonadCatchIO pr) => Int -> RegionT s pr (RegionalPtr α (RegionT s pr)) allocaArray :: (Storable α, MonadCatchIO pr) => Int -> (forall s. RegionalPtr α (RegionT s pr) -> RegionT s pr β) -> pr β allocaArray0 :: (Storable α, MonadCatchIO pr) => Int -> (forall s. RegionalPtr α (RegionT s pr) -> RegionT s pr β) -> pr β -- | Wraps: Foreign.Marshal.Array.peekArray. peekArray :: (Storable α, ParentOf pr cr, MonadIO cr) => Int -> RegionalPtr α pr -> cr [α] -- | Wraps: Foreign.Marshal.Array.peekArray0. peekArray0 :: (Storable α, Eq α, ParentOf pr cr, MonadIO cr) => α -> RegionalPtr α pr -> cr [α] -- | Wraps: Foreign.Marshal.Array.pokeArray. pokeArray :: (Storable α, ParentOf pr cr, MonadIO cr) => RegionalPtr α pr -> [α] -> cr () -- | Wraps: Foreign.Marshal.Array.pokeArray0. pokeArray0 :: (Storable α, ParentOf pr cr, MonadIO cr) => α -> RegionalPtr α pr -> [α] -> cr () newArray :: (Storable α, MonadCatchIO pr) => [α] -> RegionT s pr (RegionalPtr α (RegionT s pr)) newArray0 :: (Storable α, MonadCatchIO pr) => α -> [α] -> RegionT s pr (RegionalPtr α (RegionT s pr)) withArray :: (Storable α, MonadCatchIO pr) => [α] -> (forall s. RegionalPtr α (RegionT s pr) -> RegionT s pr β) -> pr β withArray0 :: (Storable α, MonadCatchIO pr) => α -> [α] -> (forall s. RegionalPtr α (RegionT s pr) -> RegionT s pr β) -> pr β withArrayLen :: (Storable α, MonadCatchIO pr) => [α] -> (forall s. Int -> RegionalPtr α (RegionT s pr) -> RegionT s pr β) -> pr β withArrayLen0 :: (Storable α, MonadCatchIO pr) => α -> [α] -> (forall s. Int -> RegionalPtr α (RegionT s pr) -> RegionT s pr β) -> pr β -- | Wraps: Foreign.Marshal.Array.copyArray. copyArray :: (Storable α, ParentOf pr cr, MonadIO cr) => RegionalPtr α pr -> RegionalPtr α pr -> Int -> cr () -- | Wraps: Foreign.Marshal.Array.moveArray. moveArray :: (Storable α, ParentOf pr cr, MonadIO cr) => RegionalPtr α pr -> RegionalPtr α pr -> Int -> cr () -- | Wraps: Foreign.Marshal.Array.lengthArray0. lengthArray0 :: (Storable α, Eq α, ParentOf pr cr, MonadIO cr) => α -> RegionalPtr α pr -> cr Int -- | Wraps: Foreign.Marshal.Array.advancePtr. advancePtr :: (Storable α) => RegionalPtr α pr -> Int -> RegionalPtr α pr -- | Lifts methods of the Storable type class from -- Foreign.Storable to regional pointers. module Foreign.Storable.Region -- | Wraps: Foreign.Storable.peekElemOff. peekElemOff :: (ParentOf pr cr, Storable α, MonadIO cr) => RegionalPtr α pr -> Int -> cr α -- | Wraps: Foreign.Storable.pokeElemOff. pokeElemOff :: (ParentOf pr cr, Storable α, MonadIO cr) => RegionalPtr α pr -> Int -> α -> cr () -- | Wraps: Foreign.Storable.peekByteOff. peekByteOff :: (ParentOf pr cr, Storable α, MonadIO cr) => RegionalPtr β pr -> Int -> cr α -- | Wraps: Foreign.Storable.pokeByteOff. pokeByteOff :: (ParentOf pr cr, Storable α, MonadIO cr) => RegionalPtr β pr -> Int -> α -> cr () -- | Wraps: Foreign.Storable.peek. peek :: (ParentOf pr cr, Storable α, MonadIO cr) => RegionalPtr α pr -> cr α -- | Wraps: Foreign.Storable.poke. poke :: (ParentOf pr cr, Storable α, MonadIO cr) => RegionalPtr α pr -> α -> cr () module Foreign.Marshal.Utils.Region with :: (Storable α, MonadCatchIO pr) => α -> (forall s. RegionalPtr α (RegionT s pr) -> RegionT s pr β) -> pr β new :: (Storable α, MonadCatchIO pr) => α -> RegionT s pr (RegionalPtr α (RegionT s pr)) -- | Convert a Haskell Bool to its numeric representation fromBool :: (Num a) => Bool -> a -- | Convert a Boolean in numeric representation to a Haskell value toBool :: (Num a) => a -> Bool copyBytes :: (ParentOf pr1 cr, ParentOf pr2 cr, MonadIO cr) => RegionalPtr α pr1 -> RegionalPtr α pr2 -> Int -> cr () moveBytes :: (ParentOf pr1 cr, ParentOf pr2 cr, MonadIO cr) => RegionalPtr α pr1 -> RegionalPtr α pr2 -> Int -> cr () -- | Lifts functions and types from Foreign.C.String to regional -- pointers. module Foreign.C.String.Region -- | Handy type synonym for a regional pointer to an array of C characters -- terminated by a NUL. -- -- This should provide a safer replacement for -- Foreign.C.String.CString. type RegionalCString r = RegionalPtr CChar r -- | Handy type synonym for a regional pointer to an array of C characters -- which is paired with the length of the array instead of terminated by -- a NUL. (Thus allowing NUL characters in the middle of the string) -- -- This should provide a safer replacement for -- Foreign.C.String.CStringLen. type RegionalCStringLen r = (RegionalPtr CChar r, Int) peekCString :: (ParentOf pr cr, MonadIO cr) => RegionalCString pr -> cr String peekCStringLen :: (ParentOf pr cr, MonadIO cr) => RegionalCStringLen pr -> cr String newCString :: (MonadCatchIO pr) => String -> RegionT s pr (RegionalCString (RegionT s pr)) newCStringLen :: (MonadCatchIO pr) => String -> RegionT s pr (RegionalCStringLen (RegionT s pr)) withCString :: (MonadCatchIO pr) => String -> (forall s. RegionalCString (RegionT s pr) -> RegionT s pr α) -> pr α withCStringLen :: (MonadCatchIO pr) => String -> (forall s. RegionalCStringLen (RegionT s pr) -> RegionT s pr α) -> pr α charIsRepresentable :: (MonadIO m) => Char -> m Bool -- | Convert a Haskell character to a C character. This function is only -- safe on the first 256 characters. castCharToCChar :: Char -> CChar -- | Convert a C byte, representing a Latin-1 character, to the -- corresponding Haskell character. castCCharToChar :: CChar -> Char peekCAString :: (ParentOf pr cr, MonadIO cr) => RegionalCString pr -> cr String peekCAStringLen :: (ParentOf pr cr, MonadIO cr) => RegionalCStringLen pr -> cr String newCAString :: (MonadCatchIO pr) => String -> RegionT s pr (RegionalCString (RegionT s pr)) newCAStringLen :: (MonadCatchIO pr) => String -> RegionT s pr (RegionalCStringLen (RegionT s pr)) withCAString :: (MonadCatchIO pr) => String -> (forall s. RegionalCString (RegionT s pr) -> RegionT s pr α) -> pr α withCAStringLen :: (MonadCatchIO pr) => String -> (forall s. RegionalCStringLen (RegionT s pr) -> RegionT s pr α) -> pr α -- | Handy type synonym for a regional pointer to an array of C wide -- characters terminated by a NUL. -- -- This should provide a safer replacement for -- Foreign.C.String.CWString. type RegionalCWString r = RegionalPtr CWchar r -- | Handy type synonym for a regional pointer to an array of C wide -- characters which is paired with the length of the array instead of -- terminated by a NUL. (Thus allowing NUL characters in the middle of -- the string) -- -- This should provide a safer replacement for -- Foreign.C.String.CWStringLen. type RegionalCWStringLen r = (RegionalPtr CWchar r, Int) peekCWString :: (ParentOf pr cr, MonadIO cr) => RegionalCWString pr -> cr String peekCWStringLen :: (ParentOf pr cr, MonadIO cr) => RegionalCWStringLen pr -> cr String newCWString :: (MonadCatchIO pr) => String -> RegionT s pr (RegionalCWString (RegionT s pr)) newCWStringLen :: (MonadCatchIO pr) => String -> RegionT s pr (RegionalCWStringLen (RegionT s pr)) withCWString :: (MonadCatchIO pr) => String -> (forall s. RegionalCWString (RegionT s pr) -> RegionT s pr α) -> pr α withCWStringLen :: (MonadCatchIO pr) => String -> (forall s. RegionalCWStringLen (RegionT s pr) -> RegionT s pr α) -> pr α