bug-gnulib
[Top][All Lists]
Advanced

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

Re: Status of the win32 gettimeofday module


From: Bruno Haible
Subject: Re: Status of the win32 gettimeofday module
Date: Fri, 19 Jan 2007 03:16:46 +0100 (MET)
User-agent: KMail/1.5.4

Compiling a testdir
  - on Linux (to test the case where gettimeofday is present),
  - in a cross-compile to Cygwin (to test the case where gettimeofday is
    assumed to clobber localtime's buffer),
  - in a cross-compile to Mingw (to test the case of missing gettimeofday)
I again come up with several fixes:



1) Erik Blake wrote:
> With the new headers, we no longer #define gettimeofday rpl_gettimeofday in 
> <sys/time.h>.

Sure we do. On mingw, sys/time.h should have a #if 1
around the redefinition of gettimeofday.

>       * m4/gettimeofday.m4 (gl_GETTIMEOFDAY_REPLACE_LOCALTIME): Also
>       replace gettimeofday.
>       * lib/gettimeofday.c (rpl_gettimeofday): Declare with replacement
>       name, to avoid infinite recursion.

The first part is wrong: it causes a compilation failure when cross-
compiling to Cygwin, because the declaration of gettimeofday in
<sys/time.h> or <time.h> now disagrees with its definition in
lib/gettimeofday.c.

The second part is a nop, because lib/gettimeofday.c includes sys/time.h
which defines gettimeofday to rpl_gettimeofday.

I'm installing this:

--- m4/gettimeofday.m4  18 Jan 2007 16:15:42 -0000      1.14
+++ m4/gettimeofday.m4  19 Jan 2007 01:35:36 -0000
@@ -90,8 +90,6 @@
     [Define to rpl_gmtime if the replacement function should be used.])
   AC_DEFINE([localtime], [rpl_localtime],
     [Define to rpl_localtime if the replacement function should be used.])
-  AC_DEFINE([gettimeofday], [rpl_gettimeofday],
-    [Define to rpl_gettimeofday if the replacement function should be used.])
 ])
 
 # Prerequisites of lib/gettimeofday.c.



2) A simplification: One variable to be substituted into sys/time.h is
sufficient.

--- lib/sys_time_.h     18 Jan 2007 08:33:34 -0000      1.1
+++ lib/sys_time_.h     19 Jan 2007 01:35:35 -0000
@@ -35,7 +35,7 @@
 };
 #endif
 
-#if ! @HAVE_GETTIMEOFDAY_POSIX_SIGNATURE@ || @GETTIMEOFDAY_CLOBBERS_LOCALTIME@
+#if @GETTIMEOFDAY_REPLACEMENT@
 # undef gettimeofday
 # define gettimeofday rpl_gettimeofday
 int gettimeofday (struct timeval *restrict, void *restrict);
--- m4/gettimeofday.m4  18 Jan 2007 16:15:42 -0000      1.14
+++ m4/gettimeofday.m4  19 Jan 2007 01:35:36 -0000
@@ -31,7 +31,7 @@
   gl_FUNC_GETTIMEOFDAY_CLOBBER
 
   if test $gl_cv_func_gettimeofday_posix_signature != yes; then
-    HAVE_GETTIMEOFDAY_POSIX_SIGNATURE=0
+    GETTIMEOFDAY_REPLACEMENT=1
     if test $gl_cv_func_gettimeofday_clobber != yes; then
       AC_LIBOBJ(gettimeofday)
       gl_PREREQ_GETTIMEOFDAY
@@ -76,8 +76,8 @@
      [gl_cv_func_gettimeofday_clobber=yes])])
 
  if test $gl_cv_func_gettimeofday_clobber = yes; then
+   GETTIMEOFDAY_REPLACEMENT=1
    gl_GETTIMEOFDAY_REPLACE_LOCALTIME
-   GETTIMEOFDAY_CLOBBERS_LOCALTIME=1
    AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], 1,
      [Define if gettimeofday clobbers the localtime buffer.])
  fi
--- m4/sys_time_h.m4    18 Jan 2007 08:33:35 -0000      1.1
+++ m4/sys_time_h.m4    19 Jan 2007 01:35:36 -0000
@@ -42,8 +50,6 @@
   AC_SUBST([HAVE_STRUCT_TIMEVAL])
 
   dnl Assume POSIX behavior unless another module says otherwise.
-  HAVE_GETTIMEOFDAY_POSIX_SIGNATURE=1
-  AC_SUBST([HAVE_GETTIMEOFDAY_POSIX_SIGNATURE])
-  GETTIMEOFDAY_CLOBBERS_LOCALTIME=0
-  AC_SUBST([GETTIMEOFDAY_CLOBBERS_LOCALTIME])
+  GETTIMEOFDAY_REPLACEMENT=0
+  AC_SUBST([GETTIMEOFDAY_REPLACEMENT])
 ])
