-{-# OPTIONS -fno-implicit-prelude #-}
+{-# OPTIONS_GHC -fno-implicit-prelude #-}
-----------------------------------------------------------------------------
-- |
-- Module : Foreign.C.String
newCAStringLen str = do
ptr <- mallocArray0 len
let
- go [] n = n `seq` return n -- make it strict in n
+ go [] n = n `seq` return () -- make it strict in n
go (c:cs) n = do pokeElemOff ptr n (castCharToCChar c); go cs (n+1)
- len <- go str 0
+ go str 0
return (ptr, len)
+ where
+ len = length str
#endif
-- | Marshal a Haskell string into a NUL terminated C string using temporary
withCAStringLen str f =
allocaArray len $ \ptr ->
let
- go [] n = n `seq` return n -- make it strict in n
+ go [] n = n `seq` return () -- make it strict in n
go (c:cs) n = do pokeElemOff ptr n (castCharToCChar c); go cs (n+1)
in do
- len <- go str 0
+ go str 0
f (ptr,len)
+ where
+ len = length str
#endif
-- auxiliary definitions
cWcharsToChars :: [CWchar] -> [Char]
charsToCWchars :: [Char] -> [CWchar]
-#ifdef mingw32_TARGET_OS
+#ifdef mingw32_HOST_OS
-- On Windows, wchar_t is 16 bits wide and CWString uses the UTF-16 encoding.
fromIntegral (c' `div` 0x400 + 0xd800) :
fromIntegral (c' `mod` 0x400 + 0xdc00) : wcs
-#else /* !mingw32_TARGET_OS */
+#else /* !mingw32_HOST_OS */
cWcharsToChars xs = map castCWcharToChar xs
charsToCWchars xs = map castCharToCWchar xs
castCharToCWchar :: Char -> CWchar
castCharToCWchar ch = fromIntegral (ord ch)
-#endif /* !mingw32_TARGET_OS */
+#endif /* !mingw32_HOST_OS */