X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Flib%2Fstd%2FPrelCString.lhs;h=4fe13fd5cf6e97180a4ff84bdd95e9b0cbf5d60b;hb=d9af408e5c512501cfa991f5e4a76c9154bca917;hp=2413e30c96aa5103fce5b19e948813a362837bb4;hpb=5f6f90850d5c82dc56d13bbc035d635e1cb2106b;p=ghc-hetmet.git diff --git a/ghc/lib/std/PrelCString.lhs b/ghc/lib/std/PrelCString.lhs index 2413e30..4fe13fd 100644 --- a/ghc/lib/std/PrelCString.lhs +++ b/ghc/lib/std/PrelCString.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: PrelCString.lhs,v 1.3 2001/04/14 22:28:46 qrczak Exp $ +% $Id: PrelCString.lhs,v 1.4 2001/05/18 16:54:05 simonmar Exp $ % % (c) The FFI task force, 2000 % @@ -7,10 +7,11 @@ Utilities for primitive marshaling \begin{code} -module PrelCString where +{-# OPTIONS -fno-implicit-prelude #-} -import Monad +module PrelCString where +#ifdef __GLASGOW_HASKELL__ import PrelMarshalArray import PrelPtr import PrelStorable @@ -18,10 +19,11 @@ import PrelCTypes import PrelWord import PrelByteArr import PrelPack +import PrelList +import PrelReal +import PrelNum +import PrelIOBase import PrelBase - -#ifdef __GLASGOW_HASKELL__ -import PrelIOBase hiding (malloc, _malloc) #endif ----------------------------------------------------------------------------- @@ -49,12 +51,12 @@ type CStringLen = (CString, Int) -- strings with explicit length -- marshal a NUL terminated C string into a Haskell string -- peekCString :: CString -> IO String -peekCString cp = liftM cCharsToChars $ peekArray0 nUL cp +peekCString cp = do cs <- peekArray0 nUL cp; return (cCharsToChars cs) -- marshal a C string with explicit length into a Haskell string -- peekCStringLen :: CStringLen -> IO String -peekCStringLen (cp, len) = liftM cCharsToChars $ peekArray len cp +peekCStringLen (cp, len) = do cs <- peekArray len cp; return (cCharsToChars cs) -- marshal a Haskell string into a NUL terminated C strings -- @@ -71,7 +73,8 @@ newCString = newArray0 nUL . charsToCChars -- * new storage is allocated for the C string and must be explicitly freed -- newCStringLen :: String -> IO CStringLen -newCStringLen str = liftM (pairLength str) $ newArray (charsToCChars str) +newCStringLen str = do a <- newArray (charsToCChars str) + return (pairLength str a) -- marshal a Haskell string into a NUL terminated C strings using temporary -- storage