autoconf-patches
[Top][All Lists]
Advanced

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

FYI: autoconf patch to catch recent glibc bug with mktime


From: Paul Eggert
Subject: FYI: autoconf patch to catch recent glibc bug with mktime
Date: Wed, 28 May 2003 13:07:02 -0700

A student of mine ran into a problem with Python that I tracked down
to a glibc bug with mktime.  Apparently glibc mktime no longer works
with negative time_t values.  I've installed the following patch to
Autoconf so that it can detect when mktime is not the inverse of
localtime.  I'll also fix gnulib's mktime so that it doesn't have the
bug either,

2003-05-28  Paul Eggert  <address@hidden>

        * NEWS, doc/autoconf.texi (Particular Functions),
        lib/autoconf/functions.m4 (AC_FUNC_MKTIME): Check that mktime
        is the inverse of localtime.

Index: NEWS
===================================================================
RCS file: /cvsroot/autoconf/autoconf/NEWS,v
retrieving revision 1.296
diff -p -u -r1.296 NEWS
--- NEWS        22 May 2003 21:52:43 -0000      1.296
+++ NEWS        28 May 2003 19:59:25 -0000
@@ -6,6 +6,9 @@
 ** AC_DECL_SYS_SIGLIST
   Works again.
 
+** AC_FUNC_MKTIME
+  Now checks that mktime is the inverse of localtime.
+
 ** Improve DJGPP portability
   The Autoconf tools and configure behave better under DJGPP.
 
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.739
diff -p -u -r1.739 autoconf.texi
--- doc/autoconf.texi   23 May 2003 13:14:30 -0000      1.739
+++ doc/autoconf.texi   28 May 2003 19:59:28 -0000
@@ -3945,6 +3945,9 @@ type @code{mbstate_t} are properly decla
 @prindex @code{mktime}
 If the @code{mktime} function is not available, or does not work
 correctly, require an @code{AC_LIBOBJ} replacement for @samp{mktime}.
+For the purposes of this test, @code{mktime} should conform to the
address@hidden standard and should be the inverse of
address@hidden
 @end defmac
 
 @defmac AC_FUNC_MMAP
Index: lib/autoconf/functions.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/functions.m4,v
retrieving revision 1.77
diff -p -u -r1.77 functions.m4
--- lib/autoconf/functions.m4   22 May 2003 08:24:04 -0000      1.77
+++ lib/autoconf/functions.m4   28 May 2003 19:59:29 -0000
@@ -940,7 +940,7 @@ test $ac_cv_func_memcmp_working = no && 
 AN_FUNCTION([mktime], [AC_FUNC_MKTIME])
 AC_DEFUN([AC_FUNC_MKTIME],
 [AC_REQUIRE([AC_HEADER_TIME])dnl
-AC_CHECK_HEADERS(sys/time.h unistd.h)
+AC_CHECK_HEADERS(stdlib.h sys/time.h unistd.h)
 AC_CHECK_FUNCS(alarm)
 AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
 [AC_RUN_IFELSE([AC_LANG_SOURCE(
@@ -956,6 +956,10 @@ AC_CACHE_CHECK([for working mktime], ac_
 # endif
 #endif
 
+#if HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+
 #if HAVE_UNISTD_H
 # include <unistd.h>
 #endif
@@ -968,10 +972,11 @@ AC_CACHE_CHECK([for working mktime], ac_
 #undef putenv
 
 static time_t time_t_max;
+static time_t time_t_min;
 
 /* Values we'll use to set the TZ environment variable.  */
-static const char *const tz_strings[] = {
-  (const char *) 0, "TZ=GMT0", "TZ=JST-9",
+static char *tz_strings[] = {
+  (char *) 0, "TZ=GMT0", "TZ=JST-9",
   "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
 };
 #define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
@@ -1002,15 +1007,21 @@ spring_forward_gap ()
 }
 
 static void
-mktime_test (now)
+mktime_test1 (now)
      time_t now;
 {
   struct tm *lt;
   if ((lt = localtime (&now)) && mktime (lt) != now)
     exit (1);
-  now = time_t_max - now;
-  if ((lt = localtime (&now)) && mktime (lt) != now)
-    exit (1);
+}
+
+static void
+mktime_test (now)
+     time_t now;
+{
+  mktime_test1 (now);
+  mktime_test1 ((time_t) (time_t_max - now));
+  mktime_test1 ((time_t) (time_t_min + now));
 }
 
 static void
@@ -1070,6 +1081,9 @@ main ()
   for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
     continue;
   time_t_max--;
+  if ((time_t) -1 < 0)
+    for (time_t_min = -1; (time_t) (time_t_min * 2) < 0; time_t_min *= 2)
+      continue;
   delta = time_t_max / 997; /* a suitable prime number */
   for (i = 0; i < N_STRINGS; i++)
     {
@@ -1078,8 +1092,9 @@ main ()
 
       for (t = 0; t <= time_t_max - delta; t += delta)
        mktime_test (t);
-      mktime_test ((time_t) 60 * 60);
-      mktime_test ((time_t) 60 * 60 * 24);
+      mktime_test ((time_t) 1);
+      mktime_test ((time_t) (60 * 60));
+      mktime_test ((time_t) (60 * 60 * 24));
 
       for (j = 1; 0 < j; j *= 2)
        bigtime_test (j);




reply via email to

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