FIX part of #2301
[ghc-base.git] / Foreign / C / String.hs
index b03d32b..931b661 100644 (file)
@@ -1,4 +1,4 @@
-{-# OPTIONS -fno-implicit-prelude #-}
+{-# OPTIONS_GHC -XNoImplicitPrelude #-}
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Foreign.C.String
@@ -168,10 +168,8 @@ newCStringLen = newCAStringLen
 withCString :: String -> (CString -> IO a) -> IO a
 withCString = withCAString
 
--- | Marshal a Haskell string into a NUL terminated C string using temporary
--- storage.
---
--- * the Haskell string may /not/ contain any NUL characters
+-- | Marshal a Haskell string into a 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
@@ -216,8 +214,8 @@ peekCAString cp = do
   where
     loop s i = do
         xval <- peekElemOff cp i
-       let val = castCCharToChar xval
-       val `seq` if i <= 0 then return (val:s) else loop (val:s) (i-1)
+        let val = castCCharToChar xval
+        val `seq` if i <= 0 then return (val:s) else loop (val:s) (i-1)
 #endif
 
 -- | Marshal a C string with explicit length into a Haskell string.
@@ -234,11 +232,11 @@ peekCAStringLen (cp, len)
   where
     loop acc i = do
          xval <- peekElemOff cp i
-        let val = castCCharToChar xval
-          -- blow away the coercion ASAP.
-        if (val `seq` (i == 0))
-         then return (val:acc)
-         else loop (val:acc) (i-1)
+         let val = castCCharToChar xval
+           -- blow away the coercion ASAP.
+         if (val `seq` (i == 0))
+          then return (val:acc)
+          else loop (val:acc) (i-1)
 #endif
 
 -- | Marshal a Haskell string into a NUL terminated C string.
@@ -256,8 +254,8 @@ newCAString  = newArray0 nUL . charsToCChars
 newCAString str = do
   ptr <- mallocArray0 (length str)
   let
-       go [] n     = pokeElemOff ptr n nUL
-       go (c:cs) n = do pokeElemOff ptr n (castCharToCChar c); go cs (n+1)
+        go [] n     = pokeElemOff ptr n nUL
+        go (c:cs) n = do pokeElemOff ptr n (castCharToCChar c); go cs (n+1)
   go str 0
   return ptr
 #endif
@@ -278,8 +276,8 @@ newCAStringLen str  = do
 newCAStringLen str = do
   ptr <- mallocArray0 len
   let
-       go [] n     = n `seq` return () -- make it strict in n
-       go (c:cs) n = do pokeElemOff ptr n (castCharToCChar c); go cs (n+1)
+        go [] n     = n `seq` return () -- make it strict in n
+        go (c:cs) n = do pokeElemOff ptr n (castCharToCChar c); go cs (n+1)
   go str 0
   return (ptr, len)
   where
@@ -302,17 +300,15 @@ withCAString  = withArray0 nUL . charsToCChars
 withCAString str f =
   allocaArray0 (length str) $ \ptr ->
       let
-       go [] n     = pokeElemOff ptr n nUL
-       go (c:cs) n = do pokeElemOff ptr n (castCharToCChar c); go cs (n+1)
+        go [] n     = pokeElemOff ptr n nUL
+        go (c:cs) n = do pokeElemOff ptr n (castCharToCChar c); go cs (n+1)
       in do
       go str 0
       f ptr
 #endif
 
--- | Marshal a Haskell string into a NUL terminated C string using temporary
--- storage.
---
--- * the Haskell string may /not/ contain any NUL characters
+-- | Marshal a Haskell string into a 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
@@ -325,8 +321,8 @@ withCAStringLen str act  = withArray (charsToCChars str) $ act . pairLength str
 withCAStringLen str f =
   allocaArray len $ \ptr ->
       let
-       go [] n     = n `seq` return () -- make it strict in n
-       go (c:cs) n = do pokeElemOff ptr n (castCharToCChar c); go cs (n+1)
+        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
       go str 0
       f (ptr,len)
@@ -369,7 +365,7 @@ charsToCChars xs  = map castCharToCChar xs
 -- terminated by NUL.
 type CWString    = Ptr CWchar
 
--- | A wide character string with explicit length information in bytes
+-- | A wide character string with explicit length information in 'CWchar's
 -- instead of a terminating NUL (allowing NUL characters in the middle
 -- of the string).
 type CWStringLen = (Ptr CWchar, Int)
@@ -444,7 +440,7 @@ wNUL = 0
 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.
 
@@ -465,7 +461,7 @@ charsToCWchars = foldr utf16Char [] . map ord
                     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
@@ -479,4 +475,4 @@ castCWcharToChar ch = chr (fromIntegral ch )
 castCharToCWchar :: Char -> CWchar
 castCharToCWchar ch = fromIntegral (ord ch)
 
-#endif /* !mingw32_TARGET_OS */
+#endif /* !mingw32_HOST_OS */