[m-rev.] diff: Include <sys/select.h> for select() if available.

Peter Wang novalazy at gmail.com
Tue Sep 11 11:16:43 AEST 2018


According to the man page, <sys/select.h> is the header to include
on POSIX systems for select() and associated APIs.
Fixes compilation with some versions of Cygwin (Github issue #49).

configure.ac:
runtime/mercury_conf.h.in
    Define MR_HAVE_SYS_SELECT_H if <sys/select.h> is available.

runtime/mercury_reg_workarounds.c
runtime/mercury_reg_workarounds.h
    Include <sys/select.h> if MR_HAVE_SYS_SELECT_H is defined.
---
 configure.ac                      | 5 ++++-
 runtime/mercury_conf.h.in         | 4 +++-
 runtime/mercury_reg_workarounds.c | 4 ++++
 runtime/mercury_reg_workarounds.h | 3 +++
 4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 155061e98..a63cf9bc2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1417,13 +1417,13 @@ LIBS="$save_LIBS"
 MERCURY_CHECK_FOR_HEADERS( \
         unistd.h sys/wait.h sys/siginfo.h sys/signal.h ucontext.h \
         asm/sigcontext.h sys/param.h sys/time.h sys/times.h \
         sys/types.h sys/stat.h fcntl.h termios.h sys/ioctl.h \
         sys/resource.h sys/stropts.h windows.h dirent.h getopt.h malloc.h \
         semaphore.h pthread.h time.h spawn.h fenv.h sys/mman.h sys/sem.h \
-        sched.h utmpx.h dispatch/dispatch.h stdint.h)
+        sched.h utmpx.h dispatch/dispatch.h stdint.h sys/select.h )
 
 if test "$MR_HAVE_GETOPT_H" = 1; then
     GETOPT_H_AVAILABLE=yes
 else
     GETOPT_H_AVAILABLE=no
 fi
@@ -2423,12 +2423,15 @@ fi
 #-----------------------------------------------------------------------------#
 
 AC_MSG_CHECKING(to see if we can handle contexts blocking on IO)
 AC_CACHE_VAL(mercury_cv_can_do_pending_io,
     AC_TRY_RUN(
         [
+            #ifdef MR_HAVE_SYS_SELECT_H
+            #include <sys/select.h>
+            #endif
             #include <sys/types.h>
             #include <sys/time.h>
             int main() {
                 fd_set f;
                 struct timeval zero;
                 int err;
diff --git a/runtime/mercury_conf.h.in b/runtime/mercury_conf.h.in
index 99d4d1ad2..7a46afa26 100644
--- a/runtime/mercury_conf.h.in
+++ b/runtime/mercury_conf.h.in
@@ -137,13 +137,14 @@
 //  MR_HAVE_SYS_MMAN_H      we have <sys/mman.h>
 //  MR_HAVE_SYS_SEM_H       we have <sys/sem.h>
 //  MR_HAVE_SCHED_H         we have <sched.h>
 //  MR_HAVE_UTMPX_H         we have <utmpx.h>
 //  MR_HAVE_SYS_RESOURCE_H  we have <sys/resource.h>
 //  MR_HAVE_DISPATCH_DISPATCH_H we have <dispatch/dispatch.h>
-//  MR_HAVE_STDINT          we have <stdint.h>
+//  MR_HAVE_STDINT_H        we have <stdint.h>
+//  MR_HAVE_SYS_SELECT_H    we have <sys/select.h>
 
 #undef  MR_HAVE_SYS_SIGINFO_H
 #undef  MR_HAVE_SYS_SIGNAL_H
 #undef  MR_HAVE_UCONTEXT_H
 #undef  MR_HAVE_SYS_UCONTEXT_H
 #undef  MR_HAVE_ASM_SIGCONTEXT_H
@@ -172,12 +173,13 @@
 #undef  MR_HAVE_SYS_SEM_H
 #undef  MR_HAVE_SCHED_H
 #undef  MR_HAVE_UTMPX_H
 #undef  MR_HAVE_SYS_RESOURCE_H
 #undef  MR_HAVE_DISPATCH_DISPATCH_H
 #undef  MR_HAVE_STDINT_H
+#undef  MR_HAVE_SYS_SELECT_H
 
 // MR_HAVE_POSIX_TIMES is defined if we have the POSIX
 // `struct tms' struct and times() function.
 
 #undef MR_HAVE_POSIX_TIMES
 
diff --git a/runtime/mercury_reg_workarounds.c b/runtime/mercury_reg_workarounds.c
index 0464a48fd..943fb5ed2 100644
--- a/runtime/mercury_reg_workarounds.c
+++ b/runtime/mercury_reg_workarounds.c
@@ -15,12 +15,16 @@
 #ifdef  MR_CAN_DO_PENDING_IO
 
 #ifdef MR_BZERO_NEEDS_STRINGS_HEADER
   #include <strings.h>
 #endif
 
+#ifdef MR_HAVE_SYS_SELECT_H
+  #include <sys/select.h>   // for select() -- POSIX
+#endif
+
 #include <sys/types.h>      // for fd_set and FD_ZERO()
 #include <sys/time.h>       // for FD_ZERO()
 
 #ifdef MR_HAVE_UNISTD_H
   #include <unistd.h>       // for FD_ZERO()
 #endif
diff --git a/runtime/mercury_reg_workarounds.h b/runtime/mercury_reg_workarounds.h
index f4fb2bcfd..f260c655c 100644
--- a/runtime/mercury_reg_workarounds.h
+++ b/runtime/mercury_reg_workarounds.h
@@ -9,12 +9,15 @@
 #ifndef MERCURY_REG_WORKAROUNDS_H
 #define MERCURY_REG_WORKAROUNDS_H
 
 #include "mercury_conf.h"
 
 #ifdef MR_CAN_DO_PENDING_IO
+  #ifdef MR_HAVE_SYS_SELECT_H
+    #include <sys/select.h>     // for select() -- POSIX
+  #endif
   #include <sys/types.h>        // for fd_set
   #include <sys/time.h>         // for FD_ZERO()
 #endif
 
 #include <stdlib.h>         // for size_t
 
-- 
2.18.0



More information about the reviews mailing list