regional-pointers-0.4: Regional memory pointers

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

Foreign.C.String.Region

Contents

Description

Lifts functions and types from Foreign.C.String to regional pointers.

Synopsis

Regional C Strings

type RegionalCString r = RegionalPtr CChar rSource

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 RegionalCStringLen r = (RegionalPtr CChar r, Int)Source

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.

Using a locale-dependent encoding

peekCString :: (ParentOf pr cr, MonadIO cr) => RegionalCString pr -> cr StringSource

Marshal a NUL terminated C string into a Haskell string.

Wraps: Foreign.C.String.peekCString

peekCStringLen :: (ParentOf pr cr, MonadIO cr) => RegionalCStringLen pr -> cr StringSource

Marshal a C string with explicit length into a Haskell string.

Wraps: Foreign.C.String.peekCStringLen.

newCString :: MonadCatchIO pr => String -> RegionT s pr (RegionalCString (RegionT s pr))Source

Marshal a Haskell string into a NUL terminated C string.

The Haskell string may not contain any NUL characters

Wraps: Foreign.C.String.newCString.

newCStringLen :: MonadCatchIO pr => String -> RegionT s pr (RegionalCStringLen (RegionT s pr))Source

Marshal a Haskell string into a C string (ie, character array) with explicit length information.

Wraps: Foreign.C.String.newCStringLen.

withCString :: MonadCatchIO pr => String -> (forall s. RegionalCString (RegionT s pr) -> RegionT s pr α) -> pr αSource

Marshal a Haskell string into a NUL terminated C string using temporary storage.

  • the Haskell string may not contain any NUL characters
  • the memory is freed when the subcomputation terminates (either normally or via an exception).

Wraps: Foreign.C.String.withCString.

withCStringLen :: MonadCatchIO pr => String -> (forall s. RegionalCStringLen (RegionT s pr) -> RegionT s pr α) -> pr αSource

Marshal a Haskell string into a C string (ie, character array) in temporary storage, with explicit length information.

  • the memory is freed when the subcomputation terminates (either normally or via an exception).

Wraps: Foreign.C.String.withCStringLen.

charIsRepresentable :: MonadIO m => Char -> m BoolSource

Generalizes Foreign.C.String.charIsRepresentable to any MonadIO.

Using 8-bit characters

castCharToCChar :: Char -> CChar

Convert a Haskell character to a C character. This function is only safe on the first 256 characters.

castCCharToChar :: CChar -> Char

Convert a C byte, representing a Latin-1 character, to the corresponding Haskell character.

peekCAString :: (ParentOf pr cr, MonadIO cr) => RegionalCString pr -> cr StringSource

Marshal a NUL terminated C string into a Haskell string.

Wraps: Foreign.C.String.peekCAString.

peekCAStringLen :: (ParentOf pr cr, MonadIO cr) => RegionalCStringLen pr -> cr StringSource

Marshal a C string with explicit length into a Haskell string.

Wraps: Foreign.C.String.peekCAStringLen.

newCAString :: MonadCatchIO pr => String -> RegionT s pr (RegionalCString (RegionT s pr))Source

Marshal a Haskell string into a NUL terminated C string.

The Haskell string may not contain any NUL characters

Wraps: Foreign.C.String.newCAString.

newCAStringLen :: MonadCatchIO pr => String -> RegionT s pr (RegionalCStringLen (RegionT s pr))Source

Marshal a Haskell string into a C string (ie, character array) with explicit length information.

Wraps: Foreign.C.String.newCAStringLen.

withCAString :: MonadCatchIO pr => String -> (forall s. RegionalCString (RegionT s pr) -> RegionT s pr α) -> pr αSource

Marshal a Haskell string into a NUL terminated C string using temporary storage.

  • the Haskell string may not contain any NUL characters
  • the memory is freed when the subcomputation terminates (either normally or via an exception).

Wraps: Foreign.C.String.withCAString.

withCAStringLen :: MonadCatchIO pr => String -> (forall s. RegionalCStringLen (RegionT s pr) -> RegionT s pr α) -> pr αSource

Marshal a Haskell string into a C string (ie, character array) in temporary storage, with explicit length information.

  • the memory is freed when the subcomputation terminates (either normally or via an exception).

Wraps: Foreign.C.String.withCAStringLen.

C wide strings

type RegionalCWString r = RegionalPtr CWchar rSource

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 RegionalCWStringLen r = (RegionalPtr CWchar r, Int)Source

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.

peekCWString :: (ParentOf pr cr, MonadIO cr) => RegionalCWString pr -> cr StringSource

Marshal a NUL terminated C wide string into a Haskell string.

Wraps: Foreign.C.String.peekCWString.

peekCWStringLen :: (ParentOf pr cr, MonadIO cr) => RegionalCWStringLen pr -> cr StringSource

Marshal a C wide string with explicit length into a Haskell string.

Wraps: Foreign.C.String.peekCWStringLen.

newCWString :: MonadCatchIO pr => String -> RegionT s pr (RegionalCWString (RegionT s pr))Source

Marshal a Haskell string into a NUL terminated C wide string.

The Haskell string may not contain any NUL characters.

Wraps: Foreign.C.String.newCWString.

newCWStringLen :: MonadCatchIO pr => String -> RegionT s pr (RegionalCWStringLen (RegionT s pr))Source

Marshal a Haskell string into a C wide string (ie, wide character array) with explicit length information.

Wraps: Foreign.C.String.newCWStringLen.

withCWString :: MonadCatchIO pr => String -> (forall s. RegionalCWString (RegionT s pr) -> RegionT s pr α) -> pr αSource

Marshal a Haskell string into a NUL terminated C wide string using temporary storage.

  • the Haskell string may not contain any NUL characters
  • the memory is freed when the subcomputation terminates (either normally or via an exception).

Wraps: Foreign.C.String.withCWString.

withCWStringLen :: MonadCatchIO pr => String -> (forall s. RegionalCWStringLen (RegionT s pr) -> RegionT s pr α) -> pr αSource

Marshal a Haskell string into a NUL terminated C wide string using temporary storage.

  • the Haskell string may not contain any NUL characters.
  • the memory is freed when the subcomputation terminates (either normally or via an exception).

Wraps: Foreign.C.String.withCWStringLen.