[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gnulib problem with mktime & ctime interaction
From: |
Bruno Haible |
Subject: |
Re: gnulib problem with mktime & ctime interaction |
Date: |
Mon, 27 Jul 2009 21:04:28 +0200 |
User-agent: |
KMail/1.9.9 |
Ross McFarland wrote:
> when using gnulib's mktime test any cpp file that #includes ctime will
> receive the following errors:
>
> In file included from time.cc:6:
> /usr/include/c++/4.3/ctime:73: error: ‘::mktime’ has not been declared
> time.cc: In function ‘int main()’:
> time.cc:11: error: ‘mktime’ was not declared in this scope
> ...
>
> the problem is that ctime does the following:
>
> ...
> #include <time.h>
> ...
> #undef mktime
> ...
> using ::mktime
> ...
>
> the undef mktime gets rid of the config.h mapping of mktime to
> rpl_mktime and when using ::mktime happens there's no longer a mktime
> symbol.
>
> attached is a ~minimal test program that exhibits the problem
Thanks. Even more minimally:
$ ./gnulib-tool --create-testdir --dir=/tmp/testdir mktime
$ cat > foo.cc <<EOF
#include <config.h>
#include <ctime>
EOF
$ (cd /tmp/testdir && ac_cv_func_working_mktime=no ./configure && make)
$ gcc -I/tmp/testdir -I/tmp/testdir/gllib -c foo.cc
In file included from foo.cc:2:
/usr/include/c++/4.3/ctime:73: error: ‘::mktime’ has not been declared
Jim, here is a proposed fix. I verified that it fixes the problem. The
advantage of the newer idiom, compared to the old idiom that defined the
replacements in config.h, is that the declaration of the non-rpl function
(from the system header file) is preserved. OK to commit?
2009-07-27 Bruno Haible <address@hidden>
Fix compilation error when <ctime> is used and mktime is replaced.
* lib/time.in.h (mktime): New declaration.
* m4/mktime.m4 (gl_FUNC_MKTIME): Require gl_HEADER_TIME_H_DEFAULTS. Set
REPLACE_MKTIME instead of defining mktime in config.h.
* m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize REPLACE_MKTIME.
* modules/time (Makefile.am): Substitute REPLACE_MKTIME.
Reported by Ross McFarland <address@hidden>.
--- lib/time.in.h.orig 2009-07-27 20:59:40.000000000 +0200
+++ lib/time.in.h 2009-07-27 20:55:18.000000000 +0200
@@ -1,6 +1,6 @@
/* A more-standard <time.h>.
- Copyright (C) 2007-2008 Free Software Foundation, Inc.
+ Copyright (C) 2007-2009 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -66,6 +66,12 @@
int nanosleep (struct timespec const *__rqtp, struct timespec *__rmtp);
# endif
+/* Return the 'time_t' representation of TP and normalize TP. */
+# if @REPLACE_MKTIME@
+# define mktime rpl_mktime
+extern time_t mktime (struct tm *__tp);
+# endif
+
/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
<http://www.opengroup.org/susv3xsh/localtime_r.html> and
<http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
--- m4/mktime.m4.orig 2009-07-27 20:59:40.000000000 +0200
+++ m4/mktime.m4 2009-07-27 20:57:25.000000000 +0200
@@ -215,11 +215,11 @@
AC_DEFUN([gl_FUNC_MKTIME],
[
+ AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
AC_FUNC_MKTIME
dnl Note: AC_FUNC_MKTIME does AC_LIBOBJ([mktime]).
if test $ac_cv_func_working_mktime = no; then
- AC_DEFINE([mktime], [rpl_mktime],
- [Define to rpl_mktime if the replacement function should be used.])
+ REPLACE_MKTIME=1
gl_PREREQ_MKTIME
fi
])
--- m4/time_h.m4.orig 2009-07-27 20:59:40.000000000 +0200
+++ m4/time_h.m4 2009-07-27 20:56:46.000000000 +0200
@@ -1,7 +1,6 @@
# Configure a more-standard replacement for <time.h>.
-# Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2007 Free Software
-# Foundation, Inc.
+# Copyright (C) 2000-2001, 2003-2007, 2009 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -30,6 +29,7 @@
dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
dnl this lets maintainers check for portability.
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_STRPTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRPTIME])
REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
--- modules/time.orig 2009-07-27 20:59:40.000000000 +0200
+++ modules/time 2009-07-27 20:51:42.000000000 +0200
@@ -24,6 +24,7 @@
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
-e 's|@NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \
-e 's|@REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \
+ -e 's|@REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \
-e 's|@REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \
-e 's|@REPLACE_STRPTIME''@|$(REPLACE_STRPTIME)|g' \
-e 's|@REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \