[project @ 2002-10-11 11:05:20 by malcolm]
[ghc-base.git] / Foreign / Marshal / Utils.hs
index 87881b6..06528b2 100644 (file)
@@ -3,7 +3,7 @@
 -- |
 -- Module      :  Foreign.Marshal.Utils
 -- Copyright   :  (c) The FFI task force 2001
--- License     :  BSD-style (see the file libraries/core/LICENSE)
+-- License     :  BSD-style (see the file libraries/base/LICENSE)
 -- 
 -- Maintainer  :  ffi@haskell.org
 -- Stability   :  provisional
@@ -18,8 +18,7 @@ module Foreign.Marshal.Utils (
 
   -- ** Combined allocation and marshalling
   --
-  withObject,    -- :: Storable a => a -> (Ptr a -> IO b) -> IO b
-  {- FIXME: should be `with' -}
+  with,          -- :: Storable a => a -> (Ptr a -> IO b) -> IO b
   new,           -- :: Storable a => a -> IO (Ptr a)
 
   -- ** Marshalling of Boolean values (non-zero corresponds to 'True')
@@ -41,19 +40,23 @@ module Foreign.Marshal.Utils (
   withMany,      -- :: (a -> (b -> res) -> res) -> [a] -> ([b] -> res) -> res
 
   -- ** Haskellish interface to memcpy and memmove
-
   -- | (argument order: destination, source)
+  --
   copyBytes,     -- :: Ptr a -> Ptr a -> Int -> IO ()
-  moveBytes      -- :: Ptr a -> Ptr a -> Int -> IO ()
+  moveBytes,     -- :: Ptr a -> Ptr a -> Int -> IO ()
+
+  -- ** DEPRECATED FUNCTIONS (don\'t use; they may disappear at any time)
+  --
+  withObject     -- :: Storable a => a -> (Ptr a -> IO b) -> IO b
 ) where
 
 import Data.Maybe
-
-#ifdef __GLASGOW_HASKELL__
 import Foreign.Ptr             ( Ptr, nullPtr )
-import GHC.Storable            ( Storable(poke) )
-import Foreign.C.TypesISO      ( CSize )
+import Foreign.Storable                ( Storable(poke) )
+import Foreign.C.Types         ( CSize, CInt(..) )
 import Foreign.Marshal.Alloc   ( malloc, alloca )
+
+#ifdef __GLASGOW_HASKELL__
 import GHC.IOBase
 import GHC.Real                        ( fromIntegral )
 import GHC.Num
@@ -76,14 +79,19 @@ new val  =
 --
 -- * see the life time constraints imposed by 'alloca'
 --
-{- FIXME: should be called `with' -}
-withObject       :: Storable a => a -> (Ptr a -> IO b) -> IO b
-withObject val f  =
+with       :: Storable a => a -> (Ptr a -> IO b) -> IO b
+with val f  =
   alloca $ \ptr -> do
     poke ptr val
     res <- f ptr
     return res
 
+-- old DEPRECATED name (don't use; may disappear at any time)
+--
+withObject :: Storable a => a -> (Ptr a -> IO b) -> IO b
+{-# DEPRECATED withObject "use `with' instead" #-}
+withObject  = with
+
 
 -- marshalling of Boolean values (non-zero corresponds to 'True')
 -- -----------------------------
@@ -162,5 +170,5 @@ moveBytes dest src size  = memmove dest src (fromIntegral size)
 
 -- |Basic C routines needed for memory copying
 --
-foreign import ccall unsafe memcpy  :: Ptr a -> Ptr a -> CSize -> IO ()
-foreign import ccall unsafe memmove :: Ptr a -> Ptr a -> CSize -> IO ()
+foreign import ccall unsafe "string.h" memcpy  :: Ptr a -> Ptr a -> CSize -> IO ()
+foreign import ccall unsafe "string.h" memmove :: Ptr a -> Ptr a -> CSize -> IO ()