bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] regex: port to mingw's recent addition of undeclared alarm


From: Eric Blake
Subject: [PATCH 1/2] regex: port to mingw's recent addition of undeclared alarm
Date: Mon, 11 Mar 2013 15:42:07 -0600

On mingw (at least, when cross-compiling with Fedora 18's
mingw32-headers-2.0.999-0.15.trunk.20121110.fc18.noarch build),
compilation of test-regex fails:

test-regex.c: In function 'main':
test-regex.c:42:11: error: 'SIGALRM' undeclared (first use in this function)
test-regex.c:42:11: note: each undeclared identifier is reported only
once for each function it appears in
test-regex.c:43:3: warning: implicit declaration of function 'alarm'

It turns out that recent mingw64 added an export of alarm() and
SIGALRM, but guarded their declarations behind __USE_MINGW_ALARM
(default off, and with alarm() only in the non-standard <io.h>);
so the m4 tests were setting HAVE_ALARM to 1 based on link success
but then failing to compile.

* doc/posix-functions/alarm.texi (alarm): Document that alarm
exists but still doesn't work in newer mingw.
* m4/frexp.m4 (gl_FUNC_FREXP_WORKS): Check for alarm declaration,
not existence.  Ensure SIGALRM is not trapped.
* m4/mktime.m4 (gl_FUNC_MKTIME): Likewise.
* m4/regex.m4 (gl_REGEX): Likewise.
* m4/remainderf.m4 (gl_FUNC_REMAINDERF_WORKS): Likewise.
* tests/test-regex.c (main): Use correct probe for alarm.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog                      | 10 ++++++++++
 doc/posix-functions/alarm.texi | 12 +++++++++++-
 m4/frexp.m4                    | 10 ++++++----
 m4/mktime.m4                   | 11 +++++++----
 m4/regex.m4                    |  8 ++++----
 m4/remainderf.m4               | 10 ++++++----
 tests/test-regex.c             |  4 ++--
 7 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6d8c2c7..addadee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2013-03-11  Eric Blake  <address@hidden>

+       regex: port to mingw's recent addition of undeclared alarm
+       * doc/posix-functions/alarm.texi (alarm): Document that alarm
+       exists but still doesn't work in newer mingw.
+       * m4/frexp.m4 (gl_FUNC_FREXP_WORKS): Check for alarm declaration,
+       not existence.  Ensure SIGALRM is not trapped.
+       * m4/mktime.m4 (gl_FUNC_MKTIME): Likewise.
+       * m4/regex.m4 (gl_REGEX): Likewise.
+       * m4/remainderf.m4 (gl_FUNC_REMAINDERF_WORKS): Likewise.
+       * tests/test-regex.c (main): Use correct probe for alarm.
+
        putenv: avoid compilation warning on mingw
        * lib/putenv.c (_unsetenv): Protect variable declaration.
        (putenv): Fix indentation.
diff --git a/doc/posix-functions/alarm.texi b/doc/posix-functions/alarm.texi
index 79d2db1..2a6c4f2 100644
--- a/doc/posix-functions/alarm.texi
+++ b/doc/posix-functions/alarm.texi
@@ -13,6 +13,16 @@ alarm
 Portability problems not fixed by Gnulib:
 @itemize
 @item
+This function has no impact if <code>SIGALRM</code> is inherited as
+ignored; programs should use <code>signal (SIGALRM, SIG_DFL)</code> if
+it is important to ensure the alarm will fire.
address@hidden
+Use of this function in multi-threaded applications is not advised.
address@hidden
 This function is missing on some platforms:
-mingw, MSVC 9.
+mingw (2011), MSVC 9.
address@hidden
+This function is conditionally declared in the non-standard
address@hidden<io.h>} header on some platforms:
+mingw (2012 or newer).
 @end itemize
