X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Foreign%2FMarshal%2FPool.hs;h=f15d048a9518b13a2cdb2f0f82d311a993e47f5a;hb=4c29f6f110d23b890567b8696a964bb212eba52e;hp=4f3364cab980ee2de1c4b5b257b25345d2ad5d9d;hpb=f6eda67e5db767fdaa5b645401718262aa5ad56d;p=ghc-base.git diff --git a/Foreign/Marshal/Pool.hs b/Foreign/Marshal/Pool.hs index 4f3364c..f15d048 100644 --- a/Foreign/Marshal/Pool.hs +++ b/Foreign/Marshal/Pool.hs @@ -1,11 +1,11 @@ -{-# 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 -- @@ -45,10 +45,11 @@ module Foreign.Marshal.Pool ( ) where #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.Exception ( throw ) +import GHC.IO ( IO, mask, catchAny ) +import GHC.IORef ( IORef, newIORef, readIORef, writeIORef ) import GHC.List ( elem, length ) import GHC.Num ( Num(..) ) #else @@ -56,7 +57,7 @@ import Data.IORef ( IORef, newIORef, readIORef, writeIORef ) #if defined(__NHC__) import IO ( bracket ) #else -import Control.Exception ( bracket ) +import Control.Exception.Base ( bracket ) #endif #endif @@ -96,10 +97,10 @@ freePool (Pool pool) = readIORef pool >>= freeAll withPool :: (Pool -> IO b) -> IO b #ifdef __GLASGOW_HASKELL__ withPool act = -- ATTENTION: cut-n-paste from Control.Exception below! - block (do + mask (\restore -> do pool <- newPool - val <- catchException - (unblock (act pool)) + val <- catchAny + (restore (act pool)) (\e -> do freePool pool; throw e) freePool pool return val) @@ -116,7 +117,7 @@ withPool = bracket newPool freePool 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. @@ -134,7 +135,7 @@ pooledMallocBytes (Pool pool) size = do 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. @@ -142,7 +143,7 @@ pooledRealloc = pr undefined pooledReallocBytes :: Pool -> Ptr a -> Int -> IO (Ptr a) pooledReallocBytes (Pool pool) ptr size = do let cPtr = castPtr ptr - throwIf (not . (cPtr `elem`)) (\_ -> "pointer not in pool") (readIORef pool) + _ <- throwIf (not . (cPtr `elem`)) (\_ -> "pointer not in pool") (readIORef pool) newPtr <- reallocBytes cPtr size ptrs <- readIORef pool writeIORef pool (newPtr : delete cPtr ptrs) @@ -154,7 +155,7 @@ pooledReallocBytes (Pool pool) ptr size = do 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 @@ -169,7 +170,7 @@ pooledMallocArray0 pool size = 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.