diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2017-01-15 11:53:34 -0500 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2017-01-15 11:53:34 -0500 |
commit | db91d17edfbe7deecb62bbb89c804249f9c4a4bd (patch) | |
tree | 7c01e3256c19a009625f96bc5e977ac5b673cd4c /libraries/base | |
parent | 331f88d0d878eae926b3c1c61a3ff344916b62ed (diff) | |
download | haskell-db91d17edfbe7deecb62bbb89c804249f9c4a4bd.tar.gz |
Properly introduce CTimer to System.Posix.Types
Summary:
In ffc2327070dbb664bdb407a804121eacb2a7c734, an attempt was made at
adding a Haskell wrapper around the C `timer_t` type. Unfortunately, GHC's
autoconf macros weren't sophisticated enough at the time to properly detect
that `timer_t` is represented by a `void *` (i.e., a pointer) on most OSes.
This is a second attempt at `CTimer`, this time using `AC_COMPILE_IFELSE` to
detect if a type is a pointer type by compiling the following program:
```
type val;
*val;
```
This also only derives a small subset of class instances for `CTimer` that are
known to be compatible with `Ptr` using a new `OPAQUE_TYPE_WITH_CTYPE` macro.
Test Plan: ./validate
Reviewers: erikd, hvr, austin, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2952
GHC Trac Issues: #12795, #12998
Diffstat (limited to 'libraries/base')
-rw-r--r-- | libraries/base/System/Posix/Types.hs | 14 | ||||
-rw-r--r-- | libraries/base/aclocal.m4 | 53 | ||||
-rw-r--r-- | libraries/base/changelog.md | 2 | ||||
-rw-r--r-- | libraries/base/configure.ac | 1 | ||||
-rw-r--r-- | libraries/base/include/CTypes.h | 6 |
5 files changed, 50 insertions, 26 deletions
diff --git a/libraries/base/System/Posix/Types.hs b/libraries/base/System/Posix/Types.hs index da4fc608d9..a02a5b94e4 100644 --- a/libraries/base/System/Posix/Types.hs +++ b/libraries/base/System/Posix/Types.hs @@ -92,13 +92,9 @@ module System.Posix.Types ( #if defined(HTYPE_KEY_T) CKey(..), #endif --- We can't support CTimer (timer_t) yet, as FPTOOLS_CHECK_HTYPE doesn't have --- the ability to discern pointer types (like void*, which timer_t usually is) --- from non-pointer types. See GHC Trac #12998. --- --- #if defined(HTYPE_TIMER_T) --- CTimer(..), --- #endif +#if defined(HTYPE_TIMER_T) + CTimer(..), +#endif Fd(..), @@ -213,6 +209,10 @@ INTEGRAL_TYPE_WITH_CTYPE(CId,id_t,HTYPE_ID_T) -- | @since 4.10.0.0 INTEGRAL_TYPE_WITH_CTYPE(CKey,key_t,HTYPE_KEY_T) #endif +#if defined(HTYPE_TIMER_T) +-- | @since 4.10.0.0 +OPAQUE_TYPE_WITH_CTYPE(CTimer,timer_t,HTYPE_TIMER_T) +#endif -- Make an Fd type rather than using CInt everywhere INTEGRAL_TYPE(Fd,CInt) diff --git a/libraries/base/aclocal.m4 b/libraries/base/aclocal.m4 index 50d8168ec0..17b8bca9ce 100644 --- a/libraries/base/aclocal.m4 +++ b/libraries/base/aclocal.m4 @@ -131,26 +131,43 @@ AC_DEFUN([FPTOOLS_CHECK_HTYPE_ELSE],[ if test "$HTYPE_IS_INTEGRAL" -eq 0 then - FP_COMPUTE_INT([HTYPE_IS_FLOAT],[sizeof($1) == sizeof(float)], - [FPTOOLS_HTYPE_INCLUDES], - [AC_CV_NAME_supported=no]) - FP_COMPUTE_INT([HTYPE_IS_DOUBLE],[sizeof($1) == sizeof(double)], - [FPTOOLS_HTYPE_INCLUDES], - [AC_CV_NAME_supported=no]) - FP_COMPUTE_INT([HTYPE_IS_LDOUBLE],[sizeof($1) == sizeof(long double)], - [FPTOOLS_HTYPE_INCLUDES], - [AC_CV_NAME_supported=no]) - if test "$HTYPE_IS_FLOAT" -eq 1 - then - AC_CV_NAME=Float - elif test "$HTYPE_IS_DOUBLE" -eq 1 - then - AC_CV_NAME=Double - elif test "$HTYPE_IS_LDOUBLE" -eq 1 + dnl If the C type isn't an integer, we check if it's a pointer type + dnl by trying to dereference one of its values. If that fails to + dnl compile, it's not a pointer, so we check to see if it's a + dnl floating-point type. + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [FPTOOLS_HTYPE_INCLUDES], + [$1 val; *val;] + )], + [HTYPE_IS_POINTER=yes], + [HTYPE_IS_POINTER=no]) + + if test "$HTYPE_IS_POINTER" = yes then - AC_CV_NAME=LDouble + AC_CV_NAME="Ptr ()" else - AC_CV_NAME_supported=no + FP_COMPUTE_INT([HTYPE_IS_FLOAT],[sizeof($1) == sizeof(float)], + [FPTOOLS_HTYPE_INCLUDES], + [AC_CV_NAME_supported=no]) + FP_COMPUTE_INT([HTYPE_IS_DOUBLE],[sizeof($1) == sizeof(double)], + [FPTOOLS_HTYPE_INCLUDES], + [AC_CV_NAME_supported=no]) + FP_COMPUTE_INT([HTYPE_IS_LDOUBLE],[sizeof($1) == sizeof(long double)], + [FPTOOLS_HTYPE_INCLUDES], + [AC_CV_NAME_supported=no]) + if test "$HTYPE_IS_FLOAT" -eq 1 + then + AC_CV_NAME=Float + elif test "$HTYPE_IS_DOUBLE" -eq 1 + then + AC_CV_NAME=Double + elif test "$HTYPE_IS_LDOUBLE" -eq 1 + then + AC_CV_NAME=LDouble + else + AC_CV_NAME_supported=no + fi fi else FP_COMPUTE_INT([HTYPE_IS_SIGNED],[(($1)(-1)) < (($1)0)], diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md index b73e01ecc0..d687e07cb7 100644 --- a/libraries/base/changelog.md +++ b/libraries/base/changelog.md @@ -31,7 +31,7 @@ * Added `Eq1`, `Ord1`, `Read1` and `Show1` instances for `NonEmpty`. * Add wrappers for `blksize_t`, `blkcnt_t`, `clockid_t`, `fsblkcnt_t`, - `fsfilcnt_t`, `id_t`, and `key_t` to System.Posix.Types (#12795) + `fsfilcnt_t`, `id_t`, `key_t`, and `timer_t` to System.Posix.Types (#12795) * Raw buffer operations in `GHC.IO.FD` are now strict in the buffer, offset, and length operations (#9696) diff --git a/libraries/base/configure.ac b/libraries/base/configure.ac index c99c284c93..e6c8a9b276 100644 --- a/libraries/base/configure.ac +++ b/libraries/base/configure.ac @@ -155,6 +155,7 @@ FPTOOLS_CHECK_HTYPE(fsblkcnt_t) FPTOOLS_CHECK_HTYPE(fsfilcnt_t) FPTOOLS_CHECK_HTYPE(id_t) FPTOOLS_CHECK_HTYPE(key_t) +FPTOOLS_CHECK_HTYPE(timer_t) FPTOOLS_CHECK_HTYPE(intptr_t) FPTOOLS_CHECK_HTYPE(uintptr_t) diff --git a/libraries/base/include/CTypes.h b/libraries/base/include/CTypes.h index 9fa1e4a1c1..e9d19a8401 100644 --- a/libraries/base/include/CTypes.h +++ b/libraries/base/include/CTypes.h @@ -19,6 +19,7 @@ #define ARITHMETIC_CLASSES Eq,Ord,Num,Enum,Storable,Real #define INTEGRAL_CLASSES Bounded,Integral,Bits,FiniteBits #define FLOATING_CLASSES Fractional,Floating,RealFrac,RealFloat +#define OPAQUE_CLASSES Eq,Ord,Storable #define ARITHMETIC_TYPE(T,B) \ newtype T = T B deriving (ARITHMETIC_CLASSES) \ @@ -42,4 +43,9 @@ newtype {-# CTYPE "THE_CTYPE" #-} T = T B \ deriving (ARITHMETIC_CLASSES, FLOATING_CLASSES) \ deriving newtype (Read, Show); +#define OPAQUE_TYPE_WITH_CTYPE(T,THE_CTYPE,B) \ +newtype {-# CTYPE "THE_CTYPE" #-} T = T (B) \ + deriving (OPAQUE_CLASSES) \ + deriving newtype Show; + #endif |