, 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__
)
#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.
= 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