-{-# OPTIONS -fno-implicit-prelude #-}
+{-# OPTIONS_GHC -XNoImplicitPrelude #-}
--------------------------------------------------------------------------------
-- |
-- Module : Foreign.Marshal.Pool
--- Copyright : (c) Sven Panne 2003
+-- Copyright : (c) Sven Panne 2002-2004
-- License : BSD-style (see the file libraries/base/LICENSE)
--
--- Maintainer : sven_panne@yahoo.com
+-- Maintainer : sven.panne@aedion.de
-- Stability : provisional
-- Portability : portable
--
pooledNewArray0 -- :: Storable a => Pool -> a -> [a] -> IO (Ptr a)
) where
-#if defined(__NHC__)
-import IO ( bracket )
-#elif defined(__HUGS__)
-import Control.Exception ( bracket )
-#endif
-
#ifdef __GLASGOW_HASKELL__
-import GHC.Base ( Int, Monad(..), (.), not, map )
+import GHC.Base ( Int, Monad(..), (.), not )
import GHC.Err ( undefined )
import GHC.Exception ( block, unblock, throw, catchException )
import GHC.IOBase ( IO, IORef, newIORef, readIORef, writeIORef, )
import GHC.List ( elem, length )
import GHC.Num ( Num(..) )
#else
-import Data.IORef ( IORef, newIORef, readIORef, modifyIORef )
+import Data.IORef ( IORef, newIORef, readIORef, writeIORef )
+#if defined(__NHC__)
+import IO ( bracket )
+#else
+import Control.Exception ( bracket )
+#endif
#endif
import Control.Monad ( liftM )
-- deallocated (including its contents) after the action has finished.
withPool :: (Pool -> IO b) -> IO b
+#ifdef __GLASGOW_HASKELL__
withPool act = -- ATTENTION: cut-n-paste from Control.Exception below!
block (do
pool <- newPool
(\e -> do freePool pool; throw e)
freePool pool
return val)
+#else
+withPool = bracket newPool freePool
+#endif
--------------------------------------------------------------------------------
pooledMalloc :: Storable a => Pool -> IO (Ptr a)
pooledMalloc = pm undefined
where
- pm :: Storable a => a -> Pool -> IO (Ptr a)
+ pm :: Storable a' => a' -> Pool -> IO (Ptr a')
pm dummy pool = pooledMallocBytes pool (sizeOf dummy)
-- | Allocate the given number of bytes of storage in the pool.
pooledRealloc :: Storable a => Pool -> Ptr a -> IO (Ptr a)
pooledRealloc = pr undefined
where
- pr :: Storable a => a -> Pool -> Ptr a -> IO (Ptr a)
+ pr :: Storable a' => a' -> Pool -> Ptr a' -> IO (Ptr a')
pr dummy pool ptr = pooledReallocBytes pool ptr (sizeOf dummy)
-- | Adjust the storage area for an element in the pool to the given size.
pooledMallocArray :: Storable a => Pool -> Int -> IO (Ptr a)
pooledMallocArray = pma undefined
where
- pma :: Storable a => a -> Pool -> Int -> IO (Ptr a)
+ pma :: Storable a' => a' -> Pool -> Int -> IO (Ptr a')
pma dummy pool size = pooledMallocBytes pool (size * sizeOf dummy)
-- | Allocate storage for the given number of elements of a storable type in the
pooledReallocArray :: Storable a => Pool -> Ptr a -> Int -> IO (Ptr a)
pooledReallocArray = pra undefined
where
- pra :: Storable a => a -> Pool -> Ptr a -> Int -> IO (Ptr a)
+ pra :: Storable a' => a' -> Pool -> Ptr a' -> Int -> IO (Ptr a')
pra dummy pool ptr size = pooledReallocBytes pool ptr (size * sizeOf dummy)
-- | Adjust the size of an array with an end marker in the given pool.