[project @ 2002-10-11 11:05:20 by malcolm]
[packages/base.git] / Foreign / StablePtr.hs
1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module : Foreign.StablePtr
5 -- Copyright : (c) The University of Glasgow 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
7 --
8 -- Maintainer : ffi@haskell.org
9 -- Stability : provisional
10 -- Portability : portable
11 --
12 -- This module is part of the Foreign Function Interface (FFI) and will usually
13 -- be imported via the module "Foreign".
14 --
15 -----------------------------------------------------------------------------
16
17
18 module Foreign.StablePtr
19 ( -- * Stable references to Haskell values
20 StablePtr -- abstract
21 , newStablePtr -- :: a -> IO (StablePtr a)
22 , deRefStablePtr -- :: StablePtr a -> IO a
23 , freeStablePtr -- :: StablePtr a -> IO ()
24 , castStablePtrToPtr -- :: StablePtr a -> Ptr ()
25 , castPtrToStablePtr -- :: Ptr () -> StablePtr a
26 , -- ** The C-side interface
27
28 -- $cinterface
29 ) where
30
31 #ifdef __GLASGOW_HASKELL__
32 import GHC.Stable
33 import GHC.Err
34 #endif
35
36 #ifdef __HUGS__
37 import Hugs.StablePtr
38 #endif
39
40 #ifdef __NHC__
41 import NHC.FFI
42 ( StablePtr
43 , newStablePtr
44 , deRefStablePtr
45 , freeStablePtr
46 , castStablePtrToPtr
47 , castPtrToStablePtr
48 )
49 #endif
50
51 -- $cinterface
52 --
53 -- The following definition is available to C programs inter-operating with
54 -- Haskell code when including the header @HsFFI.h@.
55 --
56 -- > typedef void *HsStablePtr; /* C representation of a StablePtr */
57 --
58 -- Note that no assumptions may be made about the values representing stable
59 -- pointers. In fact, they need not even be valid memory addresses. The only
60 -- guarantee provided is that if they are passed back to Haskell land, the
61 -- function 'deRefStablePtr' will be able to reconstruct the
62 -- Haskell value refereed to by the stable pointer.