[GHC] #869: Foreign.C.String.withCStringLen doesn't terminate C
string by NUL
GHC
trac at galois.com
Fri Aug 18 10:47:18 EDT 2006
#869: Foreign.C.String.withCStringLen doesn't terminate C string by NUL
-----------------------------+----------------------------------------------
Reporter: guest | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: libraries/base | Version: 6.4.2
Severity: normal | Resolution:
Keywords: | Os: Linux
Difficulty: Unknown | Architecture: x86
-----------------------------+----------------------------------------------
Comment (by duncan):
From my reading of the FFI spec CStringLen is not required to be nul
terminated. So I think the code is correct and the documentation is wrong.
{{{
type CString = Ptr CChar
A C string is a reference to an array of C characters
terminated by NUL.
type CStringLen = (Ptr CChar, Int)
In addition to NUL-terminated strings, the module CString also
supports strings with explicit length information in bytes.
newCString :: String -> IO CString
newCStringLen :: String -> IO CStringLen
Allocate a memory area for a Haskell string and marshal the
string into its C representation. There are two variants of
the routine, one for each supported string representation.
withCString :: String -> (CString -> IO a) -> IO a
withCStringLen :: String -> (CStringLen -> IO a) -> IO a
These two routines operate as newCString and newCStringLen,
respectively, but handle memory allocation and deallocation
like MarshalAlloc.alloca (Section 5.8).
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/869>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list