Copyright | (c) The University of Glasgow 2008-2011 |
---|---|
License | see libraries/base/LICENSE |
Maintainer | libraries@haskell.org |
Stability | internal |
Portability | non-portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Foreign marshalling support for CStrings with configurable encodings
Synopsis
- type CString = Ptr CChar
- type CStringLen = (Ptr CChar, Int)
- peekCString :: TextEncoding -> CString -> IO String
- peekCStringLen :: TextEncoding -> CStringLen -> IO String
- newCString :: TextEncoding -> String -> IO CString
- newCStringLen :: TextEncoding -> String -> IO CStringLen
- newCStringLen0 :: TextEncoding -> String -> IO CStringLen
- withCString :: TextEncoding -> String -> (CString -> IO a) -> IO a
- withCStringLen :: TextEncoding -> String -> (CStringLen -> IO a) -> IO a
- withCStringLen0 :: TextEncoding -> String -> (CStringLen -> IO a) -> IO a
- withCStringsLen :: TextEncoding -> [String] -> (Int -> Ptr CString -> IO a) -> IO a
- charIsRepresentable :: TextEncoding -> Char -> IO Bool
C strings with a configurable encoding
type CString = Ptr CChar Source #
A C string is a reference to an array of C characters terminated by NUL.
type CStringLen = (Ptr CChar, Int) Source #
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
peekCString :: TextEncoding -> CString -> IO String Source #
Marshal a NUL terminated C string into a Haskell string.
peekCStringLen :: TextEncoding -> CStringLen -> IO String Source #
Marshal a C string with explicit length into a Haskell string.
Conversion of Haskell strings into C strings
newCString :: TextEncoding -> String -> IO CString Source #
Marshal a Haskell string into a NUL terminated C string.
- the Haskell string may not contain any NUL characters
- new storage is allocated for the C string and must be
explicitly freed using
free
orfinalizerFree
.
newCStringLen :: TextEncoding -> String -> IO CStringLen Source #
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
orfinalizerFree
.
newCStringLen0 :: TextEncoding -> String -> IO CStringLen Source #
Marshal a Haskell string into a NUL-terminated C string (ie, character array) with explicit length information.
- new storage is allocated for the C string and must be
explicitly freed using
free
orfinalizerFree
.
@since base-4.19.0.0
Conversion of Haskell strings into C strings using temporary storage
withCString :: TextEncoding -> String -> (CString -> IO a) -> IO a 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), so the pointer to the temporary storage must not be used after this.
withCStringLen :: TextEncoding -> String -> (CStringLen -> IO a) -> IO a Source #
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.
withCStringLen0 :: TextEncoding -> String -> (CStringLen -> IO a) -> IO a Source #
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.
@since base-4.19.0.0
withCStringsLen :: TextEncoding -> [String] -> (Int -> Ptr CString -> IO a) -> IO a Source #
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.
charIsRepresentable :: TextEncoding -> Char -> IO Bool Source #
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.