--- modules/sys_time    18 Jan 2007 16:19:13 -0000      1.2
+++ modules/sys_time    19 Jan 2007 01:35:37 -0000
@@ -23,8 +23,7 @@
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
          sed -e 's/@''HAVE_SYS_TIME_H''@/$(HAVE_SYS_TIME_H)/g' \
              -e 's|@''ABSOLUTE_SYS_TIME_H''@|$(ABSOLUTE_SYS_TIME_H)|g' \
-             -e 
's/@''GETTIMEOFDAY_CLOBBERS_LOCALTIME''@/$(GETTIMEOFDAY_CLOBBERS_LOCALTIME)/g' \
-             -e 
's/@''HAVE_GETTIMEOFDAY_POSIX_SIGNATURE''@/$(HAVE_GETTIMEOFDAY_POSIX_SIGNATURE)/g'
 \
+             -e 
's/@''GETTIMEOFDAY_REPLACEMENT''@/$(GETTIMEOFDAY_REPLACEMENT)/g' \
              -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \
              < $(srcdir)/sys_time_.h; \
        } > address@hidden



3) "gnulib-tool --create-testdir tempname" creates a configure file
in which gl_HEADER_SYS_TIME_H is expanded twice; and the
  GETTIMEOFDAY_REPLACEMENT=0
statement in the second time overwrites earlier settings to 1. This
causes the declaration of gettimeofday in sys/time.h to be skipped when
it should really be activated. This fixes it.

--- m4/sys_time_h.m4    18 Jan 2007 08:33:35 -0000      1.1
+++ m4/sys_time_h.m4    19 Jan 2007 01:35:36 -0000
@@ -9,6 +9,14 @@
 
 AC_DEFUN([gl_HEADER_SYS_TIME_H],
 [
+  dnl Use AC_REQUIRE here, so that the GETTIMEOFDAY_REPLACEMENT=0 statement
+  dnl below is expanded once only, before all GETTIMEOFDAY_REPLACEMENT=1
+  dnl statements that occur in other macros.
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H_BODY])
+])
+
+AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
+[
   AC_REQUIRE([AC_C_RESTRICT])
   AC_CHECK_HEADERS_ONCE([sys/time.h])
 



4) The tests don't compile, because
     - they use struct tm, thus need <time.h>,
     - they use suseconds_t, but this type does not exist on Cygwin,
       and its replacement has been removed from gettimeofday.m4.

--- tests/test-gettimeofday.c   18 Jan 2007 08:33:35 -0000      1.3
+++ tests/test-gettimeofday.c   19 Jan 2007 01:35:37 -0000
@@ -20,12 +20,11 @@
 #include <config.h>
 
 #include <sys/time.h>
+#include <time.h>
 
 #include <stdio.h>
 #include <string.h>
 
-suseconds_t dummy = 0; /* just to test if this type is available */
-
 int
 main (int argc, char *argv[])
 {



5) tempname now depends on the gettimeofday module.

--- m4/tempname.m4      9 Nov 2006 18:49:46 -0000       1.2
+++ m4/tempname.m4      19 Jan 2007 01:35:36 -0000
@@ -1,6 +1,6 @@
-#serial 2
+#serial 3
 
-# Copyright (C) 2006 Free Software Foundation, Inc.
+# Copyright (C) 2006-2007 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -18,6 +18,5 @@
 # Prerequisites of lib/tempname.c.
 AC_DEFUN([gl_PREREQ_TEMPNAME],
 [
-  AC_CHECK_HEADERS_ONCE([sys/time.h])
-  AC_CHECK_FUNCS_ONCE([gettimeofday])
+  :
 ])



6) Two tests for sys/time.h are now unnecessary, because the
corresponding lib/*.c files include <sys/time.h> unconditionally.

--- m4/mktime.m4        18 Jan 2007 08:33:35 -0000      1.27
+++ m4/mktime.m4        19 Jan 2007 01:35:36 -0000
@@ -1,4 +1,4 @@
-#serial 10
+#serial 11
 dnl Copyright (C) 2002, 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -13,7 +13,7 @@
 # AC_FUNC_MKTIME
 # --------------
 AC_DEFUN([AC_FUNC_MKTIME],
-[AC_CHECK_HEADERS_ONCE(sys/time.h unistd.h)
+[AC_CHECK_HEADERS_ONCE(unistd.h)
 AC_CHECK_FUNCS_ONCE(alarm)
 AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
 [AC_RUN_IFELSE([AC_LANG_SOURCE(
--- m4/strftime.m4      18 Jan 2007 08:33:35 -0000      1.38
+++ m4/strftime.m4      19 Jan 2007 01:35:36 -0000
@@ -25,7 +25,7 @@
  AC_REQUIRE([gl_TM_GMTOFF])
 
  AC_CHECK_FUNCS_ONCE(mblen mbrlen mempcpy tzset)
- AC_CHECK_HEADERS_ONCE(sys/time.h wchar.h)
+ AC_CHECK_HEADERS_ONCE(wchar.h)
 
  AC_DEFINE([my_strftime], [nstrftime],
    [Define to the name of the strftime replacement function.])


I hope these changes are OK with you. If not, feel free to revert them.

Bruno





reply via email to

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