module Foreign.Ptr (
Ptr,
nullPtr,
castPtr,
plusPtr,
alignPtr,
minusPtr,
FunPtr,
nullFunPtr,
castFunPtr,
castFunPtrToPtr,
castPtrToFunPtr,
freeHaskellFunPtr,
#ifndef __NHC__
IntPtr,
ptrToIntPtr,
intPtrToPtr,
WordPtr,
ptrToWordPtr,
wordPtrToPtr
#endif
) where
#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 Data.Int
import Data.Word
#else
import Control.Monad ( liftM )
import Foreign.C.Types
#endif
import Data.Bits
import Data.Typeable
import Foreign.Storable ( Storable(..) )
#ifdef __NHC__
import NHC.FFI
( Ptr
, nullPtr
, castPtr
, plusPtr
, alignPtr
, minusPtr
, FunPtr
, nullFunPtr
, castFunPtr
, castFunPtrToPtr
, castPtrToFunPtr
, freeHaskellFunPtr
)
#endif
#ifdef __HUGS__
import Hugs.Ptr
#endif
#ifdef __GLASGOW_HASKELL__
foreign import ccall unsafe "freeHaskellFunctionPtr"
freeHaskellFunPtr :: FunPtr a -> IO ()
#endif
#ifndef __NHC__
# include "HsBaseConfig.h"
# include "CTypes.h"
# ifdef __GLASGOW_HASKELL__
INTEGRAL_TYPE(WordPtr,tyConWordPtr,"WordPtr",Word)
INTEGRAL_TYPE(IntPtr,tyConIntPtr,"IntPtr",Int)
ptrToWordPtr :: Ptr a -> WordPtr
ptrToWordPtr (Ptr a#) = WordPtr (W# (int2Word# (addr2Int# a#)))
wordPtrToPtr :: WordPtr -> Ptr a
wordPtrToPtr (WordPtr (W# w#)) = Ptr (int2Addr# (word2Int# w#))
ptrToIntPtr :: Ptr a -> IntPtr
ptrToIntPtr (Ptr a#) = IntPtr (I# (addr2Int# a#))
intPtrToPtr :: IntPtr -> Ptr a
intPtrToPtr (IntPtr (I# i#)) = Ptr (int2Addr# i#)
# else /* !__GLASGOW_HASKELL__ */
INTEGRAL_TYPE(WordPtr,tyConWordPtr,"WordPtr",CUIntPtr)
INTEGRAL_TYPE(IntPtr,tyConIntPtr,"IntPtr",CIntPtr)
foreign import ccall unsafe "__hscore_to_uintptr"
ptrToWordPtr :: Ptr a -> WordPtr
foreign import ccall unsafe "__hscore_from_uintptr"
wordPtrToPtr :: WordPtr -> Ptr a
foreign import ccall unsafe "__hscore_to_intptr"
ptrToIntPtr :: Ptr a -> IntPtr
foreign import ccall unsafe "__hscore_from_intptr"
intPtrToPtr :: IntPtr -> Ptr a
# endif /* !__GLASGOW_HASKELL__ */
#endif /* !__NHC_ */