[project @ 2003-06-19 13:20:37 by simonmar]
authorsimonmar <unknown>
Thu, 19 Jun 2003 13:20:37 +0000 (13:20 +0000)
committersimonmar <unknown>
Thu, 19 Jun 2003 13:20:37 +0000 (13:20 +0000)
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

Foreign/Marshal/Alloc.hs

index 3cf7174..fb9f8dd 100644 (file)
@@ -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))