X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=Foreign%2FPtr.hs;h=26dda5c23763fab24ae43e57b127a23b810da6ee;hb=3a7e8de77666fab3f6d2a7fc5c813cbca77ad57d;hp=6467c3826bb825c50c9b89b4ee748db114c36401;hpb=8c64e0dda4c143ae0bf0b0476bfbd2b58c8416dc;p=ghc-base.git diff --git a/Foreign/Ptr.hs b/Foreign/Ptr.hs index 6467c38..26dda5c 100644 --- a/Foreign/Ptr.hs +++ b/Foreign/Ptr.hs @@ -1,4 +1,13 @@ -{-# OPTIONS_GHC -fno-implicit-prelude #-} +{-# LANGUAGE CPP + , NoImplicitPrelude + , ForeignFunctionInterface + , MagicHash + , GeneralizedNewtypeDeriving + #-} +#ifdef __GLASGOW_HASKELL__ +{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-} +#endif + ----------------------------------------------------------------------------- -- | -- Module : Foreign.Ptr @@ -18,22 +27,22 @@ module Foreign.Ptr ( -- * Data pointers - + Ptr, -- data Ptr a nullPtr, -- :: Ptr a castPtr, -- :: Ptr a -> Ptr b plusPtr, -- :: Ptr a -> Int -> Ptr b alignPtr, -- :: Ptr a -> Int -> Ptr a minusPtr, -- :: Ptr a -> Ptr b -> Int - + -- * Function pointers - + FunPtr, -- data FunPtr a nullFunPtr, -- :: FunPtr a castFunPtr, -- :: FunPtr a -> FunPtr b castFunPtrToPtr, -- :: FunPtr a -> Ptr b castPtrToFunPtr, -- :: Ptr a -> FunPtr b - + freeHaskellFunPtr, -- :: FunPtr a -> IO () -- Free the function pointer created by foreign export dynamic. @@ -50,24 +59,23 @@ module Foreign.Ptr ( #ifdef __GLASGOW_HASKELL__ import GHC.Ptr -import GHC.IOBase import GHC.Base import GHC.Num import GHC.Read import GHC.Real import GHC.Show import GHC.Enum -import GHC.Word ( Word(..) ) +import GHC.Word ( Word(..) ) -import Data.Int +-- import Data.Int import Data.Word #else +import Control.Monad ( liftM ) import Foreign.C.Types #endif -import Control.Monad ( liftM ) import Data.Bits -import Data.Typeable ( Typeable(..), mkTyCon, mkTyConApp ) +import Data.Typeable import Foreign.Storable ( Storable(..) ) #ifdef __NHC__ @@ -106,14 +114,16 @@ foreign import ccall unsafe "freeHaskellFunctionPtr" # ifdef __GLASGOW_HASKELL__ -- | An unsigned integral type that can be losslessly converted to and from --- @Ptr@. +-- @Ptr@. This type is also compatible with the C99 type @uintptr_t@, and +-- can be marshalled to and from that type safely. INTEGRAL_TYPE(WordPtr,tyConWordPtr,"WordPtr",Word) - -- Word and Int are guaranteed pointer-sized in GHC + -- Word and Int are guaranteed pointer-sized in GHC -- | A signed integral type that can be losslessly converted to and from --- @Ptr@. +-- @Ptr@. This type is also compatible with the C99 type @intptr_t@, and +-- can be marshalled to and from that type safely. INTEGRAL_TYPE(IntPtr,tyConIntPtr,"IntPtr",Int) - -- Word and Int are guaranteed pointer-sized in GHC + -- Word and Int are guaranteed pointer-sized in GHC -- | casts a @Ptr@ to a @WordPtr@ ptrToWordPtr :: Ptr a -> WordPtr