[project @ 2005-01-11 16:04:08 by simonmar]
[ghc-base.git] / Foreign / C / String.hs
index 720330c..03826dd 100644 (file)
@@ -1,4 +1,4 @@
-{-# OPTIONS -fno-implicit-prelude #-}
+{-# OPTIONS_GHC -fno-implicit-prelude #-}
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Foreign.C.String
@@ -278,10 +278,12 @@ newCAStringLen str  = do
 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
@@ -323,11 +325,13 @@ withCAStringLen str act  = withArray (charsToCChars str) $ act . pairLength str
 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