1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-23 10:34:07 +00:00

Merge from gnulib

This incorporates:
2016-11-15 sys_time: add gnulib::timeval for C++
2016-11-14 snippet/c++defs: fix real-floating arg functions in C++ mode
2016-11-13 strftime: don't use __THROW
2016-11-12 strftime: tune %q
2016-11-12 Merge strftime.c changes from glibc
2016-11-09 manywarnings: fix -Wno-missing-field-initializers detection
2016-11-05 strftime,strptime: support %q to represent the quarter

The glibc changes in turn incorporate the following strftime.c changes:
2015-10-20 Convert misc function definitions to prototype style
2015-09-26 [BZ #18985] out of range data to strftime() causes segfault
2010-01-09 Add support for XPG7 testing
2009-10-30 Implement Burmese language locale for Myanmar
2008-06-13 [BZ #6612] pass reference to tzset_called around
2007-10-16 [BZ #5184] Add tzset_called argument

* build-aux/snippet/c++defs.h, lib/strftime.c, lib/sys_time.in.h:
* m4/manywarnings.m4: Copy from gnulib.
This commit is contained in:
Paul Eggert 2016-11-19 16:00:57 -08:00
parent 493a8f33ba
commit bbd84f86bc
4 changed files with 164 additions and 87 deletions

View File

@ -17,6 +17,15 @@
#ifndef _GL_CXXDEFS_H
#define _GL_CXXDEFS_H
/* Begin/end the GNULIB_NAMESPACE namespace. */
#if defined __cplusplus && defined GNULIB_NAMESPACE
# define _GL_BEGIN_NAMESPACE namespace GNULIB_NAMESPACE {
# define _GL_END_NAMESPACE }
#else
# define _GL_BEGIN_NAMESPACE
# define _GL_END_NAMESPACE
#endif
/* The three most frequent use cases of these macros are:
* For providing a substitute for a function that is missing on some
@ -111,14 +120,22 @@
that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
Example:
_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
*/
Wrapping rpl_func in an object with an inline conversion operator
avoids a reference to rpl_func unless GNULIB_NAMESPACE::func is
actually used in the program. */
#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
_GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
#if defined __cplusplus && defined GNULIB_NAMESPACE
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
namespace GNULIB_NAMESPACE \
{ \
rettype (*const func) parameters = ::rpl_func; \
static const struct _gl_ ## func ## _wrapper \
{ \
typedef rettype (*type) parameters; \
inline type rpl () const { return ::rpl_func; } \
inline operator type () const { return rpl (); } \
} func = {}; \
} \
_GL_EXTERN_C int _gl_cxxalias_dummy
#else
@ -135,8 +152,13 @@
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
namespace GNULIB_NAMESPACE \
{ \
rettype (*const func) parameters = \
reinterpret_cast<rettype(*)parameters>(::rpl_func); \
static const struct _gl_ ## func ## _wrapper \
{ \
typedef rettype (*type) parameters; \
inline type rpl () const \
{ return reinterpret_cast<type>(::rpl_func); } \
inline operator type () const { return rpl (); } \
} func = {}; \
} \
_GL_EXTERN_C int _gl_cxxalias_dummy
#else
@ -150,18 +172,20 @@
is defined.
Example:
_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
*/
Wrapping func in an object with an inline conversion operator
avoids a reference to func unless GNULIB_NAMESPACE::func is
actually used in the program. */
#if defined __cplusplus && defined GNULIB_NAMESPACE
/* If we were to write
rettype (*const func) parameters = ::func;
like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
better (remove an indirection through a 'static' pointer variable),
but then the _GL_CXXALIASWARN macro below would cause a warning not only
for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
namespace GNULIB_NAMESPACE \
{ \
static rettype (*func) parameters = ::func; \
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
namespace GNULIB_NAMESPACE \
{ \
static const struct _gl_ ## func ## _wrapper \
{ \
typedef rettype (*type) parameters; \
inline type rpl () const { return ::func; } \
inline operator type () const { return rpl (); } \
} func = {}; \
} \
_GL_EXTERN_C int _gl_cxxalias_dummy
#else
@ -178,8 +202,13 @@
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
namespace GNULIB_NAMESPACE \
{ \
static rettype (*func) parameters = \
reinterpret_cast<rettype(*)parameters>(::func); \
static const struct _gl_ ## func ## _wrapper \
{ \
typedef rettype (*type) parameters; \
inline type rpl () const \
{ return reinterpret_cast<type>(::func); } \
inline operator type () const { return rpl (); }\
} func = {}; \
} \
_GL_EXTERN_C int _gl_cxxalias_dummy
#else
@ -202,9 +231,15 @@
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
namespace GNULIB_NAMESPACE \
{ \
static rettype (*func) parameters = \
reinterpret_cast<rettype(*)parameters>( \
(rettype2(*)parameters2)(::func)); \
static const struct _gl_ ## func ## _wrapper \
{ \
typedef rettype (*type) parameters; \
\
inline type rpl () const \
{ return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); }\
\
inline operator type () const { return rpl (); } \
} func = {}; \
} \
_GL_EXTERN_C int _gl_cxxalias_dummy
#else

View File

@ -1,22 +1,22 @@
/* Copyright (C) 1991-2001, 2003-2007, 2009-2016 Free Software Foundation, Inc.
/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@prep.ai.mit.edu.
The GNU C Library 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 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,
The GNU C Library 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.
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/>. */
You should have received a copy of the GNU General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifdef _LIBC
# define USE_IN_EXTENDED_LOCALE_MODEL 1
# define HAVE_STRUCT_ERA_ENTRY 1
# define HAVE_TM_GMTOFF 1
# define HAVE_TM_ZONE 1
@ -63,10 +63,10 @@ extern char *tzname[];
#endif
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#ifdef COMPILE_WIDE
# include <endian.h>
@ -247,11 +247,11 @@ extern char *tzname[];
# undef _NL_CURRENT
# define _NL_CURRENT(category, item) \
(current->values[_NL_ITEM_INDEX (item)].string)
# define LOCALE_PARAM , __locale_t loc
# define LOCALE_ARG , loc
# define LOCALE_PARAM_PROTO , __locale_t loc
# define HELPER_LOCALE_ARG , current
#else
# define LOCALE_PARAM_PROTO
# define LOCALE_PARAM
# define LOCALE_ARG
# ifdef _LIBC
# define HELPER_LOCALE_ARG , _NL_CURRENT_DATA (LC_TIME)
@ -304,18 +304,22 @@ fwrite_uppcase (FILE *fp, const CHAR_T *src, size_t len)
}
}
#else
static CHAR_T *memcpy_lowcase (CHAR_T *dest, const CHAR_T *src,
size_t len LOCALE_PARAM);
static CHAR_T *
memcpy_lowcase (CHAR_T *dest, const CHAR_T *src,
size_t len LOCALE_PARAM_PROTO)
memcpy_lowcase (CHAR_T *dest, const CHAR_T *src, size_t len LOCALE_PARAM)
{
while (len-- > 0)
dest[len] = TOLOWER ((UCHAR_T) src[len], loc);
return dest;
}
static CHAR_T *memcpy_uppcase (CHAR_T *dest, const CHAR_T *src,
size_t len LOCALE_PARAM);
static CHAR_T *
memcpy_uppcase (CHAR_T *dest, const CHAR_T *src,
size_t len LOCALE_PARAM_PROTO)
memcpy_uppcase (CHAR_T *dest, const CHAR_T *src, size_t len LOCALE_PARAM)
{
while (len-- > 0)
dest[len] = TOUPPER ((UCHAR_T) src[len], loc);
@ -328,6 +332,7 @@ memcpy_uppcase (CHAR_T *dest, const CHAR_T *src,
/* Yield the difference between *A and *B,
measured in seconds, ignoring leap seconds. */
# define tm_diff ftime_tm_diff
static int tm_diff (const struct tm *, const struct tm *);
static int
tm_diff (const struct tm *a, const struct tm *b)
{
@ -359,6 +364,7 @@ tm_diff (const struct tm *a, const struct tm *b)
#define ISO_WEEK_START_WDAY 1 /* Monday */
#define ISO_WEEK1_WDAY 4 /* Thursday */
#define YDAY_MINIMUM (-366)
static int iso_week_days (int, int);
#ifdef __GNUC__
__inline__
#endif
@ -401,17 +407,41 @@ iso_week_days (int yday, int wday)
# define ns 0
#endif
static size_t __strftime_internal (STREAM_OR_CHAR_T *, STRFTIME_ARG (size_t)
const CHAR_T *, const struct tm *,
bool, bool *
extra_args_spec LOCALE_PARAM);
/* Just like my_strftime, below, but with one more parameter, UPCASE,
to indicate that the result should be converted to upper case. */
/* Write information from TP into S according to the format
string FORMAT, writing no more that MAXSIZE characters
(including the terminating '\0') and returning number of
characters written. If S is NULL, nothing will be written
anywhere, so to determine how many characters would be
written, use NULL for S and (size_t) -1 for MAXSIZE. */
size_t
my_strftime (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
const CHAR_T *format,
const struct tm *tp extra_args_spec LOCALE_PARAM)
{
bool tzset_called = false;
return __strftime_internal (s, STRFTIME_ARG (maxsize) format, tp,
false, &tzset_called extra_args LOCALE_ARG);
}
#if defined _LIBC && ! FPRINTFTIME
libc_hidden_def (my_strftime)
#endif
/* Just like my_strftime, above, but with two more parameters.
UPCASE indicate that the result should be converted to upper case,
and *TZSET_CALLED indicates whether tzset has been called here. */
static size_t
strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
STRFTIME_ARG (size_t maxsize)
const CHAR_T *format,
const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO)
__strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
const CHAR_T *format,
const struct tm *tp, bool upcase, bool *tzset_called
extra_args_spec LOCALE_PARAM)
{
#if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL
struct locale_data *const current = loc->__locales[LC_TIME];
struct __locale_data *const current = loc->__locales[LC_TIME];
#endif
#if FPRINTFTIME
size_t maxsize = (size_t) -1;
@ -426,13 +456,17 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
only a few elements. Dereference the pointers only if the format
requires this. Then it is ok to fail if the pointers are invalid. */
# define a_wkday \
((const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(ABDAY_1) + tp->tm_wday))
((const CHAR_T *) (tp->tm_wday < 0 || tp->tm_wday > 6 \
? "?" : _NL_CURRENT (LC_TIME, NLW(ABDAY_1) + tp->tm_wday)))
# define f_wkday \
((const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(DAY_1) + tp->tm_wday))
((const CHAR_T *) (tp->tm_wday < 0 || tp->tm_wday > 6 \
? "?" : _NL_CURRENT (LC_TIME, NLW(DAY_1) + tp->tm_wday)))
# define a_month \
((const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(ABMON_1) + tp->tm_mon))
((const CHAR_T *) (tp->tm_mon < 0 || tp->tm_mon > 11 \
? "?" : _NL_CURRENT (LC_TIME, NLW(ABMON_1) + tp->tm_mon)))
# define f_month \
((const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(MON_1) + tp->tm_mon))
((const CHAR_T *) (tp->tm_mon < 0 || tp->tm_mon > 11 \
? "?" : _NL_CURRENT (LC_TIME, NLW(MON_1) + tp->tm_mon)))
# define ampm \
((const CHAR_T *) _NL_CURRENT (LC_TIME, tp->tm_hour > 11 \
? NLW(PM_STR) : NLW(AM_STR)))
@ -482,16 +516,22 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
# if !HAVE_TM_ZONE
/* Infer the zone name from *TZ instead of from TZNAME. */
tzname_vec = tz->tzname_copy;
# endif
/* POSIX.1 requires that local time zone information be used as
though strftime called tzset. */
# if HAVE_TZSET
tzset ();
# endif
}
/* The tzset() call might have changed the value. */
if (!(zone && *zone) && tp->tm_isdst >= 0)
zone = tzname_vec[tp->tm_isdst != 0];
{
/* POSIX.1 requires that local time zone information be used as
though strftime called tzset. */
# if HAVE_TZSET
if (!*tzset_called)
{
tzset ();
*tzset_called = true;
}
# endif
zone = tzname_vec[tp->tm_isdst != 0];
}
#endif
if (! zone)
zone = "";
@ -801,14 +841,15 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
subformat:
{
size_t len = strftime_case_ (to_uppcase,
NULL, STRFTIME_ARG ((size_t) -1)
subfmt,
tp extra_args LOCALE_ARG);
add (len, strftime_case_ (to_uppcase, p,
STRFTIME_ARG (maxsize - i)
subfmt,
tp extra_args LOCALE_ARG));
size_t len = __strftime_internal (NULL, STRFTIME_ARG ((size_t) -1)
subfmt,
tp, to_uppcase, tzset_called
extra_args LOCALE_ARG);
add (len, __strftime_internal (p,
STRFTIME_ARG (maxsize - i)
subfmt,
tp, to_uppcase, tzset_called
extra_args LOCALE_ARG));
}
break;
@ -845,8 +886,6 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
#endif
case L_('C'):
if (modifier == L_('O'))
goto bad_format;
if (modifier == L_('E'))
{
#if HAVE_STRUCT_ERA_ENTRY
@ -1115,6 +1154,10 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
goto underlying_strftime;
#endif
case L_('q'): /* GNU extension. */
DO_SIGNED_NUMBER (1, false, ((tp->tm_mon * 11) >> 5) + 1);
break;
case L_('R'):
subfmt = L_("%H:%M");
goto subformat;
@ -1364,6 +1407,16 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
struct tm ltm;
time_t lt;
/* POSIX.1 requires that local time zone information be used as
though strftime called tzset. */
# if HAVE_TZSET
if (!*tzset_called)
{
tzset ();
*tzset_called = true;
}
# endif
ltm = *tp;
lt = mktime_z (tz, &ltm);
@ -1444,22 +1497,3 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
return i;
}
/* Write information from TP into S according to the format
string FORMAT, writing no more that MAXSIZE characters
(including the terminating '\0') and returning number of
characters written. If S is NULL, nothing will be written
anywhere, so to determine how many characters would be
written, use NULL for S and (size_t) -1 for MAXSIZE. */
size_t
my_strftime (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
const CHAR_T *format,
const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO)
{
return strftime_case_ (false, s, STRFTIME_ARG (maxsize)
format, tp extra_args LOCALE_ARG);
}
#if defined _LIBC && ! FPRINTFTIME
libc_hidden_def (my_strftime)
#endif

View File

@ -109,6 +109,13 @@ _GL_CXXALIAS_SYS_CAST (gettimeofday, int,
(struct timeval *restrict, void *restrict));
# endif
_GL_CXXALIASWARN (gettimeofday);
# if defined __cplusplus && defined GNULIB_NAMESPACE
namespace GNULIB_NAMESPACE {
typedef ::timeval
#undef timeval
timeval;
}
# endif
#elif defined GNULIB_POSIXCHECK
# undef gettimeofday
# if HAVE_RAW_DECL_GETTIMEOFDAY

View File

@ -62,10 +62,11 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
CFLAGS="$CFLAGS -W -Werror"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[void f (void)
[[int f (void)
{
typedef struct { int a; int b; } s_t;
s_t s1 = { 0, };
return s1.b;
}
]],
[[]])],