diff --git a/m4/frexp.m4 b/m4/frexp.m4
index 3909792..2eb98a1 100644
--- a/m4/frexp.m4
+++ b/m4/frexp.m4
@@ -1,4 +1,4 @@
-# frexp.m4 serial 14
+# frexp.m4 serial 15
 dnl Copyright (C) 2007-2013 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -93,7 +93,7 @@ AC_DEFUN([gl_FUNC_FREXP_WORKS],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
-  AC_CHECK_FUNCS_ONCE([alarm])
+  AC_CHECK_DECLS_ONCE([alarm])
   AC_CACHE_CHECK([whether frexp works], [gl_cv_func_frexp_works],
     [
       AC_RUN_IFELSE(
@@ -101,7 +101,8 @@ AC_DEFUN([gl_FUNC_FREXP_WORKS],
 #include <float.h>
 #include <math.h>
 #include <string.h>
-#if HAVE_ALARM
+#if HAVE_DECL_ALARM
+# include <signal.h>
 # include <unistd.h>
 #endif
 /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
@@ -124,9 +125,10 @@ int main()
   int i;
   volatile double x;
   double zero = 0.0;
-#if HAVE_ALARM
+#if HAVE_DECL_ALARM
   /* NeXTstep 3.3 frexp() runs into an endless loop when called on an infinite
      number.  Let the test fail in this case.  */
+  signal (SIGALRM, SIG_DFL);
   alarm (5);
 #endif
   /* Test on denormalized numbers.  */
diff --git a/m4/mktime.m4 b/m4/mktime.m4
index d3d376a..ab612ab 100644
--- a/m4/mktime.m4
+++ b/m4/mktime.m4
@@ -1,4 +1,4 @@
-# serial 24
+# serial 25
 dnl Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -14,7 +14,7 @@ AC_DEFUN([gl_FUNC_MKTIME],
   dnl We don't use AC_FUNC_MKTIME any more, because it is no longer maintained
   dnl in Autoconf and because it invokes AC_LIBOBJ.
   AC_CHECK_HEADERS_ONCE([unistd.h])
-  AC_CHECK_FUNCS_ONCE([alarm])
+  AC_CHECK_DECLS_ONCE([alarm])
   AC_REQUIRE([gl_MULTIARCH])
   if test $APPLE_UNIVERSAL_BUILD = 1; then
     # A universal build on Apple Mac OS X platforms.
@@ -34,8 +34,8 @@ AC_DEFUN([gl_FUNC_MKTIME],
 # include <unistd.h>
 #endif

-#ifndef HAVE_ALARM
-# define alarm(X) /* empty */
+#ifndef HAVE_DECL_ALARM
+# include <signal.h>
 #endif

 /* Work around redefinition to rpl_putenv by other config tests.  */
@@ -171,10 +171,13 @@ main ()
   int time_t_signed_magnitude = (time_t) ~ (time_t) 0 < (time_t) -1;
   int time_t_signed = ! ((time_t) 0 < (time_t) -1);

+#if HAVE_DECL_ALARM
   /* This test makes some buggy mktime implementations loop.
      Give up after 60 seconds; a mktime slower than that
      isn't worth using anyway.  */
+  signal (SIGALRM, SIG_DFL);
   alarm (60);
+#endif

   time_t_max = (! time_t_signed
                 ? (time_t) -1
diff --git a/m4/regex.m4 b/m4/regex.m4
index ae89e31..3334c10 100644
--- a/m4/regex.m4
+++ b/m4/regex.m4
@@ -1,4 +1,4 @@
-# serial 63
+# serial 64

 # Copyright (C) 1996-2001, 2003-2013 Free Software Foundation, Inc.
 #
@@ -27,7 +27,7 @@ AC_DEFUN([gl_REGEX],
     # following run test, then default to *not* using the included regex.c.
     # If cross compiling, assume the test would fail and use the included
     # regex.c.
-    AC_CHECK_FUNCS_ONCE([alarm])
+    AC_CHECK_DECLS_ONCE([alarm])
     AC_CACHE_CHECK([for working re_compile_pattern],
                    [gl_cv_func_re_compile_pattern_working],
       [AC_RUN_IFELSE(
@@ -37,7 +37,7 @@ AC_DEFUN([gl_REGEX],
             #include <locale.h>
             #include <limits.h>
             #include <string.h>
-            #if HAVE_ALARM
+            #if HAVE_DECL_ALARM
             # include <unistd.h>
             # include <signal.h>
             #endif
@@ -49,7 +49,7 @@ AC_DEFUN([gl_REGEX],
             const char *s;
             struct re_registers regs;

-#if HAVE_ALARM
+#if HAVE_DECL_ALARM
             /* Some builds of glibc go into an infinite loop on this test.  */
             signal (SIGALRM, SIG_DFL);
             alarm (2);
diff --git a/m4/remainderf.m4 b/m4/remainderf.m4
index 33df781..afb2618 100644
--- a/m4/remainderf.m4
+++ b/m4/remainderf.m4
@@ -1,4 +1,4 @@
-# remainderf.m4 serial 7
+# remainderf.m4 serial 8
 dnl Copyright (C) 2012-2013 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -150,13 +150,14 @@ AC_DEFUN([gl_FUNC_REMAINDERF_WORKS],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
-  AC_CHECK_FUNCS_ONCE([alarm])
+  AC_CHECK_DECLS_ONCE([alarm])
   AC_CACHE_CHECK([whether remainderf works], [gl_cv_func_remainderf_works],
     [
       AC_RUN_IFELSE(
         [AC_LANG_SOURCE([[
 #include <math.h>
-#if HAVE_ALARM
+#if HAVE_DECL_ALARM
+# include <signal.h>
 # include <unistd.h>
 #endif
 extern
@@ -169,7 +170,8 @@ volatile float y;
 float z;
 int main ()
 {
-#if HAVE_ALARM
+#if HAVE_DECL_ALARM
+  signal (SIGALRM, SIG_DFL);
   alarm (5);
 #endif
   /* This test fails on IRIX 6.5.  */
diff --git a/tests/test-regex.c b/tests/test-regex.c
index 2488cee..6829035 100644
--- a/tests/test-regex.c
+++ b/tests/test-regex.c
@@ -21,7 +21,7 @@
 #include <locale.h>
 #include <limits.h>
 #include <string.h>
-#if HAVE_ALARM
+#if HAVE_DECL_ALARM
 # include <unistd.h>
 # include <signal.h>
 #endif
@@ -36,7 +36,7 @@ main (void)
   const char *s;
   struct re_registers regs;

-#if HAVE_ALARM
+#if HAVE_DECL_ALARM
   /* Some builds of glibc go into an infinite loop on this test.  */
   int alarm_value = 2;
   signal (SIGALRM, SIG_DFL);
-- 
1.8.1.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]