X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Foreign%2FMarshal%2FPool.hs;h=4f3364cab980ee2de1c4b5b257b25345d2ad5d9d;hb=68f60ec9d6004e36d572bc3b2d38b25a16530706;hp=2b0664fba5ba4a3e21ce599c3350f805589161b8;hpb=6075d5f981bbe94387a8322de1b516968dcc000b;p=ghc-base.git diff --git a/Foreign/Marshal/Pool.hs b/Foreign/Marshal/Pool.hs index 2b0664f..4f3364c 100644 --- a/Foreign/Marshal/Pool.hs +++ b/Foreign/Marshal/Pool.hs @@ -44,12 +44,6 @@ module Foreign.Marshal.Pool ( 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.Err ( undefined ) @@ -58,7 +52,12 @@ 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 ) @@ -95,6 +94,7 @@ freePool (Pool pool) = readIORef pool >>= freeAll -- 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 @@ -103,6 +103,9 @@ withPool act = -- ATTENTION: cut-n-paste from Control.Exception below! (\e -> do freePool pool; throw e) freePool pool return val) +#else +withPool = bracket newPool freePool +#endif --------------------------------------------------------------------------------