{-# OPTIONS -fno-implicit-prelude #-}
-----------------------------------------------------------------------------
---
+-- |
-- Module : Foreign.C.String
-- Copyright : (c) The FFI task force 2001
-- License : BSD-style (see the file libraries/core/LICENSE)
-- Stability : provisional
-- Portability : portable
--
--- $Id: String.hs,v 1.2 2001/07/03 11:37:50 simonmar Exp $
---
-- Utilities for primitive marshaling
--
-----------------------------------------------------------------------------
castCharToCChar, -- :: Char -> CChar
castCCharToChar, -- :: CChar -> Char
- -- UnsafeCString: these might be more efficient than CStrings when
- -- passing the string to an "unsafe" foreign import. NOTE: this
- -- feature might be removed in favour of a more general approach in
- -- the future.
- --
- UnsafeCString, -- abstract
- withUnsafeCString, -- :: String -> (UnsafeCString -> IO a) -> IO a
-
) where
import Foreign.Marshal.Array
import Data.Word
#ifdef __GLASGOW_HASKELL__
-import GHC.ByteArr
-import GHC.Pack
import GHC.List
import GHC.Real
import GHC.Num
castCharToCChar :: Char -> CChar
castCharToCChar ch = fromIntegral (ord ch)
-
-
--- unsafe CStrings
--- ---------------
-
-withUnsafeCString :: String -> (UnsafeCString -> IO a) -> IO a
-#if __GLASGOW_HASKELL__
-newtype UnsafeCString = UnsafeCString (ByteArray Int)
-withUnsafeCString s f = f (UnsafeCString (packString s))
-#else
-newtype UnsafeCString = UnsafeCString (Ptr CChar)
-withUnsafeCString s f = withCString s (\p -> f (UnsafeCString p))
-#endif