[project @ 2001-07-13 15:03:00 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / PrelForeign.lhs
index 7b74828..cbaef2a 100644 (file)
@@ -1,5 +1,5 @@
 % ------------------------------------------------------------------------------
-% $Id: PrelForeign.lhs,v 1.17 2001/01/11 17:25:57 simonmar Exp $
+% $Id: PrelForeign.lhs,v 1.19 2001/05/18 16:54:05 simonmar Exp $
 %
 % (c) The University of Glasgow, 1994-2000
 %
@@ -12,6 +12,7 @@
 module PrelForeign where
 
 import PrelIOBase
+import PrelNum                 -- for fromInteger
 import PrelBase
 import PrelPtr
 \end{code}
@@ -23,7 +24,20 @@ import PrelPtr
 %*********************************************************
 
 \begin{code}
-#ifndef __PARALLEL_HASKELL__
+data ForeignPtr a = ForeignPtr ForeignObj#
+instance CCallable (ForeignPtr a)
+
+eqForeignPtr :: ForeignPtr a -> ForeignPtr a -> Bool
+eqForeignPtr mp1 mp2
+  = unsafePerformIO (primEqForeignPtr mp1 mp2) /= (0::Int)
+
+foreign import "eqForeignObj" unsafe 
+  primEqForeignPtr :: ForeignPtr a -> ForeignPtr a -> IO Int
+
+instance Eq (ForeignPtr a) where 
+    p == q = eqForeignPtr p q
+    p /= q = not (eqForeignPtr p q)
+
 newForeignPtr :: Ptr a -> IO () -> IO (ForeignPtr a)
 newForeignPtr p finalizer
   = do fObj <- mkForeignPtr p
@@ -53,7 +67,7 @@ foreignPtrToPtr :: ForeignPtr a -> Ptr a
 foreignPtrToPtr (ForeignPtr fo) = Ptr (foreignObjToAddr# fo)
 
 castForeignPtr (ForeignPtr a) = ForeignPtr a
-#endif
+
 \end{code}