Commit 3707f609 authored by Paul Eggert's avatar Paul Eggert

Sync from gnulib

This incorporates:
2016-05-01 mktime: port to stricter signed overflow checking
2016-05-01 mktime: speed up DEBUG_MKTIME benchmarks
2016-05-01 mktime: resurrect DEBUG_MKTIME testing
2016-05-01 mktime: simplify DEBUG_MKTIME
2016-05-01 Port mktime_internal offset to unsigned time_t
2016-04-27 xstrtol: prohibit monstrosities like "1bB"
2016-04-13 mktime: improve integer overflow checking
2016-04-13 intprops: check two's complement assumption
2016-04-13 intprops, mktime, strtol: assume two's complement
* lib/intprops.h, lib/mktime-internal.h, lib/mktime.c:
* lib/strtol.c, lib/timegm.c, m4/mktime.m4, m4/std-gnu11.m4:
Copy from gnulib.
parent 13f4efb0
......@@ -21,6 +21,7 @@
#define _GL_INTPROPS_H
#include <limits.h>
#include <verify.h>
/* Return a value with the common real type of E and V and the value of V. */
#define _GL_INT_CONVERT(e, v) (0 * (e) + (v))
......@@ -36,17 +37,6 @@
an integer. */
#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
/* True if negative values of the signed integer type T use two's
complement, ones' complement, or signed magnitude representation,
respectively. Much GNU code assumes two's complement, but some
people like to be portable to all possible C hosts. */
#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
/* True if the signed integer expression E uses two's complement. */
#define _GL_INT_TWOS_COMPLEMENT(e) (~ _GL_INT_CONVERT (e, 0) == -1)
/* True if the real type T is signed. */
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
......@@ -55,18 +45,10 @@
#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
/* Minimum and maximum values for integer types and expressions. These
macros have undefined behavior if T is signed and has padding bits.
If this is a problem for you, please let us know how to fix it for
your host. */
/* Minimum and maximum values for integer types and expressions. */
/* The maximum and minimum values for the integer type T. */
#define TYPE_MINIMUM(t) \
((t) (! TYPE_SIGNED (t) \
? (t) 0 \
: TYPE_SIGNED_MAGNITUDE (t) \
? ~ (t) 0 \
: ~ TYPE_MAXIMUM (t)))
#define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t))
#define TYPE_MAXIMUM(t) \
((t) (! TYPE_SIGNED (t) \
? (t) -1 \
......@@ -76,7 +58,7 @@
after integer promotion. E should not have side effects. */
#define _GL_INT_MINIMUM(e) \
(EXPR_SIGNED (e) \
? - _GL_INT_TWOS_COMPLEMENT (e) - _GL_SIGNED_INT_MAXIMUM (e) \
? ~ _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_CONVERT (e, 0))
#define _GL_INT_MAXIMUM(e) \
(EXPR_SIGNED (e) \
......@@ -85,8 +67,25 @@
#define _GL_SIGNED_INT_MAXIMUM(e) \
(((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1)
/* This include file assumes that signed types are two's complement without
padding bits; the above macros have undefined behavior otherwise.
If this is a problem for you, please let us know how to fix it for your host.
As a sanity check, test the assumption for some signed types that
<limits.h> bounds. */
verify (TYPE_MINIMUM (signed char) == SCHAR_MIN);
verify (TYPE_MAXIMUM (signed char) == SCHAR_MAX);
verify (TYPE_MINIMUM (short int) == SHRT_MIN);
verify (TYPE_MAXIMUM (short int) == SHRT_MAX);
verify (TYPE_MINIMUM (int) == INT_MIN);
verify (TYPE_MAXIMUM (int) == INT_MAX);
verify (TYPE_MINIMUM (long int) == LONG_MIN);
verify (TYPE_MAXIMUM (long int) == LONG_MAX);
#ifdef LLONG_MAX
verify (TYPE_MINIMUM (long long int) == LLONG_MIN);
verify (TYPE_MAXIMUM (long long int) == LLONG_MAX);
#endif
/* Return 1 if the __typeof__ keyword works. This could be done by
/* Does the __typeof__ keyword work? This could be done by
'configure', but for now it's easier to do it by hand. */
#if (2 <= __GNUC__ || defined __IBM__TYPEOF__ \
|| (0x5110 <= __SUNPRO_C && !__STDC__))
......
/* mktime variant that also uses an offset guess
Copyright 2016 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 the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, see
<http://www.gnu.org/licenses/>. */
#include <time.h>
/* mktime_offset_t is a signed type wide enough to hold a UTC offset
in seconds, and used as part of the type of the offset-guess
argument to mktime_internal. Use time_t on platforms where time_t
is signed, to be compatible with platforms like BeOS that export
this implementation detail of mktime. On platforms where time_t is
unsigned, GNU and POSIX code can assume 'int' is at least 32 bits
which is wide enough for a UTC offset. */
#if TIME_T_IS_SIGNED
typedef time_t mktime_offset_t;
#else
typedef int mktime_offset_t;
#endif
time_t mktime_internal (struct tm *,
struct tm * (*) (time_t const *, struct tm *),
time_t *);
mktime_offset_t *);
This diff is collapsed.
......@@ -121,30 +121,19 @@
/* The extra casts in the following macros work around compiler bugs,
e.g., in Cray C 5.0.3.0. */
/* True if negative values of the signed integer type T use two's
complement, ones' complement, or signed magnitude representation,
respectively. Much GNU code assumes two's complement, but some
people like to be portable to all possible C hosts. */
# define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
# define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
# define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
/* True if the arithmetic type T is signed. */
# define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
/* The maximum and minimum values for the integer type T. These
macros have undefined behavior if T is signed and has padding bits.
If this is a problem for you, please let us know how to fix it for
your host. */
# define TYPE_MINIMUM(t) \
((t) (! TYPE_SIGNED (t) \
? (t) 0 \
: TYPE_SIGNED_MAGNITUDE (t) \
? ~ (t) 0 \
: ~ TYPE_MAXIMUM (t)))
# define TYPE_MAXIMUM(t) \
((t) (! TYPE_SIGNED (t) \
? (t) -1 \
/* Minimum and maximum values for integer types.
These macros have undefined behavior for signed types that either
have padding bits or do not use two's complement. If this is a
problem for you, please let us know how to fix it for your host. */
/* The maximum and minimum values for the integer type T. */
# define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t))
# define TYPE_MAXIMUM(t) \
((t) (! TYPE_SIGNED (t) \
? (t) -1 \
: ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
# ifndef ULLONG_MAX
......
......@@ -22,7 +22,9 @@
#include <time.h>
#ifndef _LIBC
#ifdef _LIBC
typedef time_t mktime_offset_t;
#else
# undef __gmtime_r
# define __gmtime_r gmtime_r
# define __mktime_internal mktime_internal
......@@ -32,7 +34,7 @@
time_t
timegm (struct tm *tmp)
{
static time_t gmtime_offset;
static mktime_offset_t gmtime_offset;
tmp->tm_isdst = 0;
return __mktime_internal (tmp, __gmtime_r, &gmtime_offset);
}
# serial 25
# serial 26
dnl Copyright (C) 2002-2003, 2005-2007, 2009-2016 Free Software Foundation,
dnl Inc.
dnl This file is free software; the Free Software Foundation
......@@ -7,9 +7,24 @@ dnl with or without modifications, as long as this notice is preserved.
dnl From Jim Meyering.
AC_DEFUN([gl_TIME_T_IS_SIGNED],
[
AC_CACHE_CHECK([whether time_t is signed],
[gl_cv_time_t_is_signed],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <time.h>
char time_t_signed[(time_t) -1 < 0 ? 1 : -1];]])],
[gl_cv_time_t_is_signed=yes],
[gl_cv_time_t_is_signed=no])])
if test $gl_cv_time_t_is_signed = yes; then
AC_DEFINE([TIME_T_IS_SIGNED], [1], [Define to 1 if time_t is signed.])
fi
])
AC_DEFUN([gl_FUNC_MKTIME],
[
AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
AC_REQUIRE([gl_TIME_T_IS_SIGNED])
dnl We don't use AC_FUNC_MKTIME any more, because it is no longer maintained
dnl in Autoconf and because it invokes AC_LIBOBJ.
......@@ -169,7 +184,6 @@ main ()
time_t t, delta;
int i, j;
int time_t_signed_magnitude = (time_t) ~ (time_t) 0 < (time_t) -1;
int time_t_signed = ! ((time_t) 0 < (time_t) -1);
#if HAVE_DECL_ALARM
/* This test makes some buggy mktime implementations loop.
......@@ -179,11 +193,11 @@ main ()
alarm (60);
#endif
time_t_max = (! time_t_signed
time_t_max = (! TIME_T_IS_SIGNED
? (time_t) -1
: ((((time_t) 1 << (sizeof (time_t) * CHAR_BIT - 2)) - 1)
* 2 + 1));
time_t_min = (! time_t_signed
time_t_min = (! TIME_T_IS_SIGNED
? (time_t) 0
: time_t_signed_magnitude
? ~ (time_t) 0
......
# Prefer GNU C11 and C++11 to earlier versions. -*- coding: utf-8 -*-
# This implementation is taken from GNU Autoconf lib/autoconf/c.m4
# commit 739cdc82b5325402231f3f5e1a38f681fcbd1db2
# dated Tue Mar 15 09:34:11 2016 -0700.
# commit 017d5ddd82854911f0119691d91ea8a1438824d6
# dated Sun Apr 3 13:57:17 2016 -0700
# This implementation will be obsolete once we can assume Autoconf 2.70
# or later is installed everywhere a Gnulib program might be developed.
......@@ -707,7 +707,7 @@ AC_DEFUN([_AC_CXX_CXX11_TEST_BODY],
short sa[cxx11test::get_val()] = { 0 };
}
{
// Test initialiser lists
// Test initializer lists
cxx11test::testinit il = { 4323, 435234.23544 };
}
{
......@@ -801,7 +801,7 @@ dnl with extended modes being tried first.
# considers the compiler to be in ISO C++11 mode if it handles all the
# tests from the C++98 checks, plus the following: Language features
# (auto, constexpr, decltype, default/deleted constructors, delegate
# constructors, final, initialiser lists, lambda functions, nullptr,
# constructors, final, initializer lists, lambda functions, nullptr,
# override, range-based for loops, template brackets without spaces,
# unicode literals) and library features (array, memory (shared_ptr,
# weak_ptr), regex and tuple types).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment