1 {-# OPTIONS -fno-implicit-prelude #-}
2 -----------------------------------------------------------------------------
4 -- Module : Foreign.Ptr
5 -- Copyright : (c) The FFI task force 2001
6 -- License : BSD-style (see the file libraries/base/LICENSE)
8 -- Maintainer : ffi@haskell.org
9 -- Stability : provisional
10 -- Portability : portable
12 -- The "Ptr" module provides typed pointers to foreign data. It is part
13 -- of the Foreign Function Interface (FFI) and will normally be
14 -- imported via the "Foreign" module.
16 -----------------------------------------------------------------------------
24 castPtr, -- :: Ptr a -> Ptr b
25 plusPtr, -- :: Ptr a -> Int -> Ptr b
26 alignPtr, -- :: Ptr a -> Int -> Ptr a
27 minusPtr, -- :: Ptr a -> Ptr b -> Int
29 -- * Function pointers
31 FunPtr, -- data FunPtr a
32 nullFunPtr, -- :: FunPtr a
33 castFunPtr, -- :: FunPtr a -> FunPtr b
34 castFunPtrToPtr, -- :: FunPtr a -> Ptr b
35 castPtrToFunPtr, -- :: Ptr a -> FunPtr b
37 freeHaskellFunPtr, -- :: FunPtr a -> IO ()
38 -- Free the function pointer created by foreign export dynamic.
42 #ifdef __GLASGOW_HASKELL__
55 #ifdef __GLASGOW_HASKELL__
56 #if (WORD_SIZE_IN_BITS == 32 || WORD_SIZE_IN_BITS == 64)
57 instance Show (Ptr a) where
58 showsPrec p (Ptr a) rs = pad_out (showHex (word2Integer(int2Word#(addr2Int# a))) "") rs
60 -- want 0s prefixed to pad it out to a fixed length.
61 pad_out ('0':'x':ls) rs =
62 '0':'x':(replicate (2*SIZEOF_HSPTR - length ls) '0') ++ ls ++ rs
63 -- word2Integer :: Word# -> Integer (stolen from Word.lhs)
64 word2Integer w = case word2Integer# w of
67 instance Show (FunPtr a) where
68 showsPrec p = showsPrec p . castFunPtrToPtr
72 foreign import ccall unsafe "freeHaskellFunctionPtr"
73 freeHaskellFunPtr :: FunPtr a -> IO ()