1 % -----------------------------------------------------------------------------
2 % $Id: Stable.lhs,v 1.3 2002/04/24 15:47:34 simonmar Exp $
4 % (c) The GHC Team, 1992-2000
7 \section{Module @GHC.Stable@}
10 {-# OPTIONS -fno-implicit-prelude #-}
14 , newStablePtr -- :: a -> IO (StablePtr a)
15 , deRefStablePtr -- :: StablePtr a -> a
16 , freeStablePtr -- :: StablePtr a -> IO ()
17 , castStablePtrToPtr -- :: StablePtr a -> Ptr ()
18 , castPtrToStablePtr -- :: Ptr () -> StablePtr a
25 -----------------------------------------------------------------------------
28 data StablePtr a = StablePtr (StablePtr# a)
30 instance CCallable (StablePtr a)
31 instance CReturnable (StablePtr a)
33 newStablePtr :: a -> IO (StablePtr a)
34 newStablePtr a = IO $ \ s ->
35 case makeStablePtr# a s of (# s', sp #) -> (# s', StablePtr sp #)
37 deRefStablePtr :: StablePtr a -> IO a
38 deRefStablePtr (StablePtr sp) = IO $ \s -> deRefStablePtr# sp s
40 foreign import ccall unsafe freeStablePtr :: StablePtr a -> IO ()
42 castStablePtrToPtr :: StablePtr a -> Ptr ()
43 castStablePtrToPtr (StablePtr s) = Ptr (unsafeCoerce# s)
45 castPtrToStablePtr :: Ptr () -> StablePtr a
46 castPtrToStablePtr (Ptr a) = StablePtr (unsafeCoerce# a)
48 instance Eq (StablePtr a) where
49 (StablePtr sp1) == (StablePtr sp2) =
50 case eqStablePtr# sp1 sp2 of