Fix PR40190; use localtime_r, gmtime_r, add fallback implementations

From-SVN: r147985
This commit is contained in:
Janne Blomqvist 2009-05-29 23:56:20 +03:00
parent bb870b58e2
commit 2017c37012
5 changed files with 165 additions and 8 deletions

View File

@ -1,3 +1,17 @@
2009-05-29 Janne Blomqvist <jb@gcc.gnu.org>
PR libfortran/40190
* configure.ac: Check for localtime_r and gmtime_r.
* intrinsics/date_and_time.c: Add fallback implementations for
localtime_r and gmtime_r.
(date_and_time): Change to use localtime_r and gmtime_r instead of
localtime and gmtime, respectively.
(itime0): Use localtime_r instead of localtime.
(ltime_0): Likewise.
(gmtime_0): Use gmtime_r instead of gmtime.
* config.h.in: Regenerated
* configure: Regenerated.
2009-05-27 Janne Blomqvist <jb@gcc.gnu.org>
PR fortran/39178

View File

@ -426,6 +426,9 @@
/* libc includes getuid */
#undef HAVE_GETUID
/* Define to 1 if you have the `gmtime_r' function. */
#undef HAVE_GMTIME_R
/* Define if the compiler has a thread header that is non single. */
#undef HAVE_GTHR_DEFAULT
@ -507,6 +510,9 @@
/* libm includes llroundl */
#undef HAVE_LLROUNDL
/* Define to 1 if you have the `localtime_r' function. */
#undef HAVE_LOCALTIME_R
/* libm includes log */
#undef HAVE_LOG

111
libgfortran/configure vendored
View File

@ -19503,6 +19503,114 @@ fi
done
for ac_func in localtime_r gmtime_r
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5
echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
if eval "test \"\${$as_ac_var+set}\" = set"; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
if test x$gcc_no_link = xyes; then
{ { echo "$as_me:$LINENO: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&5
echo "$as_me: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&2;}
{ (exit 1); exit 1; }; }
fi
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
For example, HP-UX 11i <limits.h> declares gettimeofday. */
#define $ac_func innocuous_$ac_func
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func (); below.
Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
<limits.h> exists even on freestanding compilers. */
#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
#endif
#undef $ac_func
/* Override any gcc2 internal prototype to avoid an error. */
#ifdef __cplusplus
extern "C"
{
#endif
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char $ac_func ();
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
choke me
#else
char (*f) () = $ac_func;
#endif
#ifdef __cplusplus
}
#endif
int
main ()
{
return f != $ac_func;
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -z "$ac_c_werror_flag"
|| test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; } &&
{ ac_try='test -s conftest$ac_exeext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
eval "$as_ac_var=yes"
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
eval "$as_ac_var=no"
fi
rm -f conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
if test `eval echo '${'$as_ac_var'}'` = yes; then
cat >>confdefs.h <<_ACEOF
#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
fi
done
# Check for glibc backtrace functions
@ -34881,6 +34989,9 @@ ac_configure_args="${multilib_arg} ${ac_configure_args}"
multi_basedir="$multi_basedir"
CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
CC="$CC"
CXX="$CXX"
GFORTRAN="$GFORTRAN"
GCJ="$GCJ"
AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"

View File

@ -226,6 +226,7 @@ AC_CHECK_FUNCS(chdir strerror getlogin gethostname kill link symlink perror)
AC_CHECK_FUNCS(sleep time ttyname signal alarm ctime clock access fork execl)
AC_CHECK_FUNCS(wait setmode execvp pipe dup2 close fdopen strcasestr getrlimit)
AC_CHECK_FUNCS(gettimeofday stat fstat lstat getpwuid vsnprintf dup getcwd)
AC_CHECK_FUNCS(localtime_r gmtime_r)
# Check for glibc backtrace functions
AC_CHECK_FUNCS(backtrace backtrace_symbols)

View File

@ -48,6 +48,31 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#define abs(x) ((x)>=0 ? (x) : -(x))
#endif
/* If the re-entrant versions of localtime and gmtime are not
available, provide fallback implementations. On some targets where
the _r versions are not available, localtime and gmtime use
thread-local storage so they are threadsafe. */
#ifndef HAVE_LOCALTIME_R
static struct tm *
localtime_r (const time_t * timep, struct tm * result)
{
*result = *localtime (timep);
return result;
}
#endif
#ifndef HAVE_GMTIME_R
static struct tm *
gmtime_r (const time_t * timep, struct tm * result)
{
*result = *gmtime (timep);
return result;
}
#endif
/* DATE_AND_TIME ([DATE, TIME, ZONE, VALUES])
Description: Returns data on the real-time clock and date in a form
@ -166,8 +191,8 @@ date_and_time (char *__date, char *__time, char *__zone,
if (lt != (time_t) -1)
{
local_time = *localtime (&lt);
UTC_time = *gmtime (&lt);
localtime_r (&lt, &local_time);
gmtime_r (&lt, &UTC_time);
/* All arguments can be derived from VALUES. */
values[0] = 1900 + local_time.tm_year;
@ -361,7 +386,7 @@ itime0 (int x[3])
if (lt != (time_t) -1)
{
local_time = *localtime (&lt);
localtime_r (&lt, &local_time);
x[0] = local_time.tm_hour;
x[1] = local_time.tm_min;
@ -443,7 +468,7 @@ idate0 (int x[3])
if (lt != (time_t) -1)
{
local_time = *localtime (&lt);
localtime_r (&lt, &local_time);
x[0] = local_time.tm_mday;
x[1] = 1 + local_time.tm_mon;
@ -510,7 +535,7 @@ idate_i8 (gfc_array_i8 *__values)
/* GMTIME(STIME, TARRAY) - Non-standard
Description: Given a system time value STime, fills TArray with values
extracted from it appropriate to the GMT time zone using gmtime(3).
extracted from it appropriate to the GMT time zone using gmtime_r(3).
The array elements are as follows:
@ -530,7 +555,7 @@ gmtime_0 (const time_t * t, int x[9])
{
struct tm lt;
lt = *gmtime (t);
gmtime_r (t, &lt);
x[0] = lt.tm_sec;
x[1] = lt.tm_min;
x[2] = lt.tm_hour;
@ -602,7 +627,7 @@ gmtime_i8 (GFC_INTEGER_8 * t, gfc_array_i8 * tarray)
/* LTIME(STIME, TARRAY) - Non-standard
Description: Given a system time value STime, fills TArray with values
extracted from it appropriate to the local time zone using localtime(3).
extracted from it appropriate to the local time zone using localtime_r(3).
The array elements are as follows:
@ -622,7 +647,7 @@ ltime_0 (const time_t * t, int x[9])
{
struct tm lt;
lt = *localtime (t);
localtime_r (t, &lt);
x[0] = lt.tm_sec;
x[1] = lt.tm_min;
x[2] = lt.tm_hour;