X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Foreign%2FMarshal%2FAlloc.hs;h=8a8946769f072ddcf69735747ede749dc514497b;hb=c01a362a8cf718ff2ed317846022a3e8fa26c420;hp=dbd3644a3d70abdc185d8890a33db70757f61395;hpb=0290e82d74f9aa9f0ae06f96fd71ff93ec91c602;p=ghc-base.git diff --git a/Foreign/Marshal/Alloc.hs b/Foreign/Marshal/Alloc.hs index dbd3644..8a89467 100644 --- a/Foreign/Marshal/Alloc.hs +++ b/Foreign/Marshal/Alloc.hs @@ -1,4 +1,4 @@ -{-# OPTIONS -fno-implicit-prelude #-} +{-# OPTIONS_GHC -fno-implicit-prelude #-} ----------------------------------------------------------------------------- -- | -- Module : Foreign.Marshal.Alloc @@ -51,6 +51,8 @@ import Control.Exception ( bracket ) #endif #ifdef __HUGS__ +import Hugs.Prelude ( IOException(IOError), + IOErrorType(ResourceExhausted) ) import Hugs.ForeignPtr ( FinalizerPtr ) #endif @@ -68,7 +70,7 @@ import Hugs.ForeignPtr ( FinalizerPtr ) malloc :: Storable a => IO (Ptr a) malloc = doMalloc undefined where - doMalloc :: Storable a => a -> IO (Ptr a) + doMalloc :: Storable b => b -> IO (Ptr b) doMalloc dummy = mallocBytes (sizeOf dummy) -- |Allocate a block of memory of the given number of bytes. @@ -91,7 +93,7 @@ mallocBytes size = failWhenNULL "malloc" (_malloc (fromIntegral size)) alloca :: Storable a => (Ptr a -> IO b) -> IO b alloca = doAlloca undefined where - doAlloca :: Storable a => a -> (Ptr a -> IO b) -> IO b + doAlloca :: Storable a' => a' -> (Ptr a' -> IO b') -> IO b' doAlloca dummy = allocaBytes (sizeOf dummy) -- |@'allocaBytes' n f@ executes the computation @f@, passing as argument @@ -131,7 +133,7 @@ allocaBytes size = bracket (mallocBytes size) free realloc :: Storable b => Ptr a -> IO (Ptr b) realloc = doRealloc undefined where - doRealloc :: Storable b => b -> Ptr a -> IO (Ptr b) + doRealloc :: Storable b' => b' -> Ptr a' -> IO (Ptr b') doRealloc dummy ptr = let size = fromIntegral (sizeOf dummy) in @@ -173,8 +175,8 @@ failWhenNULL :: String -> IO (Ptr a) -> IO (Ptr a) failWhenNULL name f = do addr <- f if addr == nullPtr -#ifdef __GLASGOW_HASKELL__ - then ioException (IOError Nothing ResourceExhausted name +#if __GLASGOW_HASKELL__ || __HUGS__ + then ioError (IOError Nothing ResourceExhausted name "out of memory" Nothing) #else then ioError (userError (name++": out of memory"))