From: simonmar Date: Wed, 6 Nov 2002 10:38:16 +0000 (+0000) Subject: [project @ 2002-11-06 10:38:16 by simonmar] X-Git-Tag: nhc98-1-18-release~803 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=d2935733119306e78099dafa050fce619ce75841;p=haskell-directory.git [project @ 2002-11-06 10:38:16 by simonmar] - Add a Show instance for ForeignPtr - Fix the Eq instance for ForeignPtr to match the behaviour specified by the spec. Two ForeignPtrs are equal iff their underlying Ptrs are equal (previously they were equal iff they were the same ForeignPtr). MERGE TO STABLE --- diff --git a/Foreign/ForeignPtr.hs b/Foreign/ForeignPtr.hs index b0dd4d5..09958dc 100644 --- a/Foreign/ForeignPtr.hs +++ b/Foreign/ForeignPtr.hs @@ -44,6 +44,7 @@ import GHC.IOBase import GHC.Num import GHC.Ptr ( Ptr(..) ) import GHC.Err +import GHC.Show #endif #ifdef __NHC__ @@ -82,13 +83,12 @@ data ForeignPtr a = ForeignPtr ForeignObj# | MallocPtr (MutableByteArray# RealWorld) -eqForeignPtr :: ForeignPtr a -> ForeignPtr a -> Bool -eqForeignPtr (ForeignPtr fo1#) (ForeignPtr fo2#) = eqForeignObj# fo1# fo2# -eqForeignPtr (MallocPtr fo1#) (MallocPtr fo2#) = sameMutableByteArray# fo1# fo2# -eqForeignPtr _ _ = False - instance Eq (ForeignPtr a) where - p == q = eqForeignPtr p q + p == q = foreignPtrToPtr p == foreignPtrToPtr q + +instance Show (ForeignPtr a) where + showsPrec p f = showsPrec p (foreignPtrToPtr f) + newForeignPtr :: Ptr a -> IO () -> IO (ForeignPtr a) -- ^Turns a plain memory reference into a foreign object