[project @ 2003-01-21 16:33:20 by ross]
[ghc-base.git] / Foreign / ForeignPtr.hs
index b0dd4d5..3b37c6d 100644 (file)
@@ -26,24 +26,26 @@ module Foreign.ForeignPtr
        , touchForeignPtr        -- :: ForeignPtr a -> IO ()
        , castForeignPtr         -- :: ForeignPtr a -> ForeignPtr b
 
-#ifdef __GLASGOW_HASKELL__
-       -- * GHC extensions
+#ifndef __NHC__
        , mallocForeignPtr      --  :: Storable a => IO (ForeignPtr a)
        , mallocForeignPtrBytes --  :: Int -> IO (ForeignPtr a)
 #endif
         ) 
        where
 
-#ifdef __GLASGOW_HASKELL__
+#ifndef __NHC__
 import Foreign.Ptr
 import Foreign.Storable
 import Data.Dynamic
+#endif
 
+#ifdef __GLASGOW_HASKELL__
 import GHC.Base
 import GHC.IOBase
 import GHC.Num
 import GHC.Ptr ( Ptr(..) )
 import GHC.Err
+import GHC.Show
 #endif
 
 #ifdef __NHC__
@@ -58,10 +60,16 @@ import NHC.FFI
   )
 #endif
 
-#ifdef __GLASGOW_HASKELL__
+#ifdef __HUGS__
+import Hugs.ForeignPtr
+#endif
+
+#ifndef __NHC__
 #include "Dynamic.h"
 INSTANCE_TYPEABLE1(ForeignPtr,foreignPtrTc,"ForeignPtr")
+#endif
 
+#ifdef __GLASGOW_HASKELL__
 -- |The type 'ForeignPtr' represents references to objects that are
 -- maintained in a foreign language, i.e., that are not part of the
 -- data structures usually managed by the Haskell storage manager.
@@ -82,13 +90,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