2 {-# OPTIONS -fno-implicit-prelude #-}
3 -----------------------------------------------------------------------------
6 -- Copyright : (c) The FFI Task Force, 2000-2002
7 -- License : see libraries/base/LICENSE
9 -- Maintainer : ffi@haskell.org
10 -- Stability : internal
11 -- Portability : non-portable (GHC Extensions)
13 -- The 'Ptr' and 'FunPtr' types and operations.
15 -----------------------------------------------------------------------------
21 ------------------------------------------------------------------------
24 data Ptr a = Ptr Addr# deriving (Eq, Ord)
27 nullPtr = Ptr nullAddr#
29 castPtr :: Ptr a -> Ptr b
30 castPtr (Ptr addr) = Ptr addr
32 plusPtr :: Ptr a -> Int -> Ptr b
33 plusPtr (Ptr addr) (I# d) = Ptr (plusAddr# addr d)
35 alignPtr :: Ptr a -> Int -> Ptr a
36 alignPtr addr@(Ptr a) (I# i)
37 = case remAddr# a i of {
39 n -> Ptr (plusAddr# a (i -# n)) }
41 minusPtr :: Ptr a -> Ptr b -> Int
42 minusPtr (Ptr a1) (Ptr a2) = I# (minusAddr# a1 a2)
44 instance CCallable (Ptr a)
45 instance CReturnable (Ptr a)
47 ------------------------------------------------------------------------
48 -- Function pointers for the default calling convention.
50 data FunPtr a = FunPtr Addr# deriving (Eq, Ord)
52 nullFunPtr :: FunPtr a
53 nullFunPtr = FunPtr nullAddr#
55 castFunPtr :: FunPtr a -> FunPtr b
56 castFunPtr (FunPtr addr) = FunPtr addr
58 castFunPtrToPtr :: FunPtr a -> Ptr b
59 castFunPtrToPtr (FunPtr addr) = Ptr addr
61 castPtrToFunPtr :: Ptr a -> FunPtr b
62 castPtrToFunPtr (Ptr addr) = FunPtr addr
64 instance CCallable (FunPtr a)
65 instance CReturnable (FunPtr a)