Consistently use CInt rather than Int for FDs
[ghc-base.git] / Foreign / C / Types.hs
index c40e197..04a96ab 100644 (file)
@@ -1,4 +1,4 @@
-{-# OPTIONS -fno-implicit-prelude #-}
+{-# OPTIONS_GHC -fno-implicit-prelude #-}
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Foreign.C.Types
@@ -30,6 +30,8 @@ module Foreign.C.Types
        , CLong,  CULong
        , CPtrdiff, CSize, CWchar, CSigAtomic
         , CLLong, CULLong
+       , CIntPtr, CUIntPtr
+       , CIntMax, CUIntMax
 
          -- ** Numeric types
          -- | These types are are represented as @newtype@s of basic
@@ -64,11 +66,11 @@ module Foreign.C.Types
 
 #ifndef __NHC__
 
-import Foreign.Storable
+import {-# SOURCE #-} Foreign.Storable
 import Data.Bits       ( Bits(..) )
 import Data.Int                ( Int8,  Int16,  Int32,  Int64  )
 import Data.Word       ( Word8, Word16, Word32, Word64 )
-import Data.Typeable
+import {-# SOURCE #-} Data.Typeable
 
 #ifdef __GLASGOW_HASKELL__
 import GHC.Base
@@ -79,8 +81,11 @@ import GHC.Show
 import GHC.Read
 import GHC.Num
 #else
-import Control.Monad
-import Foreign.Ptr
+import Control.Monad   ( liftM )
+#endif
+
+#ifdef __HUGS__
+import Hugs.Ptr                ( castPtr )
 #endif
 
 #include "HsBaseConfig.h"
@@ -191,8 +196,20 @@ data CFpos = CFpos
 -- | Haskell type representing the C @jmp_buf@ type.
 data CJmpBuf = CJmpBuf
 
+INTEGRAL_TYPE(CIntPtr,tyConCIntPtr,"CIntPtr",HTYPE_INTPTR_T)
+INTEGRAL_TYPE(CUIntPtr,tyConCUIntPtr,"CUIntPtr",HTYPE_UINTPTR_T)
+INTEGRAL_TYPE(CIntMax,tyConCIntMax,"CIntMax",HTYPE_INTMAX_T)
+INTEGRAL_TYPE(CUIntMax,tyConCUIntMax,"CUIntMax",HTYPE_UINTMAX_T)
+
+{-# RULES
+"fromIntegral/a->CIntPtr"  fromIntegral = \x -> CIntPtr  (fromIntegral x)
+"fromIntegral/a->CUIntPtr" fromIntegral = \x -> CUIntPtr (fromIntegral x)
+"fromIntegral/a->CIntMax"  fromIntegral = \x -> CIntMax  (fromIntegral x)
+"fromIntegral/a->CUIntMax" fromIntegral = \x -> CUIntMax (fromIntegral x)
+ #-}
+
 -- C99 types which are still missing include:
--- intptr_t, uintptr_t, intmax_t, uintmax_t, wint_t, wctrans_t, wctype_t
+-- wint_t, wctrans_t, wctype_t
 
 {- $ctypes