bug-gnulib
[Top][All Lists]
Advanced

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

Re: failure to include C++'s <ctype> when gmtime and localtime are repla


From: Paul Eggert
Subject: Re: failure to include C++'s <ctype> when gmtime and localtime are replaced by gnulib
Date: Tue, 17 Dec 2013 12:45:14 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

On 12/17/2013 11:06 AM, Paul Eggert wrote:
> Thanks, I don't use C++ so I can't really review that, but nobody
> else has commented so I installed it into gnulib.
>

Well, I spoke too quickly; that patch broke Emacs.
I installed the following further patch to try to fix things.
It's a bit of a messy area.

---
 ChangeLog          | 20 ++++++++++++++++++++
 lib/time.in.h      | 39 +++++++++++++++++++--------------------
 m4/gettimeofday.m4 |  9 +--------
 m4/time_h.m4       | 15 ++++++++++-----
 modules/time       |  3 +--
 5 files changed, 51 insertions(+), 35 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f3e5ced..1753c8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2013-12-17  Paul Eggert  <address@hidden>
+
+    gettimeofday: port recent C++ fix to Emacs
+    Without this further patch, Emacs won't build due to
+    the portcheck failing.  Also, this simplifies the patch a bit.
+    * lib/time.in.h (localtime, gmtime): Don't replace unless
+    GNULIB_GETTIMEOFDAY.  Treat them more like mktime.
+    * lib/time.in.h (localtime, gmtime):
+    * m4/gettimeofday.m4 (gl_GETTIMEOFDAY_REPLACE_LOCALTIME):
+    * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS):
+    * modules/time (time.h):
+    Don't worry about about the possibility of localtime and gmtime
+    being absent; they're present in all C libraries we know about.
+    * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS):
+    Don't assume sys_time is present and has been initialized.
+    Instead, use a hack that should work even if it hasn't been.
+    Don't use a portcheck for gmtime or localtime; this supports
+    the hack.
+    * modules/time (time.h): Substitute GNULIB_GETTIMEOFDAY.
+
 2013-12-17  John W. Eaton  <address@hidden>
 
     gettimeofday: fix C++ crosscompilation
diff --git a/lib/time.in.h b/lib/time.in.h
index 157896f..dab0223 100644
--- a/lib/time.in.h
+++ b/lib/time.in.h
@@ -190,35 +190,34 @@ _GL_CXXALIASWARN (gmtime_r);
 /* 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
+# if @GNULIB_GETTIMEOFDAY@
+#  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 *__timer)
                                   _GL_ARG_NONNULL ((1)));
 _GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer));
-# else
-#  if ! @HAVE_LOCALTIME@
-_GL_FUNCDECL_SYS (localtime, struct tm *, (time_t const *__timer)
-                                          _GL_ARG_NONNULL ((1)));
-#  endif
+#  else
 _GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
-# endif
-# if @REPLACE_GMTIME@
-#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#   undef gmtime
-#   define gmtime rpl_gmtime
 #  endif
+_GL_CXXALIASWARN (localtime);
+# endif
+
+# if @GNULIB_GETTIMEOFDAY@
+#  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 *__timer)
                                        _GL_ARG_NONNULL ((1)));
 _GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer));
-# else
-#  if ! @HAVE_GMTIME@
-_GL_FUNCDECL_SYS (gmtime, struct tm *, (time_t const *__timer)
-                                       _GL_ARG_NONNULL ((1)));
-#  endif
+#  else
 _GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer));
+#  endif
+_GL_CXXALIASWARN (gmtime);
 # endif
 
 /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
diff --git a/m4/gettimeofday.m4 b/m4/gettimeofday.m4
index e4682bd..f48ef43 100644
--- a/m4/gettimeofday.m4
+++ b/m4/gettimeofday.m4
@@ -1,4 +1,4 @@
-# serial 20
+# serial 21
 
 # Copyright (C) 2001-2003, 2005, 2007, 2009-2013 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -127,13 +127,6 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
 ])
 
 AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
-  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
 ])
diff --git a/m4/time_h.m4 b/m4/time_h.m4
index 8675dd9..3fefb01 100644
--- a/m4/time_h.m4
+++ b/m4/time_h.m4
@@ -2,7 +2,7 @@
 
 # Copyright (C) 2000-2001, 2003-2007, 2009-2013 Free Software Foundation, Inc.
 
-# serial 7
+# serial 8
 
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -96,18 +96,23 @@ AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
   GNULIB_TIME_R=0;                       AC_SUBST([GNULIB_TIME_R])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_DECL_LOCALTIME_R=1;               AC_SUBST([HAVE_DECL_LOCALTIME_R])
-  HAVE_GMTIME=1;                         AC_SUBST([HAVE_GMTIME])
-  HAVE_LOCALTIME=1;                      AC_SUBST([HAVE_LOCALTIME])
   HAVE_NANOSLEEP=1;                      AC_SUBST([HAVE_NANOSLEEP])
   HAVE_STRPTIME=1;                       AC_SUBST([HAVE_STRPTIME])
   HAVE_TIMEGM=1;                         AC_SUBST([HAVE_TIMEGM])
   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])
   REPLACE_TIMEGM=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_TIMEGM])
+
+  dnl Hack so that the time module doesn't depend on the sys_time module.
+  dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent.
+  : ${GNULIB_GETTIMEOFDAY=0};            AC_SUBST([GNULIB_GETTIMEOFDAY])
+  dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME
+  dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier
+  dnl is no longer a big deal.
+  REPLACE_GMTIME=0;                      AC_SUBST([REPLACE_GMTIME])
+  REPLACE_LOCALTIME=0;                   AC_SUBST([REPLACE_LOCALTIME])
 ])
diff --git a/modules/time b/modules/time
index c58b933..fd3c05d 100644
--- a/modules/time
+++ b/modules/time
@@ -30,14 +30,13 @@ time.h: time.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H) $(
           -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
           -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
           -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \
+          -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \
           -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \
           -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \
           -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \
           -e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \
           -e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \
           -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \
-          -e 's|@''HAVE_LOCALTIME''@|$(HAVE_LOCALTIME)|g' \
-          -e 's|@''HAVE_GMTIME''@|$(HAVE_GMTIME)|g' \
           -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \
           -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \
           -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \
-- 
1.8.3.1





reply via email to

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