bug-gnulib
[Top][All Lists]
Advanced

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

Re: #define FOO rpl_FOO in config.h


From: John W. Eaton
Subject: Re: #define FOO rpl_FOO in config.h
Date: Wed, 30 Nov 2011 03:14:14 -0500

On 29-Nov-2011, Eric Blake wrote:

| On 11/29/2011 01:01 AM, John W. Eaton wrote:
| > While trying to cross compile Octave for MinGW, I hit the following
| > errors:
| > 
| >   In file included from /home/jwe/src/octave/liboctave/oct-time.h:26:0,
| >                    from /home/jwe/src/octave/liboctave/file-stat.h:28,
| >                    from /home/jwe/src/octave/liboctave/file-ops.cc:43:
| >   /usr/include/c++/4.6/ctime:72:11: error: '::gmtime' has not been declared
| >   /usr/include/c++/4.6/ctime:73:11: error: '::localtime' has not been 
declared
| > 
| > 
| > Would it be possible to handle these definitions in gnulib's time.h
| > instead of inserting them in config.h?
| 
| Yes, we need to modernize this module to get rid of the in-config.h
| replacements, like we have done for other modules.  Would you like to
| try helping in that process?  See commit 60b73b05 for an example of
| where we did the same for mktime().

Hmm, it seems like there is a bit more to it than that...

My first attempt is attached below.  I can try to provide a complete
changeset with commit log info later if this diff is heading in the
right direction.

At best, I have about half a clue about what is actually needed here.
For example, is it necessary to provide declarations for gmtime and
localtime in case the system does not have them?  Should we check for
the functions or for declarations directly?  I couldn't tell what is
appropriate by looking at other modules.  Some appear to check for the
function and provide the declaration based on the existence of the
function (strptime in strptime.m4, for example) while others check for
declarations directly (localtime_r in time_r.m4, for example).

Also, I think the reason that we didn't notice this problem before now
is that it only affects cross compiling because of this code in
gettimeofday.m4:

     dnl When crosscompiling, assume it is broken.
     [gl_cv_func_gettimeofday_clobber=yes])])

I guess MinGW does not actually have this problem, but this path is
taken because of cross compiling.

jwe

diff --git a/lib/time.in.h b/lib/time.in.h
index ca852e8..51bf0d7 100644
--- a/lib/time.in.h
+++ b/lib/time.in.h
@@ -188,6 +188,48 @@ _GL_CXXALIASWARN (gmtime_r);
 #  endif
 # endif
 
+/* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
+   <http://www.opengroup.org/susv3xsh/localtime.html> and
+   <http://www.opengroup.org/susv3xsh/gmtime.html>.  */
+# if @REPLACE_LOCALTIME@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef localtime
+#   define localtime rpl_localtime
+#  endif
+_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *restrict __timer,
+                                           struct tm *restrict __result)
+                                          _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *restrict __timer,
+                                             struct tm *restrict __result));
+# else
+#  if ! @HAVE_LOCALTIME@
+_GL_FUNCDECL_SYS (localtime, struct tm *, (time_t const *restrict __timer,
+                                           struct tm *restrict __result)
+                                          _GL_ARG_NONNULL ((1, 2)));
+#  endif
+_GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *restrict __timer,
+                                           struct tm *restrict __result));
+# endif
+# if @REPLACE_GMTIME@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef gmtime
+#   define gmtime rpl_gmtime
+#  endif
+_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *restrict __timer,
+                                        struct tm *restrict __result)
+                                       _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *restrict __timer,
+                                        struct tm *restrict __result));
+# else
+#  if ! @HAVE_GMTIME@
+_GL_FUNCDECL_SYS (gmtime, struct tm *, (time_t const *restrict __timer,
+                                        struct tm *restrict __result)
+                                       _GL_ARG_NONNULL ((1, 2)));
+#  endif
+_GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *restrict __timer,
+                                        struct tm *restrict __result));
+# endif
+
 /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
    the resulting broken-down time into TM.  See
    <http://www.opengroup.org/susv3xsh/strptime.html>.  */
diff --git a/m4/gettimeofday.m4 b/m4/gettimeofday.m4
index 47c1e1d..b79ee9a 100644
--- a/m4/gettimeofday.m4
+++ b/m4/gettimeofday.m4
@@ -112,10 +112,15 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
 ])
 
 AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
-  AC_DEFINE([gmtime], [rpl_gmtime],
-    [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_CHECK_FUNCS_ONCE([gmtime localtime])
+  if test $ac_cv_func_gmtime != yes; then
+    HAVE_GMTIME=0
+  fi
+  if test $ac_cv_func_localtime != yes; then
+    HAVE_LOCALTIME=0
+  fi
+  REPLACE_GMTIME=1
+  REPLACE_LOCALTIME=1
 ])
 
 # Prerequisites of lib/gettimeofday.c.
diff --git a/m4/time_h.m4 b/m4/time_h.m4
index 3454b23..c58c97f 100644
--- a/m4/time_h.m4
+++ b/m4/time_h.m4
@@ -102,6 +102,8 @@ AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
   dnl If another module says to replace or to not replace, do that.
   dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
   dnl this lets maintainers check for portability.
+  REPLACE_GMTIME=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_GMTIME])
+  REPLACE_LOCALTIME=GNULIB_PORTCHECK;    AC_SUBST([REPLACE_LOCALTIME])
   REPLACE_LOCALTIME_R=GNULIB_PORTCHECK;  AC_SUBST([REPLACE_LOCALTIME_R])
   REPLACE_MKTIME=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_MKTIME])
   REPLACE_NANOSLEEP=GNULIB_PORTCHECK;    AC_SUBST([REPLACE_NANOSLEEP])
diff --git a/modules/time b/modules/time
index 8e946fc..50fb88e 100644
--- a/modules/time
+++ b/modules/time
@@ -7,6 +7,7 @@ m4/time_h.m4
 
 Depends-on:
 extensions
+gettimeofday
 include_next
 snippet/arg-nonnull
 snippet/c++defs
@@ -38,6 +39,8 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(ARG_NONNULL_H) $(
              -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \
              -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \
              -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \
+             -e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \
+             -e 's|@''REPLACE_LOCALTIME''@|$(REPLACE_LOCALTIME)|g' \
              -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \
              -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \
              -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \

reply via email to

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