1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-23 14:10:28 -08: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 #ifndef _GL_CXXDEFS_H
#define _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: /* The three most frequent use cases of these macros are:
* For providing a substitute for a function that is missing on some * 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. that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
Example: Example:
_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...)); _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) \ #define _GL_CXXALIAS_RPL(func,rettype,parameters) \
_GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters) _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
#if defined __cplusplus && defined GNULIB_NAMESPACE #if defined __cplusplus && defined GNULIB_NAMESPACE
# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \ # define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
namespace GNULIB_NAMESPACE \ 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 _GL_EXTERN_C int _gl_cxxalias_dummy
#else #else
@ -135,8 +152,13 @@
# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \ # define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
namespace GNULIB_NAMESPACE \ namespace GNULIB_NAMESPACE \
{ \ { \
rettype (*const func) parameters = \ static const struct _gl_ ## func ## _wrapper \
reinterpret_cast<rettype(*)parameters>(::rpl_func); \ { \
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 _GL_EXTERN_C int _gl_cxxalias_dummy
#else #else
@ -150,18 +172,20 @@
is defined. is defined.
Example: Example:
_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...)); _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 defined __cplusplus && defined GNULIB_NAMESPACE
/* If we were to write # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
rettype (*const func) parameters = ::func; namespace GNULIB_NAMESPACE \
like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls { \
better (remove an indirection through a 'static' pointer variable), static const struct _gl_ ## func ## _wrapper \
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. */ typedef rettype (*type) parameters; \
# define _GL_CXXALIAS_SYS(func,rettype,parameters) \ inline type rpl () const { return ::func; } \
namespace GNULIB_NAMESPACE \ inline operator type () const { return rpl (); } \
{ \ } func = {}; \
static rettype (*func) parameters = ::func; \
} \ } \
_GL_EXTERN_C int _gl_cxxalias_dummy _GL_EXTERN_C int _gl_cxxalias_dummy
#else #else
@ -178,8 +202,13 @@
# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \ # define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
namespace GNULIB_NAMESPACE \ namespace GNULIB_NAMESPACE \
{ \ { \
static rettype (*func) parameters = \ static const struct _gl_ ## func ## _wrapper \
reinterpret_cast<rettype(*)parameters>(::func); \ { \
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 _GL_EXTERN_C int _gl_cxxalias_dummy
#else #else
@ -202,9 +231,15 @@
# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \ # define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
namespace GNULIB_NAMESPACE \ namespace GNULIB_NAMESPACE \
{ \ { \
static rettype (*func) parameters = \ static const struct _gl_ ## func ## _wrapper \
reinterpret_cast<rettype(*)parameters>( \ { \
(rettype2(*)parameters2)(::func)); \ 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 _GL_EXTERN_C int _gl_cxxalias_dummy
#else #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. The GNU C Library is free software; you can redistribute it and/or
Bugs can be reported to bug-glibc@prep.ai.mit.edu. 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 The GNU C Library is distributed in the hope that it will be useful,
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 but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
GNU General Public License for more details. General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public
along with this program. If not, see <http://www.gnu.org/licenses/>. */ License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifdef _LIBC #ifdef _LIBC
# define USE_IN_EXTENDED_LOCALE_MODEL 1
# define HAVE_STRUCT_ERA_ENTRY 1 # define HAVE_STRUCT_ERA_ENTRY 1
# define HAVE_TM_GMTOFF 1 # define HAVE_TM_GMTOFF 1
# define HAVE_TM_ZONE 1 # define HAVE_TM_ZONE 1
@ -63,10 +63,10 @@ extern char *tzname[];
#endif #endif
#include <limits.h> #include <limits.h>
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdbool.h>
#ifdef COMPILE_WIDE #ifdef COMPILE_WIDE
# include <endian.h> # include <endian.h>
@ -247,11 +247,11 @@ extern char *tzname[];
# undef _NL_CURRENT # undef _NL_CURRENT
# define _NL_CURRENT(category, item) \ # define _NL_CURRENT(category, item) \
(current->values[_NL_ITEM_INDEX (item)].string) (current->values[_NL_ITEM_INDEX (item)].string)
# define LOCALE_PARAM , __locale_t loc
# define LOCALE_ARG , loc # define LOCALE_ARG , loc
# define LOCALE_PARAM_PROTO , __locale_t loc
# define HELPER_LOCALE_ARG , current # define HELPER_LOCALE_ARG , current
#else #else
# define LOCALE_PARAM_PROTO # define LOCALE_PARAM
# define LOCALE_ARG # define LOCALE_ARG
# ifdef _LIBC # ifdef _LIBC
# define HELPER_LOCALE_ARG , _NL_CURRENT_DATA (LC_TIME) # 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 #else
static CHAR_T *memcpy_lowcase (CHAR_T *dest, const CHAR_T *src,
size_t len LOCALE_PARAM);
static CHAR_T * static CHAR_T *
memcpy_lowcase (CHAR_T *dest, const CHAR_T *src, memcpy_lowcase (CHAR_T *dest, const CHAR_T *src, size_t len LOCALE_PARAM)
size_t len LOCALE_PARAM_PROTO)
{ {
while (len-- > 0) while (len-- > 0)
dest[len] = TOLOWER ((UCHAR_T) src[len], loc); dest[len] = TOLOWER ((UCHAR_T) src[len], loc);
return dest; return dest;
} }
static CHAR_T *memcpy_uppcase (CHAR_T *dest, const CHAR_T *src,
size_t len LOCALE_PARAM);
static CHAR_T * static CHAR_T *
memcpy_uppcase (CHAR_T *dest, const CHAR_T *src, memcpy_uppcase (CHAR_T *dest, const CHAR_T *src, size_t len LOCALE_PARAM)
size_t len LOCALE_PARAM_PROTO)
{ {
while (len-- > 0) while (len-- > 0)
dest[len] = TOUPPER ((UCHAR_T) src[len], loc); 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, /* Yield the difference between *A and *B,
measured in seconds, ignoring leap seconds. */ measured in seconds, ignoring leap seconds. */
# define tm_diff ftime_tm_diff # define tm_diff ftime_tm_diff
static int tm_diff (const struct tm *, const struct tm *);
static int static int
tm_diff (const struct tm *a, const struct tm *b) 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_WEEK_START_WDAY 1 /* Monday */
#define ISO_WEEK1_WDAY 4 /* Thursday */ #define ISO_WEEK1_WDAY 4 /* Thursday */
#define YDAY_MINIMUM (-366) #define YDAY_MINIMUM (-366)
static int iso_week_days (int, int);
#ifdef __GNUC__ #ifdef __GNUC__
__inline__ __inline__
#endif #endif
@ -401,17 +407,41 @@ iso_week_days (int yday, int wday)
# define ns 0 # define ns 0
#endif #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, /* Write information from TP into S according to the format
to indicate that the result should be converted to upper case. */ 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 static size_t
strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
STRFTIME_ARG (size_t maxsize) const CHAR_T *format,
const CHAR_T *format, const struct tm *tp, bool upcase, bool *tzset_called
const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO) extra_args_spec LOCALE_PARAM)
{ {
#if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL #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 #endif
#if FPRINTFTIME #if FPRINTFTIME
size_t maxsize = (size_t) -1; 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 only a few elements. Dereference the pointers only if the format
requires this. Then it is ok to fail if the pointers are invalid. */ requires this. Then it is ok to fail if the pointers are invalid. */
# define a_wkday \ # 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 \ # 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 \ # 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 \ # 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 \ # define ampm \
((const CHAR_T *) _NL_CURRENT (LC_TIME, tp->tm_hour > 11 \ ((const CHAR_T *) _NL_CURRENT (LC_TIME, tp->tm_hour > 11 \
? NLW(PM_STR) : NLW(AM_STR))) ? NLW(PM_STR) : NLW(AM_STR)))
@ -482,16 +516,22 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
# if !HAVE_TM_ZONE # if !HAVE_TM_ZONE
/* Infer the zone name from *TZ instead of from TZNAME. */ /* Infer the zone name from *TZ instead of from TZNAME. */
tzname_vec = tz->tzname_copy; 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 # endif
} }
/* The tzset() call might have changed the value. */ /* The tzset() call might have changed the value. */
if (!(zone && *zone) && tp->tm_isdst >= 0) 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 #endif
if (! zone) if (! zone)
zone = ""; zone = "";
@ -801,14 +841,15 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
subformat: subformat:
{ {
size_t len = strftime_case_ (to_uppcase, size_t len = __strftime_internal (NULL, STRFTIME_ARG ((size_t) -1)
NULL, STRFTIME_ARG ((size_t) -1) subfmt,
subfmt, tp, to_uppcase, tzset_called
tp extra_args LOCALE_ARG); extra_args LOCALE_ARG);
add (len, strftime_case_ (to_uppcase, p, add (len, __strftime_internal (p,
STRFTIME_ARG (maxsize - i) STRFTIME_ARG (maxsize - i)
subfmt, subfmt,
tp extra_args LOCALE_ARG)); tp, to_uppcase, tzset_called
extra_args LOCALE_ARG));
} }
break; break;
@ -845,8 +886,6 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
#endif #endif
case L_('C'): case L_('C'):
if (modifier == L_('O'))
goto bad_format;
if (modifier == L_('E')) if (modifier == L_('E'))
{ {
#if HAVE_STRUCT_ERA_ENTRY #if HAVE_STRUCT_ERA_ENTRY
@ -1115,6 +1154,10 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
goto underlying_strftime; goto underlying_strftime;
#endif #endif
case L_('q'): /* GNU extension. */
DO_SIGNED_NUMBER (1, false, ((tp->tm_mon * 11) >> 5) + 1);
break;
case L_('R'): case L_('R'):
subfmt = L_("%H:%M"); subfmt = L_("%H:%M");
goto subformat; goto subformat;
@ -1364,6 +1407,16 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
struct tm ltm; struct tm ltm;
time_t lt; 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; ltm = *tp;
lt = mktime_z (tz, &ltm); lt = mktime_z (tz, &ltm);
@ -1444,22 +1497,3 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
return i; 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)); (struct timeval *restrict, void *restrict));
# endif # endif
_GL_CXXALIASWARN (gettimeofday); _GL_CXXALIASWARN (gettimeofday);
# if defined __cplusplus && defined GNULIB_NAMESPACE
namespace GNULIB_NAMESPACE {
typedef ::timeval
#undef timeval
timeval;
}
# endif
#elif defined GNULIB_POSIXCHECK #elif defined GNULIB_POSIXCHECK
# undef gettimeofday # undef gettimeofday
# if HAVE_RAW_DECL_GETTIMEOFDAY # if HAVE_RAW_DECL_GETTIMEOFDAY

View file

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