From: simonmar Date: Thu, 19 Jun 2003 13:20:37 +0000 (+0000) Subject: [project @ 2003-06-19 13:20:37 by simonmar] X-Git-Tag: nhc98-1-18-release~603 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=637cb074a8f0e250abec208184248db2ce29222f;p=haskell-directory.git [project @ 2003-06-19 13:20:37 by simonmar] Fix reallocBytes: when size is zero, it is supposed to act like free. Which it did, except that we were complaining about the NULL return value from C's realloc and reporting it as an error. MERGE TO STABLE --- diff --git a/Foreign/Marshal/Alloc.hs b/Foreign/Marshal/Alloc.hs index 3cf7174..fb9f8dd 100644 --- a/Foreign/Marshal/Alloc.hs +++ b/Foreign/Marshal/Alloc.hs @@ -40,6 +40,7 @@ import GHC.Real import GHC.Ptr import GHC.Err import GHC.Base +import GHC.Num #elif defined(__NHC__) import NHC.FFI ( FinalizerPtr, CInt(..) ) import IO ( bracket ) @@ -120,6 +121,7 @@ realloc = doRealloc undefined -- C\'s @realloc()@). -- reallocBytes :: Ptr a -> Int -> IO (Ptr a) +reallocBytes ptr 0 = do free ptr; return nullPtr reallocBytes ptr size = failWhenNULL "realloc" (_realloc ptr (fromIntegral size))