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

Modulerebase-1.21.2Haskell2010

Rebase.GHC.Foreign

  • 2 types
  • 10 values
  • Packagerebase-1.21.2
  • Exports12
  • LanguageHaskell2010
  • LicenceMIT
  • SourceEncoding.hs
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.

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).

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.

Determines whether a character can be accurately encoded in a 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.

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.

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.