HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleghc-internal-9.1003.0Haskell2010

GHC.Internal.Foreign.C.String.Encoding

Foreign marshalling support for CStrings with configurable encodings

  • 2 types
  • 10 values

C strings with a configurable encoding

2 declarations
typetype CString = Ptr CChar
#

A C string is a reference to an array of C characters terminated by NUL.

typetype CStringLen = (Ptr CChar, Int)
#

A string with explicit length information in bytes instead of a terminating NUL (allowing NUL characters in the middle of the string).

Conversion of C strings into Haskell strings

2 declarations

Conversion of Haskell strings into C strings

3 declarations

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

Note that this does not NUL terminate the resulting string.

  • new storage is allocated for the C string and must be explicitly freed using free or finalizerFree.

Conversion of Haskell strings into C strings using temporary storage

5 declarations
valuewithCString :: TextEncoding -> String -> (CString -> IO a) -> IO a
#

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), so the pointer to the temporary storage must not be used after this.

valuewithCStringLen :: TextEncoding -> String -> (CStringLen -> IO a) -> IO a
#

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

Note that this does not NUL terminate the resulting string.

  • the memory is freed when the subcomputation terminates (either normally or via an exception), so the pointer to the temporary storage must not be used after this.

valuewithCStringLen0 :: TextEncoding -> String -> (CStringLen -> IO a) -> IO a
#

Marshal a Haskell string into a NUL-terminated 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), so the pointer to the temporary storage must not be used after this.

valuewithCStringsLen
  1. :: TextEncoding
  2. -> [String]
  3. -> Int -> Ptr CString -> IO a
  4. -> IO a
#

Marshal a list of Haskell strings into an array of NUL terminated C strings using temporary storage.

  • the Haskell strings may not contain any NUL characters

  • the memory is freed when the subcomputation terminates (either normally or via an exception), so the pointer to the temporary storage must not be used after this.

Determines whether a character can be accurately encoded in a Foreign.C.String.CString.

Pretty much anyone who uses this function is in a state of sin because whether or not a character is encodable will, in general, depend on the context in which it occurs.