module Foreign (
module Foreign,
- Addr, Word
+#ifndef __PARALLEL_HASKELL__
+ ForeignObj(..),
+#endif
+ Addr(..), Word(..)
) where
import STBase
-import ArrBase
+import UnsafeST ( unsafePerformPrimIO )
import PrelBase
import GHC
\end{code}
instance CCallable Double#
instance CReturnable Double
+data Addr = A# Addr# deriving (Eq, Ord) -- Glasgow extension
+
instance CCallable Addr
instance CCallable Addr#
instance CReturnable Addr
+data Word = W# Word# deriving (Eq, Ord) -- Glasgow extension
+
instance CCallable Word
instance CCallable Word#
instance CReturnable Word
--- Is this right?
-instance CCallable (MutableByteArray s ix)
-instance CCallable (MutableByteArray# s)
-
-instance CCallable (ByteArray ix)
-instance CCallable ByteArray#
-
instance CReturnable () -- Why, exactly?
\end{code}
%*********************************************************
\begin{code}
-data ForeignObj = ForeignObj ForeignObj#
+#ifndef __PARALLEL_HASKELL__
+--Defined in PrelBase: data ForeignObj = ForeignObj ForeignObj#
+data ForeignObj = ForeignObj ForeignObj# -- another one
+
instance CCallable ForeignObj
instance CCallable ForeignObj#
-eqForeignObj :: ForeignObj -> ForeignObj -> Bool
-makeForeignObj :: Addr -> Addr -> PrimIO ForeignObj
+eqForeignObj :: ForeignObj -> ForeignObj -> Bool
+makeForeignObj :: Addr -> Addr -> PrimIO ForeignObj
+writeForeignObj :: ForeignObj -> Addr -> PrimIO ()
+
+{- derived op - attaching a free() finaliser to a malloc() allocated reference. -}
+makeMallocPtr :: Addr -> PrimIO ForeignObj
-makeForeignObj (A# obj) (A# finaliser) = ST $ \ (S# s#) ->
+makeForeignObj (A# obj) (A# finaliser) = ST ( \ (S# s#) ->
case makeForeignObj# obj finaliser s# of
- StateAndForeignObj# s1# fo# -> (ForeignObj fo#, S# s1#)
+ StateAndForeignObj# s1# fo# -> (ForeignObj fo#, S# s1#))
+
+writeForeignObj (ForeignObj fo#) (A# datum#) = ST ( \ (S# s#) ->
+ case writeForeignObj# fo# datum# s# of { s1# -> ((), S# s1#) } )
+
+makeMallocPtr a = makeForeignObj a (``&free''::Addr)
eqForeignObj mp1 mp2
= unsafePerformPrimIO (_ccall_ eqForeignObj mp1 mp2) /= (0::Int)
instance Eq ForeignObj where
p == q = eqForeignObj p q
p /= q = not (eqForeignObj p q)
+#endif /* !__PARALLEL_HASKELL__ */
\end{code}