2 {-# OPTIONS -fno-implicit-prelude #-}
3 -----------------------------------------------------------------------------
6 -- Copyright : (c) The University of Glasgow, 1992-2002
7 -- License : see libraries/base/LICENSE
9 -- Maintainer : ffi@haskell.org
10 -- Stability : internal
11 -- Portability : non-portable (GHC Extensions)
15 -----------------------------------------------------------------------------
19 , newStablePtr -- :: a -> IO (StablePtr a)
20 , deRefStablePtr -- :: StablePtr a -> a
21 , freeStablePtr -- :: StablePtr a -> IO ()
22 , castStablePtrToPtr -- :: StablePtr a -> Ptr ()
23 , castPtrToStablePtr -- :: Ptr () -> StablePtr a
30 -----------------------------------------------------------------------------
33 data StablePtr a = StablePtr (StablePtr# a)
35 instance CCallable (StablePtr a)
36 instance CReturnable (StablePtr a)
38 newStablePtr :: a -> IO (StablePtr a)
39 newStablePtr a = IO $ \ s ->
40 case makeStablePtr# a s of (# s', sp #) -> (# s', StablePtr sp #)
42 deRefStablePtr :: StablePtr a -> IO a
43 deRefStablePtr (StablePtr sp) = IO $ \s -> deRefStablePtr# sp s
45 foreign import ccall unsafe freeStablePtr :: StablePtr a -> IO ()
47 castStablePtrToPtr :: StablePtr a -> Ptr ()
48 castStablePtrToPtr (StablePtr s) = Ptr (unsafeCoerce# s)
50 castPtrToStablePtr :: Ptr () -> StablePtr a
51 castPtrToStablePtr (Ptr a) = StablePtr (unsafeCoerce# a)
53 instance Eq (StablePtr a) where
54 (StablePtr sp1) == (StablePtr sp2) =
55 case eqStablePtr# sp1 sp2 of