Add Haskell types for C types useconds_t and suseconds_t, which are respectively...
authorWilliam Knop <william.knop.nospam@gmail.com>
Tue, 5 Apr 2011 00:24:36 +0000 (20:24 -0400)
committerAdam Megacz <megacz@cs.berkeley.edu>
Mon, 20 Jun 2011 02:04:26 +0000 (19:04 -0700)
The tv_usec field of struct timeval was incorrectly used as C type time_t; the actual C type is suseconds_t. On OS X, time_t is longer than suseconds_t, which caused garbage bits to be copied as reported in trac #4247 and #4970. This patch is part 1 of 4 to fix those tickets.

Foreign/C/Types.hs
configure.ac

index 98113c8..f6bdec1 100644 (file)
@@ -49,7 +49,7 @@ module Foreign.C.Types
           -- foreign types, and are instances of
           -- 'Prelude.Eq', 'Prelude.Ord', 'Prelude.Num', 'Prelude.Read',
           -- 'Prelude.Show', 'Prelude.Enum', 'Typeable' and 'Storable'.
           -- foreign types, and are instances of
           -- 'Prelude.Eq', 'Prelude.Ord', 'Prelude.Num', 'Prelude.Read',
           -- 'Prelude.Show', 'Prelude.Enum', 'Typeable' and 'Storable'.
-        , CClock,   CTime
+        , CClock,   CTime, CUSeconds, CSUSeconds
 
         -- extracted from CTime, because we don't want this comment in
         -- the Haskell 2010 report:
 
         -- extracted from CTime, because we don't want this comment in
         -- the Haskell 2010 report:
@@ -78,7 +78,7 @@ module Foreign.C.Types
         , CLong(..),    CULong(..)
         , CPtrdiff(..), CSize(..),   CWchar(..), CSigAtomic(..)
         , CLLong(..),   CULLong(..)
         , CLong(..),    CULong(..)
         , CPtrdiff(..), CSize(..),   CWchar(..), CSigAtomic(..)
         , CLLong(..),   CULLong(..)
-        , CClock(..),   CTime(..)
+        , CClock(..),   CTime(..),   CUSeconds(..), CSUSeconds(..)
         , CFloat(..),   CDouble(..), CLDouble(..)
         , CIntPtr(..), CUIntPtr(..), CIntMax(..), CUIntMax(..)
 #endif
         , CFloat(..),   CDouble(..), CLDouble(..)
         , CIntPtr(..), CUIntPtr(..), CIntMax(..), CUIntMax(..)
 #endif
@@ -217,6 +217,10 @@ ARITHMETIC_TYPE(CClock,tyConCClock,"CClock",HTYPE_CLOCK_T)
 -- | Haskell type representing the C @time_t@ type.
 --
 ARITHMETIC_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
 -- | Haskell type representing the C @time_t@ type.
 --
 ARITHMETIC_TYPE(CTime,tyConCTime,"CTime",HTYPE_TIME_T)
+-- | Haskell type representing the C @useconds_t@ type.
+ARITHMETIC_TYPE(CUSeconds,tyConCUSeconds,"CUSeconds",HTYPE_USECONDS_T)
+-- | Haskell type representing the C @suseconds_t@ type.
+ARITHMETIC_TYPE(CSUSeconds,tyConCSUSeconds,"CSUSeconds",HTYPE_SUSECONDS_T)
 
 -- FIXME: Implement and provide instances for Eq and Storable
 -- | Haskell type representing the C @FILE@ type.
 
 -- FIXME: Implement and provide instances for Eq and Storable
 -- | Haskell type representing the C @FILE@ type.
@@ -291,7 +295,7 @@ import NHC.FFI
   , CShort(..),   CUShort(..), CInt(..),   CUInt(..)
   , CLong(..),    CULong(..),  CLLong(..), CULLong(..)
   , CPtrdiff(..), CSize(..),   CWchar(..), CSigAtomic(..)
   , CShort(..),   CUShort(..), CInt(..),   CUInt(..)
   , CLong(..),    CULong(..),  CLLong(..), CULLong(..)
   , CPtrdiff(..), CSize(..),   CWchar(..), CSigAtomic(..)
-  , CClock(..),   CTime(..)
+  , CClock(..),   CTime(..),   CUSeconds(..), CSUSeconds(..)
   , CFloat(..),   CDouble(..), CLDouble(..)
   , CIntPtr(..),  CUIntPtr(..),CIntMax(..), CUIntMax(..)
   , CFile,        CFpos,       CJmpBuf
   , CFloat(..),   CDouble(..), CLDouble(..)
   , CIntPtr(..),  CUIntPtr(..),CIntMax(..), CUIntMax(..)
   , CFile,        CFpos,       CJmpBuf
index dd6c5c6..65c5a49 100644 (file)
@@ -90,6 +90,8 @@ FPTOOLS_CHECK_HTYPE(wchar_t)
 FPTOOLS_CHECK_HTYPE(sig_atomic_t, Int32)
 FPTOOLS_CHECK_HTYPE(clock_t)
 FPTOOLS_CHECK_HTYPE(time_t)
 FPTOOLS_CHECK_HTYPE(sig_atomic_t, Int32)
 FPTOOLS_CHECK_HTYPE(clock_t)
 FPTOOLS_CHECK_HTYPE(time_t)
+FPTOOLS_CHECK_HTYPE(useconds_t)
+FPTOOLS_CHECK_HTYPE(suseconds_t)
 FPTOOLS_CHECK_HTYPE(dev_t, Word32)
 FPTOOLS_CHECK_HTYPE(ino_t)
 FPTOOLS_CHECK_HTYPE(mode_t)
 FPTOOLS_CHECK_HTYPE(dev_t, Word32)
 FPTOOLS_CHECK_HTYPE(ino_t)
 FPTOOLS_CHECK_HTYPE(mode_t)