+
+#ifndef __NHC__
+# include "HsBaseConfig.h"
+# include "CTypes.h"
+
+# ifdef __GLASGOW_HASKELL__
+-- | An unsigned integral type that can be losslessly converted to and from
+-- @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
+
+-- | A signed integral type that can be losslessly converted to and from
+-- @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
+
+-- | casts a @Ptr@ to a @WordPtr@
+ptrToWordPtr :: Ptr a -> WordPtr
+ptrToWordPtr (Ptr a#) = WordPtr (W# (int2Word# (addr2Int# a#)))
+
+-- | casts a @WordPtr@ to a @Ptr@
+wordPtrToPtr :: WordPtr -> Ptr a
+wordPtrToPtr (WordPtr (W# w#)) = Ptr (int2Addr# (word2Int# w#))
+
+-- | casts a @Ptr@ to an @IntPtr@
+ptrToIntPtr :: Ptr a -> IntPtr
+ptrToIntPtr (Ptr a#) = IntPtr (I# (addr2Int# a#))
+
+-- | casts an @IntPtr@ to a @Ptr@
+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)
+
+{-# CFILES cbits/PrelIOUtils.c #-}
+
+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_ */