diff options
author | thegeorg <thegeorg@yandex-team.com> | 2024-08-04 11:38:26 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2024-08-04 11:50:56 +0300 |
commit | ad701999eb5b93914c402b833230cf5f25958d46 (patch) | |
tree | c90ad21f5f2b35d8db8c2f75a651bbe63ec1d6ef /contrib/tools/bison/lib | |
parent | 8744db6c4910e07c48a536a49886d2601c4fe6c6 (diff) | |
download | ydb-ad701999eb5b93914c402b833230cf5f25958d46.tar.gz |
Update contrib/tools/bison to 3.5.4
3.4.2 build is broken in NixOS, hence 3.3.x is updated to 3.5.y.
61a027adbe6cc0b27392bf3980c328640fd0ba69
Diffstat (limited to 'contrib/tools/bison/lib')
205 files changed, 7703 insertions, 1101 deletions
diff --git a/contrib/tools/bison/lib/allocator.h b/contrib/tools/bison/lib/allocator.h index 5a632ba6ff..2b032383de 100644 --- a/contrib/tools/bison/lib/allocator.h +++ b/contrib/tools/bison/lib/allocator.h @@ -1,6 +1,6 @@ /* Memory allocators such as malloc+free. - Copyright (C) 2011-2019 Free Software Foundation, Inc. + Copyright (C) 2011-2020 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 diff --git a/contrib/tools/bison/lib/areadlink.c b/contrib/tools/bison/lib/areadlink.c index 059435624d..a72ddf8d65 100644 --- a/contrib/tools/bison/lib/areadlink.c +++ b/contrib/tools/bison/lib/areadlink.c @@ -1,7 +1,7 @@ /* areadlink.c -- readlink wrapper to return the link name in malloc'd storage Unlike xreadlink and xreadlink_with_size, don't ever call exit. - Copyright (C) 2001, 2003-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2003-2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/areadlink.h b/contrib/tools/bison/lib/areadlink.h index ddcd06d7d7..f68efe5e3b 100644 --- a/contrib/tools/bison/lib/areadlink.h +++ b/contrib/tools/bison/lib/areadlink.h @@ -1,6 +1,6 @@ /* Read symbolic links without size limitation. - Copyright (C) 2001, 2003-2004, 2007, 2009-2019 Free Software Foundation, + Copyright (C) 2001, 2003-2004, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/arg-nonnull.h b/contrib/tools/bison/lib/arg-nonnull.h index ad8c26c225..ac26ca8cfe 100644 --- a/contrib/tools/bison/lib/arg-nonnull.h +++ b/contrib/tools/bison/lib/arg-nonnull.h @@ -1,5 +1,5 @@ /* A C macro for declaring that specific arguments must not be NULL. - Copyright (C) 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2020 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 diff --git a/contrib/tools/bison/lib/argmatch.c b/contrib/tools/bison/lib/argmatch.c index b9a3e400c4..195f90252b 100644 --- a/contrib/tools/bison/lib/argmatch.c +++ b/contrib/tools/bison/lib/argmatch.c @@ -1,6 +1,6 @@ /* argmatch.c -- find a match for a string in an array - Copyright (C) 1990, 1998-1999, 2001-2007, 2009-2019 Free Software + Copyright (C) 1990, 1998-1999, 2001-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -29,12 +29,10 @@ #include <stdlib.h> #include <string.h> -#include "gettext.h" #define _(msgid) gettext (msgid) #include "error.h" #include "quotearg.h" -#include "quote.h" #include "getprogname.h" #if USE_UNLOCKED_IO @@ -82,7 +80,7 @@ argmatch_exit_fn argmatch_die = __argmatch_die; ptrdiff_t argmatch (const char *arg, const char *const *arglist, - const char *vallist, size_t valsize) + const void *vallist, size_t valsize) { size_t i; /* Temporary index in ARGLIST. */ size_t arglen; /* Length of ARG. */ @@ -106,8 +104,8 @@ argmatch (const char *arg, const char *const *arglist, { /* Second nonexact match found. */ if (vallist == NULL - || memcmp (vallist + valsize * matchind, - vallist + valsize * i, valsize)) + || memcmp ((char const *) vallist + valsize * matchind, + (char const *) vallist + valsize * i, valsize)) { /* There is a real ambiguity, or we could not disambiguate. */ @@ -144,7 +142,7 @@ argmatch_invalid (const char *context, const char *value, ptrdiff_t problem) VALSIZE is the size of the elements of VALLIST */ void argmatch_valid (const char *const *arglist, - const char *vallist, size_t valsize) + const void *vallist, size_t valsize) { size_t i; const char *last_val = NULL; @@ -154,10 +152,10 @@ argmatch_valid (const char *const *arglist, fputs (_("Valid arguments are:"), stderr); for (i = 0; arglist[i]; i++) if ((i == 0) - || memcmp (last_val, vallist + valsize * i, valsize)) + || memcmp (last_val, (char const *) vallist + valsize * i, valsize)) { fprintf (stderr, "\n - %s", quote (arglist[i])); - last_val = vallist + valsize * i; + last_val = (char const *) vallist + valsize * i; } else { @@ -175,7 +173,7 @@ argmatch_valid (const char *const *arglist, ptrdiff_t __xargmatch_internal (const char *context, const char *arg, const char *const *arglist, - const char *vallist, size_t valsize, + const void *vallist, size_t valsize, argmatch_exit_fn exit_fn) { ptrdiff_t res = argmatch (arg, arglist, vallist, valsize); @@ -194,14 +192,14 @@ __xargmatch_internal (const char *context, /* Look for VALUE in VALLIST, an array of objects of size VALSIZE and return the first corresponding argument in ARGLIST */ const char * -argmatch_to_argument (const char *value, +argmatch_to_argument (const void *value, const char *const *arglist, - const char *vallist, size_t valsize) + const void *vallist, size_t valsize) { size_t i; for (i = 0; arglist[i]; i++) - if (!memcmp (value, vallist + valsize * i, valsize)) + if (!memcmp (value, (char const *) vallist + valsize * i, valsize)) return arglist[i]; return NULL; } diff --git a/contrib/tools/bison/lib/argmatch.h b/contrib/tools/bison/lib/argmatch.h index 51d2885879..daa0fdbf3a 100644 --- a/contrib/tools/bison/lib/argmatch.h +++ b/contrib/tools/bison/lib/argmatch.h @@ -1,6 +1,6 @@ /* argmatch.h -- definitions and prototypes for argmatch.c - Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2019 Free Software + Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -22,13 +22,19 @@ #ifndef ARGMATCH_H_ # define ARGMATCH_H_ 1 +# include <limits.h> +# include <stdbool.h> # include <stddef.h> +# include <stdio.h> +# include <string.h> /* memcmp */ +# include "gettext.h" +# include "quote.h" # include "verify.h" -#ifdef __cplusplus +# ifdef __cplusplus extern "C" { -#endif +# endif # define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array)) @@ -44,10 +50,10 @@ extern "C" { to the same values in VALLIST). */ ptrdiff_t argmatch (char const *arg, char const *const *arglist, - char const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE; + void const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE; # define ARGMATCH(Arg, Arglist, Vallist) \ - argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist)) + argmatch (Arg, Arglist, (void const *) (Vallist), sizeof *(Vallist)) /* xargmatch calls this function when it fails. This function should not return. By default, this is a function that calls ARGMATCH_DIE which @@ -70,10 +76,10 @@ void argmatch_invalid (char const *context, char const *value, /* Report on stderr the list of possible arguments. */ void argmatch_valid (char const *const *arglist, - char const *vallist, size_t valsize); + void const *vallist, size_t valsize); # define ARGMATCH_VALID(Arglist, Vallist) \ - argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist)) + argmatch_valid (Arglist, (void const *) (Vallist), sizeof *(Vallist)) @@ -82,30 +88,244 @@ void argmatch_valid (char const *const *arglist, ptrdiff_t __xargmatch_internal (char const *context, char const *arg, char const *const *arglist, - char const *vallist, size_t valsize, + void const *vallist, size_t valsize, argmatch_exit_fn exit_fn); /* Programmer friendly interface to __xargmatch_internal. */ # define XARGMATCH(Context, Arg, Arglist, Vallist) \ ((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \ - (char const *) (Vallist), \ + (void const *) (Vallist), \ sizeof *(Vallist), \ argmatch_die)]) /* Convert a value into a corresponding argument. */ -char const *argmatch_to_argument (char const *value, +char const *argmatch_to_argument (void const *value, char const *const *arglist, - char const *vallist, size_t valsize) + void const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE; # define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \ argmatch_to_argument (Value, Arglist, \ - (char const *) (Vallist), sizeof *(Vallist)) - -#ifdef __cplusplus + (void const *) (Vallist), sizeof *(Vallist)) + +# define ARGMATCH_DEFINE_GROUP(Name, Type) \ + /* The type of the values of this group. */ \ + typedef Type argmatch_##Name##_type; \ + \ + /* The size of the type of the values of this group. */ \ + enum argmatch_##Name##_size_enum \ + { \ + argmatch_##Name##_size = sizeof (argmatch_##Name##_type) \ + }; \ + \ + /* Argument mapping of this group. */ \ + typedef struct \ + { \ + /* Argument (e.g., "simple"). */ \ + const char *arg; \ + /* Value (e.g., simple_backups). */ \ + const argmatch_##Name##_type val; \ + } argmatch_##Name##_arg; \ + \ + /* Documentation of this group. */ \ + typedef struct \ + { \ + /* Argument (e.g., "simple"). */ \ + const char *arg; \ + /* Documentation (e.g., N_("always make simple backups")). */ \ + const char *doc; \ + } argmatch_##Name##_doc; \ + \ + /* All the features of an argmatch group. */ \ + typedef struct \ + { \ + const argmatch_##Name##_arg* args; \ + const argmatch_##Name##_doc* docs; \ + \ + /* Printed before the usage message. */ \ + const char *doc_pre; \ + /* Printed after the usage message. */ \ + const char *doc_post; \ + } argmatch_##Name##_group_type; \ + \ + /* The structure the user must build. */ \ + extern const argmatch_##Name##_group_type argmatch_##Name##_group; \ + \ + /* Print the documentation of this group. */ \ + void argmatch_##Name##_usage (FILE *out); \ + \ + /* If nonnegative, the index I of ARG in ARGS, i.e, \ + ARGS[I] == ARG. \ + Return -1 for invalid argument, -2 for ambiguous argument. */ \ + ptrdiff_t argmatch_##Name##_choice (const char *arg); \ + \ + /* A pointer to the corresponding value if it exists, or \ + report an error and exit with failure if the argument was \ + not recognized. */ \ + const argmatch_##Name##_type* \ + argmatch_##Name##_value (const char *context, const char *arg); \ + \ + /* The first argument in ARGS that matches this value, or NULL. */ \ + const char * \ + argmatch_##Name##_argument (const argmatch_##Name##_type *val); \ + \ + ptrdiff_t \ + argmatch_##Name##_choice (const char *arg) \ + { \ + const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \ + size_t size = argmatch_##Name##_size; \ + ptrdiff_t res = -1; /* Index of first nonexact match. */ \ + bool ambiguous = false; /* Whether multiple nonexact match(es). */ \ + size_t arglen = strlen (arg); \ + \ + /* Test all elements for either exact match or abbreviated \ + matches. */ \ + for (size_t i = 0; g->args[i].arg; i++) \ + if (!strncmp (g->args[i].arg, arg, arglen)) \ + { \ + if (strlen (g->args[i].arg) == arglen) \ + /* Exact match found. */ \ + return i; \ + else if (res == -1) \ + /* First nonexact match found. */ \ + res = i; \ + else if (memcmp (&g->args[res].val, &g->args[i].val, size)) \ + /* Second nonexact match found. */ \ + /* There is a real ambiguity, or we could not \ + disambiguate. */ \ + ambiguous = true; \ + } \ + return ambiguous ? -2 : res; \ + } \ + \ + const char * \ + argmatch_##Name##_argument (const argmatch_##Name##_type *val) \ + { \ + const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \ + size_t size = argmatch_##Name##_size; \ + for (size_t i = 0; g->args[i].arg; i++) \ + if (!memcmp (val, &g->args[i].val, size)) \ + return g->args[i].arg; \ + return NULL; \ + } \ + \ + /* List the valid values of this group. */ \ + static void \ + argmatch_##Name##_valid (FILE *out) \ + { \ + const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \ + size_t size = argmatch_##Name##_size; \ + \ + /* Try to put synonyms on the same line. Synonyms are expected \ + to follow each other. */ \ + fputs (gettext ("Valid arguments are:"), out); \ + for (int i = 0; g->args[i].arg; i++) \ + if (i == 0 \ + || memcmp (&g->args[i-1].val, &g->args[i].val, size)) \ + fprintf (out, "\n - %s", quote (g->args[i].arg)); \ + else \ + fprintf (out, ", %s", quote (g->args[i].arg)); \ + putc ('\n', out); \ + } \ + \ + const argmatch_##Name##_type* \ + argmatch_##Name##_value (const char *context, const char *arg) \ + { \ + const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \ + ptrdiff_t res = argmatch_##Name##_choice (arg); \ + if (res < 0) \ + { \ + argmatch_invalid (context, arg, res); \ + argmatch_##Name##_valid (stderr); \ + argmatch_die (); \ + } \ + return &g->args[res].val; \ + } \ + \ + /* The column in which the documentation is displayed. \ + The leftmost possible, but no more than 20. */ \ + static int \ + argmatch_##Name##_doc_col (void) \ + { \ + const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \ + size_t size = argmatch_##Name##_size; \ + int res = 0; \ + for (int i = 0; g->docs[i].arg; ++i) \ + { \ + int col = 4; \ + int ival = argmatch_##Name##_choice (g->docs[i].arg); \ + if (ival < 0) \ + /* Pseudo argument, display it. */ \ + col += strlen (g->docs[i].arg); \ + else \ + /* Genuine argument, display it with its synonyms. */ \ + for (int j = 0; g->args[j].arg; ++j) \ + if (! memcmp (&g->args[ival].val, &g->args[j].val, size)) \ + col += (col == 4 ? 0 : 2) + strlen (g->args[j].arg); \ + if (res <= col) \ + res = col <= 20 ? col : 20; \ + } \ + return res ? res : 20; \ + } \ + \ + void \ + argmatch_##Name##_usage (FILE *out) \ + { \ + const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \ + size_t size = argmatch_##Name##_size; \ + /* Width of the screen. Help2man does not seem to support \ + arguments on several lines, so in that case pretend a very \ + large width. */ \ + const int screen_width = getenv ("HELP2MAN") ? INT_MAX : 80; \ + if (g->doc_pre) \ + fprintf (out, "%s\n", gettext (g->doc_pre)); \ + int doc_col = argmatch_##Name##_doc_col (); \ + for (int i = 0; g->docs[i].arg; ++i) \ + { \ + int col = 0; \ + bool first = true; \ + int ival = argmatch_##Name##_choice (g->docs[i].arg); \ + if (ival < 0) \ + /* Pseudo argument, display it. */ \ + col += fprintf (out, " %s", g->docs[i].arg); \ + else \ + /* Genuine argument, display it with its synonyms. */ \ + for (int j = 0; g->args[j].arg; ++j) \ + if (! memcmp (&g->args[ival].val, &g->args[j].val, size)) \ + { \ + if (!first \ + && screen_width < col + 2 + strlen (g->args[j].arg)) \ + { \ + fprintf (out, ",\n"); \ + col = 0; \ + first = true; \ + } \ + if (first) \ + { \ + col += fprintf (out, " "); \ + first = false; \ + } \ + else \ + col += fprintf (out, ","); \ + col += fprintf (out, " %s", g->args[j].arg); \ + } \ + /* The doc. Separated by at least two spaces. */ \ + if (doc_col < col + 2) \ + { \ + fprintf (out, "\n"); \ + col = 0; \ + } \ + fprintf (out, "%*s%s\n", \ + doc_col - col, "", gettext (g->docs[i].doc)); \ + } \ + if (g->doc_post) \ + fprintf (out, "%s\n", gettext (g->doc_post)); \ + } + +# ifdef __cplusplus } -#endif +# endif #endif /* ARGMATCH_H_ */ diff --git a/contrib/tools/bison/lib/asnprintf.c b/contrib/tools/bison/lib/asnprintf.c index d2a8c09720..37dcf925ec 100644 --- a/contrib/tools/bison/lib/asnprintf.c +++ b/contrib/tools/bison/lib/asnprintf.c @@ -1,5 +1,5 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/asprintf.c b/contrib/tools/bison/lib/asprintf.c new file mode 100644 index 0000000000..f97580f745 --- /dev/null +++ b/contrib/tools/bison/lib/asprintf.c @@ -0,0 +1,39 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007, 2009-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#ifdef IN_LIBASPRINTF +# include "vasprintf.h" +#else +# include <stdio.h> +#endif + +#include <stdarg.h> + +int +asprintf (char **resultp, const char *format, ...) +{ + va_list args; + int result; + + va_start (args, format); + result = vasprintf (resultp, format, args); + va_end (args); + return result; +} diff --git a/contrib/tools/bison/lib/assure.h b/contrib/tools/bison/lib/assure.h new file mode 100644 index 0000000000..8ea2f6e480 --- /dev/null +++ b/contrib/tools/bison/lib/assure.h @@ -0,0 +1,37 @@ +/* Run-time assert-like macros. + + Copyright (C) 2014-2020 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#ifndef _GL_ASSURE_H +#define _GL_ASSURE_H + +#include <assert.h> + +/* Check E's value at runtime, and report an error and abort if not. + However, do nothing if NDEBUG is defined. + + Unlike standard 'assert', this macro always compiles E even when NDEBUG + is defined, so as to catch typos and avoid some GCC warnings. */ + +#ifdef NDEBUG +# define assure(E) ((void) (0 && (E))) +#else +# define assure(E) assert (E) +#endif + +#endif diff --git a/contrib/tools/bison/lib/basename-lgpl.c b/contrib/tools/bison/lib/basename-lgpl.c index 0ae04ee572..565469ea3d 100644 --- a/contrib/tools/bison/lib/basename-lgpl.c +++ b/contrib/tools/bison/lib/basename-lgpl.c @@ -1,6 +1,6 @@ /* basename.c -- return the last element in a file name - Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2019 Free Software + Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/basename.c b/contrib/tools/bison/lib/basename.c index 1b6e0ea59b..b14417f48d 100644 --- a/contrib/tools/bison/lib/basename.c +++ b/contrib/tools/bison/lib/basename.c @@ -1,6 +1,6 @@ /* basename.c -- return the last element in a file name - Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2019 Free Software + Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/binary-io.c b/contrib/tools/bison/lib/binary-io.c index 01e0bf6476..e84e223fc8 100644 --- a/contrib/tools/bison/lib/binary-io.c +++ b/contrib/tools/bison/lib/binary-io.c @@ -1,5 +1,5 @@ /* Binary mode I/O. - Copyright 2017-2019 Free Software Foundation, Inc. + Copyright 2017-2020 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 @@ -20,18 +20,20 @@ #include "binary-io.h" #if defined __DJGPP__ || defined __EMX__ -# include <errno.h> # include <unistd.h> int -__gl_setmode_check (int fd) +set_binary_mode (int fd, int mode) { if (isatty (fd)) - { - errno = EINVAL; - return -1; - } + /* If FD refers to a console (not a pipe, not a regular file), + O_TEXT is the only reasonable mode, both on input and on output. + Silently ignore the request. If we were to return -1 here, + all programs that use xset_binary_mode would fail when run + with console input or console output. */ + return O_TEXT; else - return 0; + return __gl_setmode (fd, mode); } + #endif diff --git a/contrib/tools/bison/lib/binary-io.h b/contrib/tools/bison/lib/binary-io.h index 100ac3011c..05f7986b5f 100644 --- a/contrib/tools/bison/lib/binary-io.h +++ b/contrib/tools/bison/lib/binary-io.h @@ -1,5 +1,5 @@ /* Binary mode I/O. - Copyright (C) 2001, 2003, 2005, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2003, 2005, 2008-2020 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 @@ -61,25 +61,21 @@ __gl_setmode (int fd _GL_UNUSED, int mode _GL_UNUSED) } #endif -#if defined __DJGPP__ || defined __EMX__ -extern int __gl_setmode_check (int); -#else -BINARY_IO_INLINE int -__gl_setmode_check (int fd _GL_UNUSED) { return 0; } -#endif - /* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY. Return the old mode if successful, -1 (setting errno) on failure. Ordinarily this function would be called 'setmode', since that is its name on MS-Windows, but it is called 'set_binary_mode' here to avoid colliding with a BSD function of another name. */ +#if defined __DJGPP__ || defined __EMX__ +extern int set_binary_mode (int fd, int mode); +#else BINARY_IO_INLINE int set_binary_mode (int fd, int mode) { - int r = __gl_setmode_check (fd); - return r != 0 ? r : __gl_setmode (fd, mode); + return __gl_setmode (fd, mode); } +#endif /* This macro is obsolescent. */ #define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY)) diff --git a/contrib/tools/bison/lib/bitrotate.h b/contrib/tools/bison/lib/bitrotate.h index 862331e204..59827e2742 100644 --- a/contrib/tools/bison/lib/bitrotate.h +++ b/contrib/tools/bison/lib/bitrotate.h @@ -1,5 +1,5 @@ /* bitrotate.h - Rotate bits in integers - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 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 @@ -95,7 +95,8 @@ rotr_sz (size_t x, int n) BITROTATE_INLINE uint16_t rotl16 (uint16_t x, int n) { - return ((x << n) | (x >> (16 - n))) & UINT16_MAX; + return (((unsigned int) x << n) | ((unsigned int) x >> (16 - n))) + & UINT16_MAX; } /* Given an unsigned 16-bit argument X, return the value corresponding @@ -106,7 +107,8 @@ rotl16 (uint16_t x, int n) BITROTATE_INLINE uint16_t rotr16 (uint16_t x, int n) { - return ((x >> n) | (x << (16 - n))) & UINT16_MAX; + return (((unsigned int) x >> n) | ((unsigned int) x << (16 - n))) + & UINT16_MAX; } /* Given an unsigned 8-bit argument X, return the value corresponding @@ -117,7 +119,7 @@ rotr16 (uint16_t x, int n) BITROTATE_INLINE uint8_t rotl8 (uint8_t x, int n) { - return ((x << n) | (x >> (8 - n))) & UINT8_MAX; + return (((unsigned int) x << n) | ((unsigned int) x >> (8 - n))) & UINT8_MAX; } /* Given an unsigned 8-bit argument X, return the value corresponding @@ -128,7 +130,7 @@ rotl8 (uint8_t x, int n) BITROTATE_INLINE uint8_t rotr8 (uint8_t x, int n) { - return ((x >> n) | (x << (8 - n))) & UINT8_MAX; + return (((unsigned int) x >> n) | ((unsigned int) x << (8 - n))) & UINT8_MAX; } _GL_INLINE_HEADER_END diff --git a/contrib/tools/bison/lib/bitset.c b/contrib/tools/bison/lib/bitset.c index cccb1e8347..c0fc13fd52 100644 --- a/contrib/tools/bison/lib/bitset.c +++ b/contrib/tools/bison/lib/bitset.c @@ -1,6 +1,6 @@ /* General bitsets. - Copyright (C) 2002-2006, 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -15,7 +15,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include <config.h> @@ -129,7 +129,7 @@ bitset_alloc (bitset_bindex n_bits, enum bitset_type type) { size_t bytes = bitset_bytes (type, n_bits); - bitset bset = xcalloc (1, bytes); + bitset bset = xzalloc (bytes); /* The cache is disabled until some elements are allocated. If we have variable length arrays, then we may need to allocate a dummy @@ -168,8 +168,11 @@ bitset_create (bitset_bindex n_bits, unsigned attr) void bitset_free (bitset bset) { - BITSET_FREE_ (bset); - free (bset); + if (bset) + { + BITSET_FREE_ (bset); + free (bset); + } } @@ -177,7 +180,8 @@ bitset_free (bitset bset) void bitset_obstack_free (bitset bset) { - BITSET_FREE_ (bset); + if (bset) + BITSET_FREE_ (bset); } diff --git a/contrib/tools/bison/lib/bitset.h b/contrib/tools/bison/lib/bitset.h index 32d08e7aa9..a13b8d4d16 100644 --- a/contrib/tools/bison/lib/bitset.h +++ b/contrib/tools/bison/lib/bitset.h @@ -1,6 +1,6 @@ /* Generic bitsets. - Copyright (C) 2002-2004, 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -15,7 +15,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifndef _GL_BITSET_H #define _GL_BITSET_H @@ -109,7 +109,7 @@ enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs); /* Create a bitset of desired type and size. The bitset is zeroed. */ bitset bitset_alloc (bitset_bindex, enum bitset_type); -/* Free bitset. */ +/* Free bitset. Do nothing if NULL. */ void bitset_free (bitset); /* Create a bitset of desired type and size using an obstack. The @@ -117,7 +117,7 @@ void bitset_free (bitset); bitset bitset_obstack_alloc (struct obstack *bobstack, bitset_bindex, enum bitset_type); -/* Free bitset allocated on obstack. */ +/* Free bitset allocated on obstack. Do nothing if NULL. */ void bitset_obstack_free (bitset); /* Create a bitset of desired size and attributes. The bitset is zeroed. */ @@ -178,8 +178,9 @@ bitset_test (bitset bset, bitset_bindex bitno) /* Return size in bits of bitset SRC. */ #define bitset_size(SRC) BITSET_SIZE_ (SRC) -/* Change size of bitset. */ -void bitset_resize (bitset, bitset_bindex); +/* Change size in bits of bitset. New bits are zeroed. Return + SIZE. */ +#define bitset_resize(DST, SIZE) BITSET_RESIZE_ (DST, SIZE) /* Return number of bits set in bitset SRC. */ #define bitset_count(SRC) BITSET_COUNT_ (SRC) diff --git a/contrib/tools/bison/lib/bitset/array.c b/contrib/tools/bison/lib/bitset/array.c index fde9fa24f5..e611f38bcf 100644 --- a/contrib/tools/bison/lib/bitset/array.c +++ b/contrib/tools/bison/lib/bitset/array.c @@ -1,6 +1,6 @@ /* Array bitsets. - Copyright (C) 2002-2003, 2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002-2003, 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include <config.h> diff --git a/contrib/tools/bison/lib/bitset/array.h b/contrib/tools/bison/lib/bitset/array.h index 6f49a2e047..0ec6a46129 100644 --- a/contrib/tools/bison/lib/bitset/array.h +++ b/contrib/tools/bison/lib/bitset/array.h @@ -1,6 +1,6 @@ /* Functions to support abitsets. - Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifndef _BITSET_ARRAY_H #define _BITSET_ARRAY_H diff --git a/contrib/tools/bison/lib/bitset/base.h b/contrib/tools/bison/lib/bitset/base.h index 4fcafac8b6..46ec894ece 100644 --- a/contrib/tools/bison/lib/bitset/base.h +++ b/contrib/tools/bison/lib/bitset/base.h @@ -1,6 +1,6 @@ /* Base bitset stuff. - Copyright (C) 2002-2004, 2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002-2004, 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifndef _BITSET_BASE_H #define _BITSET_BASE_H @@ -55,8 +55,6 @@ enum bitset_type {BITSET_ARRAY, BITSET_LIST, BITSET_TABLE, BITSET_VECTOR, extern const char * const bitset_type_names[]; -enum bitset_alloc_type {BITSET_MALLOC, BITSET_OBALLOC}; - /* Data type used to store a word of bits. */ typedef unsigned long bitset_word; #define BITSET_WORD_BITS ((unsigned) (CHAR_BIT * sizeof (bitset_word))) diff --git a/contrib/tools/bison/lib/bitset/list.c b/contrib/tools/bison/lib/bitset/list.c index f42edb8ea3..f453671827 100644 --- a/contrib/tools/bison/lib/bitset/list.c +++ b/contrib/tools/bison/lib/bitset/list.c @@ -1,6 +1,6 @@ /* Functions to support link list bitsets. - Copyright (C) 2002-2004, 2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002-2004, 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include <config.h> @@ -859,7 +859,8 @@ lbitset_unused_clear (bitset dst) bitset_word *srcp = elt->words; bitset_windex windex = n_bits / BITSET_WORD_BITS; - srcp[windex - elt->index] &= ((bitset_word) 1 << last_bit) - 1; + srcp[windex - elt->index] + &= ((bitset_word) 1 << (last_bit % BITSET_WORD_BITS)) - 1; windex++; for (; (windex - elt->index) < LBITSET_ELT_WORDS; windex++) diff --git a/contrib/tools/bison/lib/bitset/list.h b/contrib/tools/bison/lib/bitset/list.h index a0fc09f8c6..8b24f2593f 100644 --- a/contrib/tools/bison/lib/bitset/list.h +++ b/contrib/tools/bison/lib/bitset/list.h @@ -1,6 +1,6 @@ /* Functions to support lbitsets. - Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifndef _BITSET_LIST_H #define _BITSET_LIST_H diff --git a/contrib/tools/bison/lib/bitset/stats.c b/contrib/tools/bison/lib/bitset/stats.c index da73cdcac5..222cde0905 100644 --- a/contrib/tools/bison/lib/bitset/stats.c +++ b/contrib/tools/bison/lib/bitset/stats.c @@ -1,6 +1,6 @@ /* Bitset statistics. - Copyright (C) 2002-2006, 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -15,7 +15,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ /* This file is a wrapper bitset implementation for the other bitset implementations. It provides bitset compatibility checking and @@ -694,7 +694,7 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) case BITSET_ARRAY: { size_t bytes = abitset_bytes (n_bits); - bset->s.bset = xcalloc (1, bytes); + bset->s.bset = xzalloc (bytes); abitset_init (bset->s.bset, n_bits); } break; @@ -702,7 +702,7 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) case BITSET_LIST: { size_t bytes = lbitset_bytes (n_bits); - bset->s.bset = xcalloc (1, bytes); + bset->s.bset = xzalloc (bytes); lbitset_init (bset->s.bset, n_bits); } break; @@ -710,7 +710,7 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) case BITSET_TABLE: { size_t bytes = tbitset_bytes (n_bits); - bset->s.bset = xcalloc (1, bytes); + bset->s.bset = xzalloc (bytes); tbitset_init (bset->s.bset, n_bits); } break; @@ -718,7 +718,7 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) case BITSET_VECTOR: { size_t bytes = vbitset_bytes (n_bits); - bset->s.bset = xcalloc (1, bytes); + bset->s.bset = xzalloc (bytes); vbitset_init (bset->s.bset, n_bits); } break; diff --git a/contrib/tools/bison/lib/bitset/stats.h b/contrib/tools/bison/lib/bitset/stats.h index 95e64dc4e5..0bfed3e21b 100644 --- a/contrib/tools/bison/lib/bitset/stats.h +++ b/contrib/tools/bison/lib/bitset/stats.h @@ -1,6 +1,6 @@ /* Functions to support bitset statistics. - Copyright (C) 2002-2004, 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -15,7 +15,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifndef _BITSET_STATS_H #define _BITSET_STATS_H diff --git a/contrib/tools/bison/lib/bitset/table.c b/contrib/tools/bison/lib/bitset/table.c index 8351cf7848..ab68e518d0 100644 --- a/contrib/tools/bison/lib/bitset/table.c +++ b/contrib/tools/bison/lib/bitset/table.c @@ -1,6 +1,6 @@ /* Functions to support expandable bitsets. - Copyright (C) 2002-2006, 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -15,7 +15,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include <config.h> @@ -25,6 +25,7 @@ #include <string.h> #include "obstack.h" +#include "xalloc.h" /* This file implements expandable bitsets. These bitsets can be of arbitrary length and are more efficient than arrays of bits for @@ -142,7 +143,7 @@ tbitset_resize (bitset src, bitset_bindex n_bits) bitset_windex size = oldsize == 0 ? newsize : newsize + newsize / 4; EBITSET_ELTS (src) - = realloc (EBITSET_ELTS (src), size * sizeof (tbitset_elt *)); + = xrealloc (EBITSET_ELTS (src), size * sizeof (tbitset_elt *)); EBITSET_ASIZE (src) = size; } @@ -155,9 +156,13 @@ tbitset_resize (bitset src, bitset_bindex n_bits) the memory unless it is shrinking by a reasonable amount. */ if ((oldsize - newsize) >= oldsize / 2) { - EBITSET_ELTS (src) + void *p = realloc (EBITSET_ELTS (src), newsize * sizeof (tbitset_elt *)); - EBITSET_ASIZE (src) = newsize; + if (p) + { + EBITSET_ELTS (src) = p; + EBITSET_ASIZE (src) = newsize; + } } /* Need to prune any excess bits. FIXME. */ @@ -188,21 +193,21 @@ tbitset_elt_alloc (void) /* Let particular systems override the size of a chunk. */ #ifndef OBSTACK_CHUNK_SIZE -#define OBSTACK_CHUNK_SIZE 0 +# define OBSTACK_CHUNK_SIZE 0 #endif /* Let them override the alloc and free routines too. */ #ifndef OBSTACK_CHUNK_ALLOC -#define OBSTACK_CHUNK_ALLOC xmalloc +# define OBSTACK_CHUNK_ALLOC xmalloc #endif #ifndef OBSTACK_CHUNK_FREE -#define OBSTACK_CHUNK_FREE free +# define OBSTACK_CHUNK_FREE free #endif #if ! defined __GNUC__ || __GNUC__ < 2 -#define __alignof__(type) 0 +# define __alignof__(type) 0 #endif obstack_specify_allocation (&tbitset_obstack, OBSTACK_CHUNK_SIZE, @@ -300,7 +305,7 @@ tbitset_elt_find (bitset bset, bitset_bindex bindex, abort (); case EBITSET_FIND: - return 0; + return NULL; case EBITSET_CREATE: if (eindex >= size) @@ -588,8 +593,8 @@ tbitset_list_reverse (bitset bset, bitset_bindex *list, /* Find list of up to NUM bits set in BSET starting from and including - *NEXT and store in array LIST. Return with actual number of bits - found and with *NEXT indicating where search stopped. */ + *NEXT and store in array LIST. Return with actual number of bits + found and with *NEXT indicating where search stopped. */ static bitset_bindex tbitset_list (bitset bset, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) @@ -607,17 +612,14 @@ tbitset_list (bitset bset, bitset_bindex *list, if (bitno % EBITSET_ELT_BITS) { /* We need to start within an element. This is not very common. */ - tbitset_elt *elt = elts[eindex]; if (elt) { - bitset_windex woffset; bitset_word *srcp = EBITSET_WORDS (elt); + bitset_windex woffset = eindex * EBITSET_ELT_WORDS; - bitset_windex windex = bitno / BITSET_WORD_BITS; - woffset = eindex * EBITSET_ELT_WORDS; - - for (; (windex - woffset) < EBITSET_ELT_WORDS; windex++) + for (bitset_windex windex = bitno / BITSET_WORD_BITS; + (windex - woffset) < EBITSET_ELT_WORDS; windex++) { bitset_word word = srcp[windex - woffset] >> (bitno % BITSET_WORD_BITS); @@ -781,7 +783,8 @@ tbitset_unused_clear (bitset dst) bitset_windex windex = n_bits / BITSET_WORD_BITS; bitset_windex woffset = eindex * EBITSET_ELT_WORDS; - srcp[windex - woffset] &= ((bitset_word) 1 << last_bit) - 1; + srcp[windex - woffset] + &= ((bitset_word) 1 << (last_bit % BITSET_WORD_BITS)) - 1; windex++; for (; (windex - woffset) < EBITSET_ELT_WORDS; windex++) srcp[windex - woffset] = 0; @@ -1020,13 +1023,9 @@ tbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) } if (!tbitset_elt_zero_p (delt)) - { - tbitset_elt_add (dst, delt, j); - } + tbitset_elt_add (dst, delt, j); else - { - tbitset_elt_free (delt); - } + tbitset_elt_free (delt); } /* If we have elements of DST left over, free them all. */ @@ -1061,7 +1060,8 @@ tbitset_and_cmp (bitset dst, bitset src1, bitset src2) tbitset_zero (dst); return changed; } - return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND); + else + return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND); } @@ -1076,9 +1076,7 @@ static bool tbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { if (EBITSET_ZERO_P (src2)) - { - return tbitset_copy_cmp (dst, src1); - } + return tbitset_copy_cmp (dst, src1); else if (EBITSET_ZERO_P (src1)) { tbitset_weed (dst); @@ -1086,7 +1084,8 @@ tbitset_andn_cmp (bitset dst, bitset src1, bitset src2) tbitset_zero (dst); return changed; } - return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN); + else + return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN); } @@ -1101,14 +1100,11 @@ static bool tbitset_or_cmp (bitset dst, bitset src1, bitset src2) { if (EBITSET_ZERO_P (src2)) - { - return tbitset_copy_cmp (dst, src1); - } + return tbitset_copy_cmp (dst, src1); else if (EBITSET_ZERO_P (src1)) - { - return tbitset_copy_cmp (dst, src2); - } - return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR); + return tbitset_copy_cmp (dst, src2); + else + return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR); } @@ -1123,14 +1119,11 @@ static bool tbitset_xor_cmp (bitset dst, bitset src1, bitset src2) { if (EBITSET_ZERO_P (src2)) - { - return tbitset_copy_cmp (dst, src1); - } + return tbitset_copy_cmp (dst, src1); else if (EBITSET_ZERO_P (src1)) - { - return tbitset_copy_cmp (dst, src2); - } - return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR); + return tbitset_copy_cmp (dst, src2); + else + return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR); } diff --git a/contrib/tools/bison/lib/bitset/table.h b/contrib/tools/bison/lib/bitset/table.h index 6c781adde3..cf8555b9ce 100644 --- a/contrib/tools/bison/lib/bitset/table.h +++ b/contrib/tools/bison/lib/bitset/table.h @@ -1,6 +1,6 @@ /* Functions to support tbitsets. - Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifndef _BITSET_TABLE_H #define _BITSET_TABLE_H diff --git a/contrib/tools/bison/lib/bitset/vector.c b/contrib/tools/bison/lib/bitset/vector.c index 15d3e99567..cb60ba4a3a 100644 --- a/contrib/tools/bison/lib/bitset/vector.c +++ b/contrib/tools/bison/lib/bitset/vector.c @@ -1,6 +1,6 @@ /* Variable array bitsets. - Copyright (C) 2002-2006, 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -15,7 +15,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include <config.h> @@ -24,6 +24,8 @@ #include <stdlib.h> #include <string.h> +#include "xalloc.h" + /* This file implements variable size bitsets stored as a variable length array of words. Any unused bits in the last word must be zero. @@ -74,13 +76,12 @@ vbitset_resize (bitset src, bitset_bindex n_bits) bitset_windex size = oldsize == 0 ? newsize : newsize + newsize / 4; VBITSET_WORDS (src) - = realloc (VBITSET_WORDS (src), size * sizeof (bitset_word)); + = xrealloc (VBITSET_WORDS (src), size * sizeof (bitset_word)); VBITSET_ASIZE (src) = size; } memset (VBITSET_WORDS (src) + oldsize, 0, (newsize - oldsize) * sizeof (bitset_word)); - VBITSET_SIZE (src) = newsize; } else { @@ -88,16 +89,19 @@ vbitset_resize (bitset src, bitset_bindex n_bits) the memory unless it is shrinking by a reasonable amount. */ if ((oldsize - newsize) >= oldsize / 2) { - VBITSET_WORDS (src) + void *p = realloc (VBITSET_WORDS (src), newsize * sizeof (bitset_word)); - VBITSET_ASIZE (src) = newsize; + if (p) + { + VBITSET_WORDS (src) = p; + VBITSET_ASIZE (src) = newsize; + } } /* Need to prune any excess bits. FIXME. */ - - VBITSET_SIZE (src) = newsize; } + VBITSET_SIZE (src) = newsize; BITSET_NBITS_ (src) = n_bits; return n_bits; } @@ -467,7 +471,6 @@ vbitset_and (bitset dst, bitset src1, bitset src2) static bool vbitset_and_cmp (bitset dst, bitset src1, bitset src2) { - bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); bitset_windex dsize = VBITSET_SIZE (dst); @@ -477,6 +480,7 @@ vbitset_and_cmp (bitset dst, bitset src1, bitset src2) bitset_word *src1p = VBITSET_WORDS (src1); bitset_word *src2p = VBITSET_WORDS (src2); + bool changed = false; unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { @@ -546,7 +550,6 @@ vbitset_andn (bitset dst, bitset src1, bitset src2) static bool vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { - bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); bitset_windex dsize = VBITSET_SIZE (dst); @@ -556,6 +559,7 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) bitset_word *src1p = VBITSET_WORDS (src1); bitset_word *src2p = VBITSET_WORDS (src2); + bool changed = false; unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { @@ -633,8 +637,6 @@ vbitset_or (bitset dst, bitset src1, bitset src2) static bool vbitset_or_cmp (bitset dst, bitset src1, bitset src2) { - bool changed = false; - vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); bitset_windex dsize = VBITSET_SIZE (dst); @@ -644,6 +646,7 @@ vbitset_or_cmp (bitset dst, bitset src1, bitset src2) bitset_word *src1p = VBITSET_WORDS (src1); bitset_word *src2p = VBITSET_WORDS (src2); + bool changed = false; unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { @@ -711,7 +714,6 @@ vbitset_xor (bitset dst, bitset src1, bitset src2) static bool vbitset_xor_cmp (bitset dst, bitset src1, bitset src2) { - bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); bitset_windex dsize = VBITSET_SIZE (dst); @@ -721,6 +723,7 @@ vbitset_xor_cmp (bitset dst, bitset src1, bitset src2) bitset_word *src1p = VBITSET_WORDS (src1); bitset_word *src2p = VBITSET_WORDS (src2); + bool changed = false; unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { @@ -903,8 +906,8 @@ vbitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) bitset_word *dstp = VBITSET_WORDS (dst); bitset_windex size = VBITSET_SIZE (dst); - unsigned i; bool changed = false; + unsigned i; for (i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ | *src2p++) & *src3p++; @@ -929,6 +932,13 @@ vbitset_copy (bitset dst, bitset src) } +static void +vbitset_free (bitset bset) +{ + free (VBITSET_WORDS (bset)); +} + + /* Vector of operations for multiple word bitsets. */ struct bitset_vtable vbitset_vtable = { vbitset_set, @@ -962,7 +972,7 @@ struct bitset_vtable vbitset_vtable = { vbitset_or_and_cmp, vbitset_list, vbitset_list_reverse, - NULL, + vbitset_free, BITSET_VECTOR }; diff --git a/contrib/tools/bison/lib/bitset/vector.h b/contrib/tools/bison/lib/bitset/vector.h index 1f5b94dea0..aeea89a6c7 100644 --- a/contrib/tools/bison/lib/bitset/vector.h +++ b/contrib/tools/bison/lib/bitset/vector.h @@ -1,6 +1,6 @@ /* Functions to support vbitsets. - Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifndef _BITSET_VECTOR_H #define _BITSET_VECTOR_H diff --git a/contrib/tools/bison/lib/bitsetv.c b/contrib/tools/bison/lib/bitsetv.c index e3cc5845a7..0ec9ac38c2 100644 --- a/contrib/tools/bison/lib/bitsetv.c +++ b/contrib/tools/bison/lib/bitsetv.c @@ -1,6 +1,6 @@ /* Bitset vectors. - Copyright (C) 2001-2002, 2004-2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2001-2002, 2004-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -14,7 +14,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include <config.h> @@ -41,7 +41,7 @@ bitsetv_alloc (bitset_bindex n_vecs, bitset_bindex n_bits, /* Allocate vector table at head of bitset array. */ size_t vector_bytes = (n_vecs + 1) * sizeof (bitset) + bytes - 1; vector_bytes -= vector_bytes % bytes; - bitset *bsetv = xcalloc (1, vector_bytes + bytes * n_vecs); + bitset *bsetv = xzalloc (vector_bytes + bytes * n_vecs); bitset_bindex i = 0; for (i = 0; i < n_vecs; i++) @@ -71,9 +71,12 @@ bitsetv_create (bitset_bindex n_vecs, bitset_bindex n_bits, unsigned attr) void bitsetv_free (bitsetv bsetv) { - for (bitset_bindex i = 0; bsetv[i]; i++) - BITSET_FREE_ (bsetv[i]); - free (bsetv); + if (bsetv) + { + for (bitset_bindex i = 0; bsetv[i]; i++) + BITSET_FREE_ (bsetv[i]); + free (bsetv); + } } diff --git a/contrib/tools/bison/lib/bitsetv.h b/contrib/tools/bison/lib/bitsetv.h index 798b70d9b4..13e9ba4cd6 100644 --- a/contrib/tools/bison/lib/bitsetv.h +++ b/contrib/tools/bison/lib/bitsetv.h @@ -1,6 +1,6 @@ /* Bitset vectors. - Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifndef _BITSETV_H #define _BITSETV_H @@ -33,7 +33,7 @@ bitsetv bitsetv_alloc (bitset_bindex, bitset_bindex, enum bitset_type); attribute hints specified by ATTR. */ bitsetv bitsetv_create (bitset_bindex, bitset_bindex, unsigned); -/* Free vector of bitsets. */ +/* Free vector of bitsets. Do nothing if NULL. */ void bitsetv_free (bitsetv); /* Zero vector of bitsets. */ diff --git a/contrib/tools/bison/lib/c-ctype.h b/contrib/tools/bison/lib/c-ctype.h index 4d52176384..fbd11b3450 100644 --- a/contrib/tools/bison/lib/c-ctype.h +++ b/contrib/tools/bison/lib/c-ctype.h @@ -5,7 +5,7 @@ <ctype.h> functions' behaviour depends on the current locale set via setlocale. - Copyright (C) 2000-2003, 2006, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2000-2003, 2006, 2008-2020 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 diff --git a/contrib/tools/bison/lib/c-strcase.h b/contrib/tools/bison/lib/c-strcase.h index b67c9b5da0..3b711f5aa5 100644 --- a/contrib/tools/bison/lib/c-strcase.h +++ b/contrib/tools/bison/lib/c-strcase.h @@ -1,5 +1,5 @@ /* Case-insensitive string comparison functions in C locale. - Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2019 Free Software + Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/c-strcasecmp.c b/contrib/tools/bison/lib/c-strcasecmp.c index ec50f1abe7..951220f3e2 100644 --- a/contrib/tools/bison/lib/c-strcasecmp.c +++ b/contrib/tools/bison/lib/c-strcasecmp.c @@ -1,5 +1,5 @@ /* c-strcasecmp.c -- case insensitive string comparator in C locale - Copyright (C) 1998-1999, 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1998-1999, 2005-2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/c-strcaseeq.h b/contrib/tools/bison/lib/c-strcaseeq.h index bcc81fc388..304c72ea49 100644 --- a/contrib/tools/bison/lib/c-strcaseeq.h +++ b/contrib/tools/bison/lib/c-strcaseeq.h @@ -1,5 +1,5 @@ /* Optimized case-insensitive string comparison in C locale. - Copyright (C) 2001-2002, 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/c-strncasecmp.c b/contrib/tools/bison/lib/c-strncasecmp.c index 513c353f6c..9ad49191b7 100644 --- a/contrib/tools/bison/lib/c-strncasecmp.c +++ b/contrib/tools/bison/lib/c-strncasecmp.c @@ -1,5 +1,5 @@ /* c-strncasecmp.c -- case insensitive string comparator in C locale - Copyright (C) 1998-1999, 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1998-1999, 2005-2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/careadlinkat.c b/contrib/tools/bison/lib/careadlinkat.c index e56d503085..1effdb7845 100644 --- a/contrib/tools/bison/lib/careadlinkat.c +++ b/contrib/tools/bison/lib/careadlinkat.c @@ -1,6 +1,6 @@ /* Read symbolic links into a buffer without size limitation, relative to fd. - Copyright (C) 2001, 2003-2004, 2007, 2009-2019 Free Software Foundation, + Copyright (C) 2001, 2003-2004, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -54,7 +54,7 @@ The PREADLINKAT function specifies how to read links. It operates like POSIX readlinkat() - <http://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html> + <https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html> but can assume that its first argument is the same as FD. If successful, return the buffer address; otherwise return NULL and diff --git a/contrib/tools/bison/lib/careadlinkat.h b/contrib/tools/bison/lib/careadlinkat.h index 68b69aa889..a4a37b274d 100644 --- a/contrib/tools/bison/lib/careadlinkat.h +++ b/contrib/tools/bison/lib/careadlinkat.h @@ -1,6 +1,6 @@ /* Read symbolic links into a buffer without size limitation, relative to fd. - Copyright (C) 2011-2019 Free Software Foundation, Inc. + Copyright (C) 2011-2020 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 @@ -40,14 +40,14 @@ struct allocator; The PREADLINKAT function specifies how to read links. It operates like POSIX readlinkat() - <http://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html> + <https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html> but can assume that its first argument is the same as FD. If successful, return the buffer address; otherwise return NULL and set errno. */ char *careadlinkat (int fd, char const *filename, - char *buffer, size_t buffer_size, + char *restrict buffer, size_t buffer_size, struct allocator const *alloc, ssize_t (*preadlinkat) (int, char const *, char *, size_t)); diff --git a/contrib/tools/bison/lib/cloexec.c b/contrib/tools/bison/lib/cloexec.c index db425766a0..510be3d57e 100644 --- a/contrib/tools/bison/lib/cloexec.c +++ b/contrib/tools/bison/lib/cloexec.c @@ -1,6 +1,6 @@ /* cloexec.c - set or clear the close-on-exec descriptor flag - Copyright (C) 1991, 2004-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1991, 2004-2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/cloexec.h b/contrib/tools/bison/lib/cloexec.h index 06ad945d8e..f14a99736d 100644 --- a/contrib/tools/bison/lib/cloexec.h +++ b/contrib/tools/bison/lib/cloexec.h @@ -1,6 +1,6 @@ /* cloexec.c - set or clear the close-on-exec descriptor flag - Copyright (C) 2004, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2004, 2009-2020 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 diff --git a/contrib/tools/bison/lib/close-stream.c b/contrib/tools/bison/lib/close-stream.c index 5458c4f29f..04bc8009a5 100644 --- a/contrib/tools/bison/lib/close-stream.c +++ b/contrib/tools/bison/lib/close-stream.c @@ -1,6 +1,6 @@ /* Close a stream, with nicer error checking than fclose's. - Copyright (C) 1998-2002, 2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 1998-2002, 2004, 2006-2020 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 diff --git a/contrib/tools/bison/lib/close.c b/contrib/tools/bison/lib/close.c index 40ce845bc3..0c8780dc24 100644 --- a/contrib/tools/bison/lib/close.c +++ b/contrib/tools/bison/lib/close.c @@ -1,5 +1,5 @@ /* close replacement. - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 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 diff --git a/contrib/tools/bison/lib/closeout.c b/contrib/tools/bison/lib/closeout.c index 4a604ec35d..8b92ce9476 100644 --- a/contrib/tools/bison/lib/closeout.c +++ b/contrib/tools/bison/lib/closeout.c @@ -1,6 +1,6 @@ /* Close standard output and standard error, exiting with a diagnostic on error. - Copyright (C) 1998-2002, 2004, 2006, 2008-2019 Free Software Foundation, + Copyright (C) 1998-2002, 2004, 2006, 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/closeout.h b/contrib/tools/bison/lib/closeout.h index ac89f760a9..8294c6268c 100644 --- a/contrib/tools/bison/lib/closeout.h +++ b/contrib/tools/bison/lib/closeout.h @@ -1,6 +1,6 @@ /* Close standard output and standard error. - Copyright (C) 1998, 2000, 2003-2004, 2006, 2008-2019 Free Software + Copyright (C) 1998, 2000, 2003-2004, 2006, 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/concat-filename.c b/contrib/tools/bison/lib/concat-filename.c index df0e170a89..367e41d22c 100644 --- a/contrib/tools/bison/lib/concat-filename.c +++ b/contrib/tools/bison/lib/concat-filename.c @@ -1,5 +1,5 @@ /* Construct a full filename from a directory and a relative filename. - Copyright (C) 2001-2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006-2020 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 diff --git a/contrib/tools/bison/lib/concat-filename.h b/contrib/tools/bison/lib/concat-filename.h index 4448b783fc..64b461e39d 100644 --- a/contrib/tools/bison/lib/concat-filename.h +++ b/contrib/tools/bison/lib/concat-filename.h @@ -1,5 +1,5 @@ /* Construct a full filename from a directory and a relative filename. - Copyright (C) 2001-2004, 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2007-2020 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 diff --git a/contrib/tools/bison/lib/config-linux.h b/contrib/tools/bison/lib/config-linux.h index 9c4e201410..5d1714a49f 100644 --- a/contrib/tools/bison/lib/config-linux.h +++ b/contrib/tools/bison/lib/config-linux.h @@ -31,9 +31,6 @@ /* Define to 1 if using `alloca.c'. */ /* #undef C_ALLOCA */ -/* Define to 1 if the C locale may have encoding errors. */ -#define C_LOCALE_MAYBE_EILSEQ 1 - /* Define as the bit index in the word where to find bit 0 of the exponent of 'double'. */ #define DBL_EXPBIT0_BIT 20 @@ -113,7 +110,7 @@ /* Define to a C preprocessor expression that evaluates to 1 or 0, depending whether the gnulib module lock shall be considered present. */ -/* #undef GNULIB_LOCK */ +#define GNULIB_LOCK 1 /* Define to a C preprocessor expression that evaluates to 1 or 0, depending whether the gnulib module malloc-gnu shall be considered present. */ @@ -187,9 +184,15 @@ /* Define to 1 when the gnulib module fstat should be tested. */ /* #undef GNULIB_TEST_FSTAT */ +/* Define to 1 when the gnulib module fsync should be tested. */ +#define GNULIB_TEST_FSYNC 1 + /* Define to 1 when the gnulib module getdtablesize should be tested. */ #define GNULIB_TEST_GETDTABLESIZE 1 +/* Define to 1 when the gnulib module getopt-posix should be tested. */ +#define GNULIB_TEST_GETOPT_POSIX 1 + /* Define to 1 when the gnulib module getrusage should be tested. */ #define GNULIB_TEST_GETRUSAGE 1 @@ -208,6 +211,15 @@ /* Define to 1 when the gnulib module isnanl should be tested. */ #define GNULIB_TEST_ISNANL 1 +/* Define to 1 when the gnulib module iswblank should be tested. */ +#define GNULIB_TEST_ISWBLANK 1 + +/* Define to 1 when the gnulib module iswdigit should be tested. */ +#define GNULIB_TEST_ISWDIGIT 1 + +/* Define to 1 when the gnulib module iswxdigit should be tested. */ +#define GNULIB_TEST_ISWXDIGIT 1 + /* Define to 1 when the gnulib module ldexpl should be tested. */ #define GNULIB_TEST_LDEXPL 1 @@ -301,6 +313,9 @@ /* Define to 1 when the gnulib module rmdir should be tested. */ /* #undef GNULIB_TEST_RMDIR */ +/* Define to 1 when the gnulib module setlocale_null should be tested. */ +#define GNULIB_TEST_SETLOCALE_NULL 1 + /* Define to 1 when the gnulib module sigaction should be tested. */ #define GNULIB_TEST_SIGACTION 1 @@ -349,6 +364,9 @@ /* Define to 1 when the gnulib module unsetenv should be tested. */ #define GNULIB_TEST_UNSETENV 1 +/* Define to 1 when the gnulib module vasprintf should be tested. */ +#define GNULIB_TEST_VASPRINTF 1 + /* Define to 1 when the gnulib module vfprintf-posix should be tested. */ #define GNULIB_TEST_VFPRINTF_POSIX 1 @@ -364,6 +382,9 @@ /* Define to 1 when the gnulib module wcwidth should be tested. */ #define GNULIB_TEST_WCWIDTH 1 +/* Define if your system defines TIOCGWINSZ in sys/ioctl.h. */ +#define GWINSZ_IN_SYS_IOCTL 1 + /* Define to 1 if you have 'alloca' after including <alloca.h>, a header that may be supplied by this distribution. */ #define HAVE_ALLOCA 1 @@ -391,10 +412,6 @@ CoreFoundation framework. */ /* #undef HAVE_CFLOCALECOPYCURRENT */ -/* Define to 1 if you have the Mac OS X function - CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */ -/* #undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES */ - /* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in the CoreFoundation framework. */ /* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */ @@ -420,6 +437,9 @@ libc. */ /* #undef HAVE_COPYSIGN_IN_LIBC */ +/* Define to 1 if you have the `copy_file_range' function. */ +/* #undef HAVE_COPY_FILE_RANGE */ + /* Define to 1 if you have the <crtdefs.h> header file. */ /* #undef HAVE_CRTDEFS_H */ @@ -495,6 +515,10 @@ don't. */ #define HAVE_DECL_GETHRTIME 0 +/* Define to 1 if you have the declaration of `iswblank', and to 0 if you + don't. */ +#define HAVE_DECL_ISWBLANK 1 + /* Define to 1 if you have the declaration of `mbrtowc', and to 0 if you don't. */ /* #undef HAVE_DECL_MBRTOWC */ @@ -597,6 +621,9 @@ /* Define if the frexp function is available in libc. */ #define HAVE_FREXP_IN_LIBC 1 +/* Define to 1 if you have the `fsync' function. */ +#define HAVE_FSYNC 1 + /* Define to 1 if you have the `getcwd' function. */ #define HAVE_GETCWD 1 @@ -649,6 +676,9 @@ /* Define if the isnan(long double) function is available in libc. */ #define HAVE_ISNANL_IN_LIBC 1 +/* Define to 1 if you have the `iswblank' function. */ +#define HAVE_ISWBLANK 1 + /* Define to 1 if you have the `iswcntrl' function. */ #define HAVE_ISWCNTRL 1 @@ -664,6 +694,9 @@ /* Define if the ldexp function is available in libc. */ #define HAVE_LDEXP_IN_LIBC 1 +/* Define if you have the libtextstyle library. */ +/* #undef HAVE_LIBTEXTSTYLE */ + /* Define to 1 if you have the <limits.h> header file. */ #define HAVE_LIMITS_H 1 @@ -754,11 +787,14 @@ /* Define to 1 if the system has the type `posix_spawn_file_actions_t'. */ #define HAVE_POSIX_SPAWN_FILE_ACTIONS_T 1 +/* Define if you have the <pthread.h> header and the POSIX threads API. */ +#define HAVE_PTHREAD_API 1 + /* Define if the <pthread.h> defines PTHREAD_MUTEX_RECURSIVE. */ -/* #undef HAVE_PTHREAD_MUTEX_RECURSIVE */ +#define HAVE_PTHREAD_MUTEX_RECURSIVE 1 /* Define if the POSIX multithreading library has read/write locks. */ -/* #undef HAVE_PTHREAD_RWLOCK */ +#define HAVE_PTHREAD_RWLOCK 1 /* Define if the 'pthread_rwlock_rdlock' function prefers a writer to a reader. */ @@ -786,7 +822,7 @@ /* #undef HAVE_SAME_LONG_DOUBLE_AS_DOUBLE */ /* Define to 1 if you have the <sched.h> header file. */ -/* #undef HAVE_SCHED_H */ +#define HAVE_SCHED_H 1 /* Define to 1 if you have the `sched_setparam' function. */ /* #undef HAVE_SCHED_SETPARAM */ @@ -956,6 +992,15 @@ /* Define to 1 if you have the <sys/wait.h> header file. */ #define HAVE_SYS_WAIT_H 1 +/* Define to 1 if you have the `tcdrain' function. */ +#define HAVE_TCDRAIN 1 + +/* Define to 1 if you have the `thrd_create' function. */ +/* #undef HAVE_THRD_CREATE */ + +/* Define to 1 if you have the <threads.h> header file. */ +#define HAVE_THREADS_H 1 + /* Define to 1 if you have the `towlower' function. */ #define HAVE_TOWLOWER 1 @@ -977,9 +1022,16 @@ /* Define to 1 if you have the `vasnprintf' function. */ /* #undef HAVE_VASNPRINTF */ +/* Define to 1 if you have the `vasprintf' function. */ +#define HAVE_VASPRINTF 1 + /* Define to 1 if you have the `vfork' function. */ /* #undef HAVE_VFORK */ +/* Define to 1 or 0, depending whether the compiler supports simple visibility + declarations. */ +/* #undef HAVE_VISIBILITY */ + /* Define to 1 if you have the `vsnprintf' function. */ #define HAVE_VSNPRINTF 1 @@ -1007,6 +1059,10 @@ /* Define to 1 if you have the `wcwidth' function. */ #define HAVE_WCWIDTH 1 +/* Define to 1 if the compiler and linker support weak declarations of + symbols. */ +#define HAVE_WEAK_SYMBOLS 1 + /* Define to 1 if you have the <winsock2.h> header file. */ /* #undef HAVE_WINSOCK2_H */ @@ -1019,6 +1075,9 @@ /* Define to 1 if O_NOFOLLOW works. */ #define HAVE_WORKING_O_NOFOLLOW 1 +/* Define to 1 if you have the <xlocale.h> header file. */ +/* #undef HAVE_XLOCALE_H */ + /* Define to 1 if the system has the type `_Bool'. */ #define HAVE__BOOL 1 @@ -1031,11 +1090,14 @@ /* Define to 1 if you have the `__fseterr' function. */ /* #undef HAVE___FSETERR */ +/* Define to 1 if the compiler supports the keyword '__inline'. */ +/* #undef HAVE___INLINE */ + /* Define to 1 if you have the `__xpg_strerror_r' function. */ #define HAVE___XPG_STRERROR_R 1 /* Define to the value of ${prefix}, as a string. */ -#define INSTALLPREFIX "/var/empty/bison-3.3.2" +#define INSTALLPREFIX "/var/empty/bison-3.5.4" /* Define as the bit index in the word where to find bit 0 of the exponent of 'long double'. */ @@ -1071,6 +1133,10 @@ */ /* #undef MBRTOWC_EMPTY_INPUT_BUG */ +/* Define if the mbrtowc function may signal encoding errors in the C locale. + */ +#define MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ 1 + /* Define if the mbrtowc function has the NULL pwc argument bug. */ /* #undef MBRTOWC_NULL_ARG1_BUG */ @@ -1083,6 +1149,10 @@ /* Define if the mbrtowc function returns a wrong return value. */ /* #undef MBRTOWC_RETVAL_BUG */ +/* Define if the mbrtowc function stores a wide character when reporting + incomplete input. */ +/* #undef MBRTOWC_STORES_INCOMPLETE_BUG */ + /* Use GNU style printf and scanf. */ #ifndef __USE_MINGW_ANSI_STDIO # define __USE_MINGW_ANSI_STDIO 1 @@ -1150,22 +1220,22 @@ #define PACKAGE_BUGREPORT "bug-bison@gnu.org" /* The copyright year for this package */ -#define PACKAGE_COPYRIGHT_YEAR 2019 +#define PACKAGE_COPYRIGHT_YEAR 2020 /* Define to the full name of this package. */ #define PACKAGE_NAME "GNU Bison" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "GNU Bison 3.3.2" +#define PACKAGE_STRING "GNU Bison 3.5.4" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "bison" /* Define to the home page for this package. */ -#define PACKAGE_URL "http://www.gnu.org/software/bison/" +#define PACKAGE_URL "https://www.gnu.org/software/bison/" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.3.2" +#define PACKAGE_VERSION "3.5.4" /* Define if <inttypes.h> exists and defines unusable PRI* macros. */ /* #undef PRI_MACROS_BROKEN */ @@ -1225,10 +1295,18 @@ implementation. */ #define REPLACE_VFPRINTF_POSIX 1 +/* Define to 1 if setlocale (LC_ALL, NULL) is multithread-safe. */ +#define SETLOCALE_NULL_ALL_MTSAFE 1 + +/* Define to 1 if setlocale (category, NULL) is multithread-safe. */ +#define SETLOCALE_NULL_ONE_MTSAFE 1 + /* File name of the Bourne shell. */ -#if defined __CYGWIN__ -/* Omit the directory part because for 32-bit Cygwin programs in a - 64-bit Cygwin environment, the Cygwin mounts are not visible. */ +#if defined __CYGWIN__ || defined __ANDROID__ +/* Omit the directory part because + - For 32-bit Cygwin programs in a 64-bit Cygwin environment, the Cygwin + mounts are not visible. + - On Android, /bin/sh does not exist. It's /system/bin/sh instead. */ # define BOURNE_SHELL "sh" #else # define BOURNE_SHELL "/bin/sh" @@ -1276,6 +1354,13 @@ an underscore or empty. */ #define USER_LABEL_PREFIX +/* Define if the combination of the ISO C and POSIX multithreading APIs can be + used. */ +/* #undef USE_ISOC_AND_POSIX_THREADS */ + +/* Define if the ISO C multithreading library can be used. */ +/* #undef USE_ISOC_THREADS */ + /* Define if the POSIX multithreading library can be used. */ #define USE_POSIX_THREADS 1 @@ -1283,20 +1368,6 @@ weak. */ #define USE_POSIX_THREADS_WEAK 1 -/* Define if the GNU Pth multithreading library can be used. */ -/* #undef USE_PTH_THREADS */ - -/* Define if references to the GNU Pth multithreading library should be made - weak. */ -/* #undef USE_PTH_THREADS_WEAK */ - -/* Define if the old Solaris multithreading library can be used. */ -/* #undef USE_SOLARIS_THREADS */ - -/* Define if references to the old Solaris multithreading library should be - made weak. */ -/* #undef USE_SOLARIS_THREADS_WEAK */ - /* Enable extensions on AIX 3, Interix. */ #ifndef _ALL_SOURCE # define _ALL_SOURCE 1 @@ -1379,7 +1450,7 @@ /* #undef USE_WINDOWS_THREADS */ /* Version number of package */ -#define VERSION "3.3.2" +#define VERSION "3.5.4" /* Define to 1 if unsetenv returns void instead of int. */ /* #undef VOID_UNSETENV */ @@ -1388,13 +1459,13 @@ 'wchar_t'. */ /* #undef WCHAR_T_SUFFIX */ +/* Define if sys/ptem.h is required for struct winsize. */ +/* #undef WINSIZE_IN_PTEM */ + /* Define to l, ll, u, ul, ull, etc., as suitable for constants of type 'wint_t'. */ /* #undef WINT_T_SUFFIX */ -/* Define if using the dmalloc debugging malloc package */ -/* #undef WITH_DMALLOC */ - /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ #if defined AC_APPLE_UNIVERSAL_BUILD @@ -1414,15 +1485,15 @@ `char[]'. */ /* #undef YYTEXT_POINTER */ -/* Enable large inode numbers on Mac OS X 10.5. */ -#define _DARWIN_USE_64_BIT_INODE 1 - /* Number of bits in a file offset, on hosts where this is settable. */ /* #undef _FILE_OFFSET_BITS */ /* Define for large files, on AIX-style hosts. */ /* #undef _LARGE_FILES */ +/* Define to 1 on Solaris. */ +/* #undef _LCONV_C99 */ + /* Define to 1 if on MINIX. */ /* #undef _MINIX */ @@ -1431,10 +1502,23 @@ /* The _Noreturn keyword of C11. */ #ifndef _Noreturn -# if 201103 <= (defined __cplusplus ? __cplusplus : 0) +# if (defined __cplusplus \ + && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \ + || (defined _MSC_VER && 1900 <= _MSC_VER)) \ + && 0) + /* [[noreturn]] is not practically usable, because with it the syntax + extern _Noreturn void func (...); + would not be valid; such a declaration would only be valid with 'extern' + and '_Noreturn' swapped, or without the 'extern' keyword. However, some + AIX system header files and several gnulib header files use precisely + this syntax with 'extern'. */ # define _Noreturn [[noreturn]] -# elif (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ - || 4 < __GNUC__ + (7 <= __GNUC_MINOR__)) +# elif ((!defined __cplusplus || defined __clang__) \ + && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ + || 4 < __GNUC__ + (7 <= __GNUC_MINOR__) \ + || (defined __apple_build_version__ \ + ? 6000000 <= __apple_build_version__ \ + : 3 < __clang_major__ + (5 <= __clang_minor__)))) /* _Noreturn works as-is. */ # elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C # define _Noreturn __attribute__ ((__noreturn__)) @@ -1466,6 +1550,33 @@ /* Define to 1 if the system <stdint.h> predates C++11. */ /* #undef __STDC_LIMIT_MACROS */ +/* The _GL_ASYNC_SAFE marker should be attached to functions that are + signal handlers (for signals other than SIGABRT, SIGPIPE) or can be + invoked from such signal handlers. Such functions have some restrictions: + * All functions that it calls should be marked _GL_ASYNC_SAFE as well, + or should be listed as async-signal-safe in POSIX + <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04> + section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in + particular, are NOT async-signal-safe. + * All memory locations (variables and struct fields) that these functions + access must be marked 'volatile'. This holds for both read and write + accesses. Otherwise the compiler might optimize away stores to and + reads from such locations that occur in the program, depending on its + data flow analysis. For example, when the program contains a loop + that is intended to inspect a variable set from within a signal handler + while (!signal_occurred) + ; + the compiler is allowed to transform this into an endless loop if the + variable 'signal_occurred' is not declared 'volatile'. + Additionally, recall that: + * A signal handler should not modify errno (except if it is a handler + for a fatal signal and ends by raising the same signal again, thus + provoking the termination of the process). If it invokes a function + that may clobber errno, it needs to save and restore the value of + errno. */ +#define _GL_ASYNC_SAFE + + /* Please see the Gnulib manual for how to use these macros. Suppress extern inline with HP-UX cc, as it appears to be broken; see @@ -1490,7 +1601,7 @@ https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html DragonFly; see - http://muscles.dragonflybsd.org/bulk/bleeding-edge-potential/latest-per-pkg/ah-tty-0.3.12.log + http://muscles.dragonflybsd.org/bulk/clang-master-potential/20141111_102002/logs/ah-tty-0.3.12.log FreeBSD; see: https://lists.gnu.org/r/bug-gnulib/2014-07/msg00104.html @@ -1612,12 +1723,13 @@ nothing if this is not supported. Do not define if restrict is supported directly. */ #define restrict __restrict -/* Work around a bug in Sun C++: it does not support _Restrict or - __restrict__, even though the corresponding Sun C compiler ends up with - "#define restrict _Restrict" or "#define restrict __restrict__" in the - previous line. Perhaps some future version of Sun C++ will work with - restrict; if so, hopefully it defines __RESTRICT like Sun C does. */ -#if defined __SUNPRO_CC && !defined __RESTRICT +/* Work around a bug in older versions of Sun C++, which did not + #define __restrict__ or support _Restrict or __restrict__ + even though the corresponding Sun C compiler ended up with + "#define restrict _Restrict" or "#define restrict __restrict__" + in the previous line. This workaround can be removed once + we assume Oracle Developer Studio 12.5 (2016) or later. */ +#if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__ # define _Restrict # define __restrict__ #endif @@ -1678,4 +1790,5 @@ # define _GL_ATTRIBUTE_MALLOC /* empty */ #endif +#undef HAVE_THREADS_H #define _GL_ATTRIBUTE_FORMAT_PRINTF(...) diff --git a/contrib/tools/bison/lib/config-win.h b/contrib/tools/bison/lib/config-win.h index a3a4ad1ade..ef3a3edc5b 100644 --- a/contrib/tools/bison/lib/config-win.h +++ b/contrib/tools/bison/lib/config-win.h @@ -1226,7 +1226,7 @@ char *strsignal (int signum); /* #undef PACKAGE_PACKAGER_VERSION */ /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "GNU Bison 3.3.2" +#define PACKAGE_STRING "GNU Bison 3.5.4" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "m4" @@ -1235,7 +1235,7 @@ char *strsignal (int signum); #define PACKAGE_URL "http://www.gnu.org/software/m4/" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.3.2" +#define PACKAGE_VERSION "3.5.4" /* Define if <inttypes.h> exists and defines unusable PRI* macros. */ /* #undef PRI_MACROS_BROKEN */ @@ -1398,7 +1398,7 @@ char *strsignal (int signum); /* #undef USE_WINDOWS_THREADS */ /* Version number of package */ -#define VERSION "3.3.2" +#define VERSION "3.5.4" /* Define to 1 if unsetenv returns void instead of int. */ /* #undef VOID_UNSETENV */ @@ -1709,3 +1709,4 @@ char *strsignal (int signum); #define _GL_ATTRIBUTE_FORMAT_PRINTF(...) #define HAVE_ISNANL_IN_LIBC 1 #define HAVE_ISNAND_IN_LIBC 1 +#define _GL_ASYNC_SAFE diff --git a/contrib/tools/bison/lib/configmake-linux.h b/contrib/tools/bison/lib/configmake-linux.h index 14fe253583..7dc40e17b9 100644 --- a/contrib/tools/bison/lib/configmake-linux.h +++ b/contrib/tools/bison/lib/configmake-linux.h @@ -1,28 +1,31 @@ /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ -#define PREFIX "/var/empty/bison-3.3.2" -#define EXEC_PREFIX "/var/empty/bison-3.3.2" -#define BINDIR "/var/empty/bison-3.3.2/bin" -#define SBINDIR "/var/empty/bison-3.3.2/sbin" -#define LIBEXECDIR "/var/empty/bison-3.3.2/libexec" -#define DATAROOTDIR "/var/empty/bison-3.3.2/share" -#define DATADIR "/var/empty/bison-3.3.2/share" -#define SYSCONFDIR "/var/empty/bison-3.3.2/etc" -#define SHAREDSTATEDIR "/var/empty/bison-3.3.2/com" -#define LOCALSTATEDIR "/var/empty/bison-3.3.2/var" -#define RUNSTATEDIR "/var/empty/bison-3.3.2/var/run" -#define INCLUDEDIR "/var/empty/bison-3.3.2/include" +#if HAVE_WINSOCK2_H +# include <winsock2.h> /* avoid mingw pollution on DATADIR */ +#endif +#define PREFIX "/var/empty/bison-3.5.4" +#define EXEC_PREFIX "/var/empty/bison-3.5.4" +#define BINDIR "/var/empty/bison-3.5.4/bin" +#define SBINDIR "/var/empty/bison-3.5.4/sbin" +#define LIBEXECDIR "/var/empty/bison-3.5.4/libexec" +#define DATAROOTDIR "/var/empty/bison-3.5.4/share" +#define DATADIR "/var/empty/bison-3.5.4/share" +#define SYSCONFDIR "/var/empty/bison-3.5.4/etc" +#define SHAREDSTATEDIR "/var/empty/bison-3.5.4/com" +#define LOCALSTATEDIR "/var/empty/bison-3.5.4/var" +#define RUNSTATEDIR "/var/empty/bison-3.5.4/var/run" +#define INCLUDEDIR "/var/empty/bison-3.5.4/include" #define OLDINCLUDEDIR "/usr/include" -#define DOCDIR "/var/empty/bison-3.3.2/share/doc/bison" -#define INFODIR "/var/empty/bison-3.3.2/share/info" -#define HTMLDIR "/var/empty/bison-3.3.2/share/doc/bison" -#define DVIDIR "/var/empty/bison-3.3.2/share/doc/bison" -#define PDFDIR "/var/empty/bison-3.3.2/share/doc/bison" -#define PSDIR "/var/empty/bison-3.3.2/share/doc/bison" -#define LIBDIR "/var/empty/bison-3.3.2/lib" -#define LISPDIR "/var/empty/bison-3.3.2/share/emacs/site-lisp" -#define LOCALEDIR "/var/empty/bison-3.3.2/share/locale" -#define MANDIR "/var/empty/bison-3.3.2/share/man" -#define PKGDATADIR "/var/empty/bison-3.3.2/share/bison" -#define PKGINCLUDEDIR "/var/empty/bison-3.3.2/include/bison" -#define PKGLIBDIR "/var/empty/bison-3.3.2/lib/bison" -#define PKGLIBEXECDIR "/var/empty/bison-3.3.2/libexec/bison" +#define DOCDIR "/var/empty/bison-3.5.4/share/doc/bison" +#define INFODIR "/var/empty/bison-3.5.4/share/info" +#define HTMLDIR "/var/empty/bison-3.5.4/share/doc/bison" +#define DVIDIR "/var/empty/bison-3.5.4/share/doc/bison" +#define PDFDIR "/var/empty/bison-3.5.4/share/doc/bison" +#define PSDIR "/var/empty/bison-3.5.4/share/doc/bison" +#define LIBDIR "/var/empty/bison-3.5.4/lib" +#define LISPDIR "/var/empty/bison-3.5.4/share/emacs/site-lisp" +#define LOCALEDIR "/var/empty/bison-3.5.4/share/locale" +#define MANDIR "/var/empty/bison-3.5.4/share/man" +#define PKGDATADIR "/var/empty/bison-3.5.4/share/bison" +#define PKGINCLUDEDIR "/var/empty/bison-3.5.4/include/bison" +#define PKGLIBDIR "/var/empty/bison-3.5.4/lib/bison" +#define PKGLIBEXECDIR "/var/empty/bison-3.5.4/libexec/bison" diff --git a/contrib/tools/bison/lib/configmake-win.h b/contrib/tools/bison/lib/configmake-win.h index 3efbed28df..5c53dc59ec 100644 --- a/contrib/tools/bison/lib/configmake-win.h +++ b/contrib/tools/bison/lib/configmake-win.h @@ -1,3 +1,2 @@ -/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ - #define LOCALEDIR "C:\\Windows" +#define PKGDATADIR "C:\\Windows" diff --git a/contrib/tools/bison/lib/diffseq.h b/contrib/tools/bison/lib/diffseq.h new file mode 100644 index 0000000000..c89363ac9e --- /dev/null +++ b/contrib/tools/bison/lib/diffseq.h @@ -0,0 +1,529 @@ +/* Analyze differences between two vectors. + + Copyright (C) 1988-1989, 1992-1995, 2001-2004, 2006-2020 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 <https://www.gnu.org/licenses/>. */ + + +/* The basic idea is to consider two vectors as similar if, when + transforming the first vector into the second vector through a + sequence of edits (inserts and deletes of one element each), + this sequence is short - or equivalently, if the ordered list + of elements that are untouched by these edits is long. For a + good introduction to the subject, read about the "Levenshtein + distance" in Wikipedia. + + The basic algorithm is described in: + "An O(ND) Difference Algorithm and its Variations", Eugene W. Myers, + Algorithmica Vol. 1, 1986, pp. 251-266, + <https://doi.org/10.1007/BF01840446>. + See especially section 4.2, which describes the variation used below. + + The basic algorithm was independently discovered as described in: + "Algorithms for Approximate String Matching", Esko Ukkonen, + Information and Control Vol. 64, 1985, pp. 100-118, + <https://doi.org/10.1016/S0019-9958(85)80046-2>. + + Unless the 'find_minimal' flag is set, this code uses the TOO_EXPENSIVE + heuristic, by Paul Eggert, to limit the cost to O(N**1.5 log N) + at the price of producing suboptimal output for large inputs with + many differences. */ + +/* Before including this file, you need to define: + ELEMENT The element type of the vectors being compared. + EQUAL A two-argument macro that tests two elements for + equality. + OFFSET A signed integer type sufficient to hold the + difference between two indices. Usually + something like ptrdiff_t. + EXTRA_CONTEXT_FIELDS Declarations of fields for 'struct context'. + NOTE_DELETE(ctxt, xoff) Record the removal of the object xvec[xoff]. + NOTE_INSERT(ctxt, yoff) Record the insertion of the object yvec[yoff]. + EARLY_ABORT(ctxt) (Optional) A boolean expression that triggers an + early abort of the computation. + USE_HEURISTIC (Optional) Define if you want to support the + heuristic for large vectors. + It is also possible to use this file with abstract arrays. In this case, + xvec and yvec are not represented in memory. They only exist conceptually. + In this case, the list of defines above is amended as follows: + ELEMENT Undefined. + EQUAL Undefined. + XVECREF_YVECREF_EQUAL(ctxt, xoff, yoff) + A three-argument macro: References xvec[xoff] and + yvec[yoff] and tests these elements for equality. + Before including this file, you also need to include: + #include <limits.h> + #include <stdbool.h> + #include "minmax.h" + */ + +/* Maximum value of type OFFSET. */ +#define OFFSET_MAX \ + ((((OFFSET)1 << (sizeof (OFFSET) * CHAR_BIT - 2)) - 1) * 2 + 1) + +/* Default to no early abort. */ +#ifndef EARLY_ABORT +# define EARLY_ABORT(ctxt) false +#endif + +/* Use this to suppress gcc's "...may be used before initialized" warnings. + Beware: The Code argument must not contain commas. */ +#ifndef IF_LINT +# if defined GCC_LINT || defined lint +# define IF_LINT(Code) Code +# else +# define IF_LINT(Code) /* empty */ +# endif +#endif + +/* As above, but when Code must contain one comma. */ +#ifndef IF_LINT2 +# if defined GCC_LINT || defined lint +# define IF_LINT2(Code1, Code2) Code1, Code2 +# else +# define IF_LINT2(Code1, Code2) /* empty */ +# endif +#endif + +/* + * Context of comparison operation. + */ +struct context +{ + #ifdef ELEMENT + /* Vectors being compared. */ + ELEMENT const *xvec; + ELEMENT const *yvec; + #endif + + /* Extra fields. */ + EXTRA_CONTEXT_FIELDS + + /* Vector, indexed by diagonal, containing 1 + the X coordinate of the point + furthest along the given diagonal in the forward search of the edit + matrix. */ + OFFSET *fdiag; + + /* Vector, indexed by diagonal, containing the X coordinate of the point + furthest along the given diagonal in the backward search of the edit + matrix. */ + OFFSET *bdiag; + + #ifdef USE_HEURISTIC + /* This corresponds to the diff --speed-large-files flag. With this + heuristic, for vectors with a constant small density of changes, + the algorithm is linear in the vector size. */ + bool heuristic; + #endif + + /* Edit scripts longer than this are too expensive to compute. */ + OFFSET too_expensive; + + /* Snakes bigger than this are considered "big". */ + #define SNAKE_LIMIT 20 +}; + +struct partition +{ + /* Midpoints of this partition. */ + OFFSET xmid; + OFFSET ymid; + + /* True if low half will be analyzed minimally. */ + bool lo_minimal; + + /* Likewise for high half. */ + bool hi_minimal; +}; + + +/* Find the midpoint of the shortest edit script for a specified portion + of the two vectors. + + Scan from the beginnings of the vectors, and simultaneously from the ends, + doing a breadth-first search through the space of edit-sequence. + When the two searches meet, we have found the midpoint of the shortest + edit sequence. + + If FIND_MINIMAL is true, find the minimal edit script regardless of + expense. Otherwise, if the search is too expensive, use heuristics to + stop the search and report a suboptimal answer. + + Set PART->(xmid,ymid) to the midpoint (XMID,YMID). The diagonal number + XMID - YMID equals the number of inserted elements minus the number + of deleted elements (counting only elements before the midpoint). + + Set PART->lo_minimal to true iff the minimal edit script for the + left half of the partition is known; similarly for PART->hi_minimal. + + This function assumes that the first elements of the specified portions + of the two vectors do not match, and likewise that the last elements do not + match. The caller must trim matching elements from the beginning and end + of the portions it is going to specify. + + If we return the "wrong" partitions, the worst this can do is cause + suboptimal diff output. It cannot cause incorrect diff output. */ + +static void +diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, bool find_minimal, + struct partition *part, struct context *ctxt) +{ + OFFSET *const fd = ctxt->fdiag; /* Give the compiler a chance. */ + OFFSET *const bd = ctxt->bdiag; /* Additional help for the compiler. */ +#ifdef ELEMENT + ELEMENT const *const xv = ctxt->xvec; /* Still more help for the compiler. */ + ELEMENT const *const yv = ctxt->yvec; /* And more and more . . . */ + #define XREF_YREF_EQUAL(x,y) EQUAL (xv[x], yv[y]) +#else + #define XREF_YREF_EQUAL(x,y) XVECREF_YVECREF_EQUAL (ctxt, x, y) +#endif + const OFFSET dmin = xoff - ylim; /* Minimum valid diagonal. */ + const OFFSET dmax = xlim - yoff; /* Maximum valid diagonal. */ + const OFFSET fmid = xoff - yoff; /* Center diagonal of top-down search. */ + const OFFSET bmid = xlim - ylim; /* Center diagonal of bottom-up search. */ + OFFSET fmin = fmid; + OFFSET fmax = fmid; /* Limits of top-down search. */ + OFFSET bmin = bmid; + OFFSET bmax = bmid; /* Limits of bottom-up search. */ + OFFSET c; /* Cost. */ + bool odd = (fmid - bmid) & 1; /* True if southeast corner is on an odd + diagonal with respect to the northwest. */ + + fd[fmid] = xoff; + bd[bmid] = xlim; + + for (c = 1;; ++c) + { + OFFSET d; /* Active diagonal. */ + bool big_snake = false; + + /* Extend the top-down search by an edit step in each diagonal. */ + if (fmin > dmin) + fd[--fmin - 1] = -1; + else + ++fmin; + if (fmax < dmax) + fd[++fmax + 1] = -1; + else + --fmax; + for (d = fmax; d >= fmin; d -= 2) + { + OFFSET x; + OFFSET y; + OFFSET tlo = fd[d - 1]; + OFFSET thi = fd[d + 1]; + OFFSET x0 = tlo < thi ? thi : tlo + 1; + + for (x = x0, y = x0 - d; + x < xlim && y < ylim && XREF_YREF_EQUAL (x, y); + x++, y++) + continue; + if (x - x0 > SNAKE_LIMIT) + big_snake = true; + fd[d] = x; + if (odd && bmin <= d && d <= bmax && bd[d] <= x) + { + part->xmid = x; + part->ymid = y; + part->lo_minimal = part->hi_minimal = true; + return; + } + } + + /* Similarly extend the bottom-up search. */ + if (bmin > dmin) + bd[--bmin - 1] = OFFSET_MAX; + else + ++bmin; + if (bmax < dmax) + bd[++bmax + 1] = OFFSET_MAX; + else + --bmax; + for (d = bmax; d >= bmin; d -= 2) + { + OFFSET x; + OFFSET y; + OFFSET tlo = bd[d - 1]; + OFFSET thi = bd[d + 1]; + OFFSET x0 = tlo < thi ? tlo : thi - 1; + + for (x = x0, y = x0 - d; + xoff < x && yoff < y && XREF_YREF_EQUAL (x - 1, y - 1); + x--, y--) + continue; + if (x0 - x > SNAKE_LIMIT) + big_snake = true; + bd[d] = x; + if (!odd && fmin <= d && d <= fmax && x <= fd[d]) + { + part->xmid = x; + part->ymid = y; + part->lo_minimal = part->hi_minimal = true; + return; + } + } + + if (find_minimal) + continue; + +#ifdef USE_HEURISTIC + bool heuristic = ctxt->heuristic; +#else + bool heuristic = false; +#endif + + /* Heuristic: check occasionally for a diagonal that has made lots + of progress compared with the edit distance. If we have any + such, find the one that has made the most progress and return it + as if it had succeeded. + + With this heuristic, for vectors with a constant small density + of changes, the algorithm is linear in the vector size. */ + + if (200 < c && big_snake && heuristic) + { + { + OFFSET best = 0; + + for (d = fmax; d >= fmin; d -= 2) + { + OFFSET dd = d - fmid; + OFFSET x = fd[d]; + OFFSET y = x - d; + OFFSET v = (x - xoff) * 2 - dd; + + if (v > 12 * (c + (dd < 0 ? -dd : dd))) + { + if (v > best + && xoff + SNAKE_LIMIT <= x && x < xlim + && yoff + SNAKE_LIMIT <= y && y < ylim) + { + /* We have a good enough best diagonal; now insist + that it end with a significant snake. */ + int k; + + for (k = 1; XREF_YREF_EQUAL (x - k, y - k); k++) + if (k == SNAKE_LIMIT) + { + best = v; + part->xmid = x; + part->ymid = y; + break; + } + } + } + } + if (best > 0) + { + part->lo_minimal = true; + part->hi_minimal = false; + return; + } + } + + { + OFFSET best = 0; + + for (d = bmax; d >= bmin; d -= 2) + { + OFFSET dd = d - bmid; + OFFSET x = bd[d]; + OFFSET y = x - d; + OFFSET v = (xlim - x) * 2 + dd; + + if (v > 12 * (c + (dd < 0 ? -dd : dd))) + { + if (v > best + && xoff < x && x <= xlim - SNAKE_LIMIT + && yoff < y && y <= ylim - SNAKE_LIMIT) + { + /* We have a good enough best diagonal; now insist + that it end with a significant snake. */ + int k; + + for (k = 0; XREF_YREF_EQUAL (x + k, y + k); k++) + if (k == SNAKE_LIMIT - 1) + { + best = v; + part->xmid = x; + part->ymid = y; + break; + } + } + } + } + if (best > 0) + { + part->lo_minimal = false; + part->hi_minimal = true; + return; + } + } + } + + /* Heuristic: if we've gone well beyond the call of duty, give up + and report halfway between our best results so far. */ + if (c >= ctxt->too_expensive) + { + OFFSET fxybest; + OFFSET fxbest IF_LINT (= 0); + OFFSET bxybest; + OFFSET bxbest IF_LINT (= 0); + + /* Find forward diagonal that maximizes X + Y. */ + fxybest = -1; + for (d = fmax; d >= fmin; d -= 2) + { + OFFSET x = MIN (fd[d], xlim); + OFFSET y = x - d; + if (ylim < y) + { + x = ylim + d; + y = ylim; + } + if (fxybest < x + y) + { + fxybest = x + y; + fxbest = x; + } + } + + /* Find backward diagonal that minimizes X + Y. */ + bxybest = OFFSET_MAX; + for (d = bmax; d >= bmin; d -= 2) + { + OFFSET x = MAX (xoff, bd[d]); + OFFSET y = x - d; + if (y < yoff) + { + x = yoff + d; + y = yoff; + } + if (x + y < bxybest) + { + bxybest = x + y; + bxbest = x; + } + } + + /* Use the better of the two diagonals. */ + if ((xlim + ylim) - bxybest < fxybest - (xoff + yoff)) + { + part->xmid = fxbest; + part->ymid = fxybest - fxbest; + part->lo_minimal = true; + part->hi_minimal = false; + } + else + { + part->xmid = bxbest; + part->ymid = bxybest - bxbest; + part->lo_minimal = false; + part->hi_minimal = true; + } + return; + } + } + #undef XREF_YREF_EQUAL +} + + +/* Compare in detail contiguous subsequences of the two vectors + which are known, as a whole, to match each other. + + The subsequence of vector 0 is [XOFF, XLIM) and likewise for vector 1. + + Note that XLIM, YLIM are exclusive bounds. All indices into the vectors + are origin-0. + + If FIND_MINIMAL, find a minimal difference no matter how + expensive it is. + + The results are recorded by invoking NOTE_DELETE and NOTE_INSERT. + + Return false if terminated normally, or true if terminated through early + abort. */ + +static bool +compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, + bool find_minimal, struct context *ctxt) +{ +#ifdef ELEMENT + ELEMENT const *xv = ctxt->xvec; /* Help the compiler. */ + ELEMENT const *yv = ctxt->yvec; + #define XREF_YREF_EQUAL(x,y) EQUAL (xv[x], yv[y]) +#else + #define XREF_YREF_EQUAL(x,y) XVECREF_YVECREF_EQUAL (ctxt, x, y) +#endif + + /* Slide down the bottom initial diagonal. */ + while (xoff < xlim && yoff < ylim && XREF_YREF_EQUAL (xoff, yoff)) + { + xoff++; + yoff++; + } + + /* Slide up the top initial diagonal. */ + while (xoff < xlim && yoff < ylim && XREF_YREF_EQUAL (xlim - 1, ylim - 1)) + { + xlim--; + ylim--; + } + + /* Handle simple cases. */ + if (xoff == xlim) + while (yoff < ylim) + { + NOTE_INSERT (ctxt, yoff); + if (EARLY_ABORT (ctxt)) + return true; + yoff++; + } + else if (yoff == ylim) + while (xoff < xlim) + { + NOTE_DELETE (ctxt, xoff); + if (EARLY_ABORT (ctxt)) + return true; + xoff++; + } + else + { + struct partition part IF_LINT2 (= { .xmid = 0, .ymid = 0 }); + + /* Find a point of correspondence in the middle of the vectors. */ + diag (xoff, xlim, yoff, ylim, find_minimal, &part, ctxt); + + /* Use the partitions to split this problem into subproblems. */ + if (compareseq (xoff, part.xmid, yoff, part.ymid, part.lo_minimal, ctxt)) + return true; + if (compareseq (part.xmid, xlim, part.ymid, ylim, part.hi_minimal, ctxt)) + return true; + } + + return false; + #undef XREF_YREF_EQUAL +} + +#undef ELEMENT +#undef EQUAL +#undef OFFSET +#undef EXTRA_CONTEXT_FIELDS +#undef NOTE_DELETE +#undef NOTE_INSERT +#undef EARLY_ABORT +#undef USE_HEURISTIC +#undef XVECREF_YVECREF_EQUAL +#undef OFFSET_MAX diff --git a/contrib/tools/bison/lib/dirname-lgpl.c b/contrib/tools/bison/lib/dirname-lgpl.c index 7cf89d8cf8..27d4374c2e 100644 --- a/contrib/tools/bison/lib/dirname-lgpl.c +++ b/contrib/tools/bison/lib/dirname-lgpl.c @@ -1,6 +1,6 @@ /* dirname.c -- return all but the last element in a file name - Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2019 Free Software + Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/dirname.c b/contrib/tools/bison/lib/dirname.c index 1e042a5cdc..dc1997c810 100644 --- a/contrib/tools/bison/lib/dirname.c +++ b/contrib/tools/bison/lib/dirname.c @@ -1,6 +1,6 @@ /* dirname.c -- return all but the last element in a file name - Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2019 Free Software + Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/dirname.h b/contrib/tools/bison/lib/dirname.h index 579165947f..8c12d93b51 100644 --- a/contrib/tools/bison/lib/dirname.h +++ b/contrib/tools/bison/lib/dirname.h @@ -1,6 +1,6 @@ /* Take file names apart into directory and base names. - Copyright (C) 1998, 2001, 2003-2006, 2009-2019 Free Software Foundation, + Copyright (C) 1998, 2001, 2003-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/dosname.h b/contrib/tools/bison/lib/dosname.h index c0ab6848a5..5782960094 100644 --- a/contrib/tools/bison/lib/dosname.h +++ b/contrib/tools/bison/lib/dosname.h @@ -1,6 +1,6 @@ /* File names on MS-DOS/Windows systems. - Copyright (C) 2000-2001, 2004-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2000-2001, 2004-2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/dup-safer-flag.c b/contrib/tools/bison/lib/dup-safer-flag.c index 485f7411bd..b2c345e0ed 100644 --- a/contrib/tools/bison/lib/dup-safer-flag.c +++ b/contrib/tools/bison/lib/dup-safer-flag.c @@ -1,7 +1,7 @@ /* Duplicate a file descriptor result, avoiding clobbering STD{IN,OUT,ERR}_FILENO, with specific flags. - Copyright (C) 2001, 2004-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2004-2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/dup-safer.c b/contrib/tools/bison/lib/dup-safer.c index c0c5f2a914..4ada3fe8d2 100644 --- a/contrib/tools/bison/lib/dup-safer.c +++ b/contrib/tools/bison/lib/dup-safer.c @@ -1,6 +1,6 @@ /* Invoke dup, but avoid some glitches. - Copyright (C) 2001, 2004-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2004-2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/dup2.c b/contrib/tools/bison/lib/dup2.c index 56a2794478..410064a935 100644 --- a/contrib/tools/bison/lib/dup2.c +++ b/contrib/tools/bison/lib/dup2.c @@ -1,6 +1,6 @@ /* Duplicate an open file descriptor to a specified file descriptor. - Copyright (C) 1999, 2004-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1999, 2004-2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/error.c b/contrib/tools/bison/lib/error.c index 7e532f0e48..3657b51cdf 100644 --- a/contrib/tools/bison/lib/error.c +++ b/contrib/tools/bison/lib/error.c @@ -1,5 +1,5 @@ /* Error handler for noninteractive utilities - Copyright (C) 1990-1998, 2000-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1990-1998, 2000-2007, 2009-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software: you can redistribute it and/or modify @@ -119,7 +119,7 @@ int strerror_r (int errnum, char *buf, size_t buflen); # endif # endif -#define program_name getprogname () +# define program_name getprogname () # if GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r # define __strerror_r strerror_r diff --git a/contrib/tools/bison/lib/error.h b/contrib/tools/bison/lib/error.h index 3759f8ad44..bad47a16dd 100644 --- a/contrib/tools/bison/lib/error.h +++ b/contrib/tools/bison/lib/error.h @@ -1,5 +1,5 @@ /* Declaration for error-reporting function - Copyright (C) 1995-1997, 2003, 2006, 2008-2019 Free Software Foundation, + Copyright (C) 1995-1997, 2003, 2006, 2008-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. diff --git a/contrib/tools/bison/lib/exitfail.c b/contrib/tools/bison/lib/exitfail.c index 69b351372e..189fa16f46 100644 --- a/contrib/tools/bison/lib/exitfail.c +++ b/contrib/tools/bison/lib/exitfail.c @@ -1,6 +1,6 @@ /* Failure exit status - Copyright (C) 2002-2003, 2005-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2003, 2005-2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/exitfail.h b/contrib/tools/bison/lib/exitfail.h index 480ad1a166..a69a03bbd5 100644 --- a/contrib/tools/bison/lib/exitfail.h +++ b/contrib/tools/bison/lib/exitfail.h @@ -1,6 +1,6 @@ /* Failure exit status - Copyright (C) 2002, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2002, 2009-2020 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 diff --git a/contrib/tools/bison/lib/fatal-signal.c b/contrib/tools/bison/lib/fatal-signal.c index 1fe31d10f5..c8ff338041 100644 --- a/contrib/tools/bison/lib/fatal-signal.c +++ b/contrib/tools/bison/lib/fatal-signal.c @@ -1,5 +1,5 @@ /* Emergency actions in case of a fatal signal. - Copyright (C) 2003-2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2003-2004, 2006-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software: you can redistribute it and/or modify @@ -107,7 +107,7 @@ init_fatal_signals (void) /* ========================================================================= */ -typedef void (*action_t) (void); +typedef _GL_ASYNC_SAFE void (*action_t) (int sig); /* Type of an entry in the actions array. The 'action' field is accessed from within the fatal_signal_handler(), @@ -131,7 +131,7 @@ static struct sigaction saved_sigactions[64]; /* Uninstall the handlers. */ -static void +static _GL_ASYNC_SAFE void uninstall_handlers (void) { size_t i; @@ -148,7 +148,7 @@ uninstall_handlers (void) /* The signal handler. It gets called asynchronously. */ -static void +static _GL_ASYNC_SAFE void fatal_signal_handler (int sig) { for (;;) @@ -162,7 +162,7 @@ fatal_signal_handler (int sig) actions_count = n; action = actions[n].action; /* Execute the action. */ - action (); + action (sig); } /* Now execute the signal's default action. @@ -284,3 +284,20 @@ unblock_fatal_signals (void) init_fatal_signal_set (); sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL); } + + +unsigned int +get_fatal_signals (int signals[64]) +{ + init_fatal_signal_set (); + + { + int *p = signals; + size_t i; + + for (i = 0; i < num_fatal_signals; i++) + if (fatal_signals[i] >= 0) + *p++ = fatal_signals[i]; + return p - signals; + } +} diff --git a/contrib/tools/bison/lib/fatal-signal.h b/contrib/tools/bison/lib/fatal-signal.h index a2e60d3a62..2c0154ffc3 100644 --- a/contrib/tools/bison/lib/fatal-signal.h +++ b/contrib/tools/bison/lib/fatal-signal.h @@ -1,5 +1,5 @@ /* Emergency actions in case of a fatal signal. - Copyright (C) 2003-2004, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2003-2004, 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software: you can redistribute it and/or modify @@ -36,7 +36,8 @@ extern "C" { occurs. Restrictions for the cleanup function: - - The cleanup function can do all kinds of system calls. + - The cleanup function can do all kinds of system calls. It may also + modify (clobber) errno. - It can also access application dependent memory locations and data structures provided they are in a consistent state. One way to ensure this is through block_fatal_signals()/unblock_fatal_signals(), see @@ -51,7 +52,7 @@ extern "C" { The cleanup function is executed asynchronously. It is unspecified whether during its execution the catchable fatal signals are blocked or not. */ -extern void at_fatal_signal (void (*function) (void)); +extern void at_fatal_signal (_GL_ASYNC_SAFE void (*function) (int sig)); /* Sometimes it is necessary to block the usually fatal signals while the @@ -71,6 +72,12 @@ extern void block_fatal_signals (void); extern void unblock_fatal_signals (void); +/* Return the list of signals that block_fatal_signals/unblock_fatal_signals + would block or unblock. + Fills signals[0..count-1] and returns count. */ +extern unsigned int get_fatal_signals (int signals[64]); + + #ifdef __cplusplus } #endif diff --git a/contrib/tools/bison/lib/fcntl.c b/contrib/tools/bison/lib/fcntl.c index e65f1b21c7..cc54f62ed7 100644 --- a/contrib/tools/bison/lib/fcntl.c +++ b/contrib/tools/bison/lib/fcntl.c @@ -1,6 +1,6 @@ /* Provide file descriptor control. - Copyright (C) 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2020 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 @@ -25,6 +25,7 @@ #include <errno.h> #include <limits.h> #include <stdarg.h> +#include <stdlib.h> #include <unistd.h> #ifdef __KLIBC__ diff --git a/contrib/tools/bison/lib/fd-hook.c b/contrib/tools/bison/lib/fd-hook.c index 78791198fa..8840f63488 100644 --- a/contrib/tools/bison/lib/fd-hook.c +++ b/contrib/tools/bison/lib/fd-hook.c @@ -1,5 +1,5 @@ /* Hook for making file descriptor functions close(), ioctl() extensible. - Copyright (C) 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2009. This program is free software: you can redistribute it and/or modify it diff --git a/contrib/tools/bison/lib/fd-hook.h b/contrib/tools/bison/lib/fd-hook.h index bf07f0068b..ed1a15a230 100644 --- a/contrib/tools/bison/lib/fd-hook.h +++ b/contrib/tools/bison/lib/fd-hook.h @@ -1,5 +1,5 @@ /* Hook for making file descriptor functions close(), ioctl() extensible. - Copyright (C) 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2020 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 diff --git a/contrib/tools/bison/lib/fd-safer-flag.c b/contrib/tools/bison/lib/fd-safer-flag.c index 7c026ef541..8fdf8dbc16 100644 --- a/contrib/tools/bison/lib/fd-safer-flag.c +++ b/contrib/tools/bison/lib/fd-safer-flag.c @@ -1,7 +1,7 @@ /* Adjust a file descriptor result so that it avoids clobbering STD{IN,OUT,ERR}_FILENO, with specific flags. - Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/fd-safer.c b/contrib/tools/bison/lib/fd-safer.c index b5113e1367..e011c00308 100644 --- a/contrib/tools/bison/lib/fd-safer.c +++ b/contrib/tools/bison/lib/fd-safer.c @@ -1,6 +1,6 @@ /* Return a safer copy of a file descriptor. - Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/filename.h b/contrib/tools/bison/lib/filename.h index 3ba31059f6..d4c70203e6 100644 --- a/contrib/tools/bison/lib/filename.h +++ b/contrib/tools/bison/lib/filename.h @@ -1,5 +1,5 @@ /* Basic filename support macros. - Copyright (C) 2001-2004, 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2007-2020 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 diff --git a/contrib/tools/bison/lib/float+.h b/contrib/tools/bison/lib/float+.h index 5af861f7ae..1e19a7185a 100644 --- a/contrib/tools/bison/lib/float+.h +++ b/contrib/tools/bison/lib/float+.h @@ -1,5 +1,5 @@ /* Supplemental information about the floating-point formats. - Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2007. This program is free software; you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/fopen-safer.c b/contrib/tools/bison/lib/fopen-safer.c index 5d4a4a9e75..bd36317765 100644 --- a/contrib/tools/bison/lib/fopen-safer.c +++ b/contrib/tools/bison/lib/fopen-safer.c @@ -1,6 +1,6 @@ /* Invoke fopen, but avoid some glitches. - Copyright (C) 2001, 2004-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2004-2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/fpending.c b/contrib/tools/bison/lib/fpending.c index 3c01285bb8..802ebcba65 100644 --- a/contrib/tools/bison/lib/fpending.c +++ b/contrib/tools/bison/lib/fpending.c @@ -1,5 +1,5 @@ /* fpending.c -- return the number of pending output bytes on a stream - Copyright (C) 2000, 2004, 2006-2007, 2009-2019 Free Software Foundation, + Copyright (C) 2000, 2004, 2006-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/fpending.h b/contrib/tools/bison/lib/fpending.h index 097a3ef071..a8b8859726 100644 --- a/contrib/tools/bison/lib/fpending.h +++ b/contrib/tools/bison/lib/fpending.h @@ -1,6 +1,6 @@ /* Declare __fpending. - Copyright (C) 2000, 2003, 2005-2006, 2009-2019 Free Software Foundation, + Copyright (C) 2000, 2003, 2005-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/fpucw.h b/contrib/tools/bison/lib/fpucw.h index caa51fe3bb..1c6edf6b76 100644 --- a/contrib/tools/bison/lib/fpucw.h +++ b/contrib/tools/bison/lib/fpucw.h @@ -1,5 +1,5 @@ /* Manipulating the FPU control word. -*- coding: utf-8 -*- - Copyright (C) 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2007-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2007. This program is free software: you can redistribute it and/or modify @@ -43,7 +43,7 @@ See Vincent Lefèvre's page https://www.vinc17.net/research/extended.en.html for a good explanation. - See http://www.uwsg.iu.edu/hypermail/linux/kernel/0103.0/0453.html for + See https://web.archive.org/web/20060905133417/http://www.uwsg.iu.edu/hypermail/linux/kernel/0103.0/0453.html some argumentation which setting should be the default. */ /* This header file provides the following facilities: @@ -70,12 +70,12 @@ typedef unsigned short fpucw_t; /* glibc calls this fpu_control_t */ # define FPU_PC_DOUBLE 0x200 /* glibc calls this _FPU_DOUBLE */ # define FPU_PC_EXTENDED 0x300 /* glibc calls this _FPU_EXTENDED */ -# define GET_FPUCW() \ +# define GET_FPUCW() __extension__ \ ({ fpucw_t _cw; \ __asm__ __volatile__ ("fnstcw %0" : "=m" (*&_cw)); \ _cw; \ }) -# define SET_FPUCW(word) \ +# define SET_FPUCW(word) __extension__ \ (void)({ fpucw_t _ncw = (word); \ __asm__ __volatile__ ("fldcw %0" : : "m" (*&_ncw)); \ }) diff --git a/contrib/tools/bison/lib/fseterr.c b/contrib/tools/bison/lib/fseterr.c index 8cd68e8ce7..8f32b7e5af 100644 --- a/contrib/tools/bison/lib/fseterr.c +++ b/contrib/tools/bison/lib/fseterr.c @@ -1,5 +1,5 @@ /* Set the error indicator of a stream. - Copyright (C) 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2007-2020 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 diff --git a/contrib/tools/bison/lib/fseterr.h b/contrib/tools/bison/lib/fseterr.h index 7b57faa3d2..bbeb6619f9 100644 --- a/contrib/tools/bison/lib/fseterr.h +++ b/contrib/tools/bison/lib/fseterr.h @@ -1,5 +1,5 @@ /* Set the error indicator of a stream. - Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/fstrcmp.c b/contrib/tools/bison/lib/fstrcmp.c new file mode 100644 index 0000000000..1a4fbfdf8d --- /dev/null +++ b/contrib/tools/bison/lib/fstrcmp.c @@ -0,0 +1,263 @@ +/* Functions to make fuzzy comparisons between strings + Copyright (C) 1988-1989, 1992-1993, 1995, 2001-2003, 2006, 2008-2020 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 <https://www.gnu.org/licenses/>. */ + + +#include <config.h> + +/* Specification. */ +#include "fstrcmp.h" + +#include <string.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <limits.h> + +#include "glthread/lock.h" +#include "glthread/tls.h" +#include "minmax.h" +#include "xalloc.h" + + +#define ELEMENT char +#define EQUAL(x,y) ((x) == (y)) +#define OFFSET ptrdiff_t +#define EXTRA_CONTEXT_FIELDS \ + /* The number of edits beyond which the computation can be aborted. */ \ + ptrdiff_t edit_count_limit; \ + /* The number of edits (= number of elements inserted, plus the number of \ + elements deleted), temporarily minus edit_count_limit. */ \ + ptrdiff_t edit_count; +#define NOTE_DELETE(ctxt, xoff) ctxt->edit_count++ +#define NOTE_INSERT(ctxt, yoff) ctxt->edit_count++ +#define EARLY_ABORT(ctxt) ctxt->edit_count > 0 +/* We don't need USE_HEURISTIC, since it is unlikely in typical uses of + fstrcmp(). */ +#include "diffseq.h" + + +/* Because fstrcmp is typically called multiple times, attempt to minimize + the number of memory allocations performed. Thus, let a call reuse the + memory already allocated by the previous call, if it is sufficient. + To make it multithread-safe, without need for a lock that protects the + already allocated memory, store the allocated memory per thread. Free + it only when the thread exits. */ + +static gl_tls_key_t buffer_key; /* TLS key for a 'ptrdiff_t *' */ +static gl_tls_key_t bufmax_key; /* TLS key for a 'uintptr_t' */ + +static void +keys_init (void) +{ + gl_tls_key_init (buffer_key, free); + gl_tls_key_init (bufmax_key, NULL); + /* The per-thread initial values are NULL and 0, respectively. */ +} + +/* Ensure that keys_init is called once only. */ +gl_once_define(static, keys_init_once) + +void +fstrcmp_free_resources (void) +{ + ptrdiff_t *buffer; + + gl_once (keys_init_once, keys_init); + buffer = gl_tls_get (buffer_key); + if (buffer != NULL) + { + gl_tls_set (buffer_key, NULL); + gl_tls_set (bufmax_key, (void *) (uintptr_t) 0); + free (buffer); + } +} + + +/* In the code below, branch probabilities were measured by Ralf Wildenhues, + by running "msgmerge LL.po coreutils.pot" with msgmerge 0.18 for many + values of LL. The probability indicates that the condition evaluates + to true; whether that leads to a branch or a non-branch in the code, + depends on the compiler's reordering of basic blocks. */ + + +double +fstrcmp_bounded (const char *string1, const char *string2, double lower_bound) +{ + struct context ctxt; + size_t xvec_length = strlen (string1); + size_t yvec_length = strlen (string2); + size_t length_sum = xvec_length + yvec_length; + ptrdiff_t i; + + ptrdiff_t fdiag_len; + ptrdiff_t *buffer; + uintptr_t bufmax; + + /* short-circuit obvious comparisons */ + if (xvec_length == 0 || yvec_length == 0) /* Prob: 1% */ + return length_sum == 0; + + if (! (xvec_length <= length_sum + && length_sum <= MIN (UINTPTR_MAX, PTRDIFF_MAX) - 3)) + xalloc_die (); + + if (lower_bound > 0) + { + /* Compute a quick upper bound. + Each edit is an insertion or deletion of an element, hence modifies + the length of the sequence by at most 1. + Therefore, when starting from a sequence X and ending at a sequence Y, + with N edits, | yvec_length - xvec_length | <= N. (Proof by + induction over N.) + So, at the end, we will have + edit_count >= | xvec_length - yvec_length |. + and hence + result + = (xvec_length + yvec_length - edit_count) + / (xvec_length + yvec_length) + <= (xvec_length + yvec_length - | yvec_length - xvec_length |) + / (xvec_length + yvec_length) + = 2 * min (xvec_length, yvec_length) / (xvec_length + yvec_length). + */ + ptrdiff_t length_min = MIN (xvec_length, yvec_length); + volatile double upper_bound = 2.0 * length_min / length_sum; + + if (upper_bound < lower_bound) /* Prob: 74% */ + /* Return an arbitrary value < LOWER_BOUND. */ + return 0.0; + +#if CHAR_BIT <= 8 + /* When X and Y are both small, avoid the overhead of setting up an + array of size 256. */ + if (length_sum >= 20) /* Prob: 99% */ + { + /* Compute a less quick upper bound. + Each edit is an insertion or deletion of a character, hence + modifies the occurrence count of a character by 1 and leaves the + other occurrence counts unchanged. + Therefore, when starting from a sequence X and ending at a + sequence Y, and denoting the occurrence count of C in X with + OCC (X, C), with N edits, + sum_C | OCC (X, C) - OCC (Y, C) | <= N. + (Proof by induction over N.) + So, at the end, we will have + edit_count >= sum_C | OCC (X, C) - OCC (Y, C) |, + and hence + result + = (xvec_length + yvec_length - edit_count) + / (xvec_length + yvec_length) + <= (xvec_length + yvec_length - sum_C | OCC(X,C) - OCC(Y,C) |) + / (xvec_length + yvec_length). + */ + ptrdiff_t occ_diff[UCHAR_MAX + 1]; /* array C -> OCC(X,C) - OCC(Y,C) */ + ptrdiff_t sum; + double dsum; + + /* Determine the occurrence counts in X. */ + memset (occ_diff, 0, sizeof (occ_diff)); + for (i = xvec_length - 1; i >= 0; i--) + occ_diff[(unsigned char) string1[i]]++; + /* Subtract the occurrence counts in Y. */ + for (i = yvec_length - 1; i >= 0; i--) + occ_diff[(unsigned char) string2[i]]--; + /* Sum up the absolute values. */ + sum = 0; + for (i = 0; i <= UCHAR_MAX; i++) + { + ptrdiff_t d = occ_diff[i]; + sum += (d >= 0 ? d : -d); + } + + dsum = sum; + upper_bound = 1.0 - dsum / length_sum; + + if (upper_bound < lower_bound) /* Prob: 66% */ + /* Return an arbitrary value < LOWER_BOUND. */ + return 0.0; + } +#endif + } + + /* set the info for each string. */ + ctxt.xvec = string1; + ctxt.yvec = string2; + + /* Set TOO_EXPENSIVE to be approximate square root of input size, + bounded below by 4096. */ + ctxt.too_expensive = 1; + for (i = xvec_length + yvec_length; i != 0; i >>= 2) + ctxt.too_expensive <<= 1; + if (ctxt.too_expensive < 4096) + ctxt.too_expensive = 4096; + + /* Allocate memory for fdiag and bdiag from a thread-local pool. */ + fdiag_len = length_sum + 3; + gl_once (keys_init_once, keys_init); + buffer = gl_tls_get (buffer_key); + bufmax = (uintptr_t) gl_tls_get (bufmax_key); + if (fdiag_len > bufmax) + { + /* Need more memory. */ + bufmax = 2 * bufmax; + if (fdiag_len > bufmax) + bufmax = fdiag_len; + /* Calling xrealloc would be a waste: buffer's contents does not need + to be preserved. */ + free (buffer); + buffer = xnmalloc (bufmax, 2 * sizeof *buffer); + gl_tls_set (buffer_key, buffer); + gl_tls_set (bufmax_key, (void *) (uintptr_t) bufmax); + } + ctxt.fdiag = buffer + yvec_length + 1; + ctxt.bdiag = ctxt.fdiag + fdiag_len; + + /* The edit_count is only ever increased. The computation can be aborted + when + (xvec_length + yvec_length - edit_count) / (xvec_length + yvec_length) + < lower_bound, + or equivalently + edit_count > (xvec_length + yvec_length) * (1 - lower_bound) + or equivalently + edit_count > floor((xvec_length + yvec_length) * (1 - lower_bound)). + We need to add an epsilon inside the floor(...) argument, to neutralize + rounding errors. */ + ctxt.edit_count_limit = + (lower_bound < 1.0 + ? (ptrdiff_t) (length_sum * (1.0 - lower_bound + 0.000001)) + : 0); + + /* Now do the main comparison algorithm */ + ctxt.edit_count = - ctxt.edit_count_limit; + if (compareseq (0, xvec_length, 0, yvec_length, 0, &ctxt)) /* Prob: 98% */ + /* The edit_count passed the limit. Hence the result would be + < lower_bound. We can return any value < lower_bound instead. */ + return 0.0; + ctxt.edit_count += ctxt.edit_count_limit; + + /* The result is + ((number of chars in common) / (average length of the strings)). + The numerator is + = xvec_length - (number of calls to NOTE_DELETE) + = yvec_length - (number of calls to NOTE_INSERT) + = 1/2 * (xvec_length + yvec_length - (number of edits)). + This is admittedly biased towards finding that the strings are + similar, however it does produce meaningful results. */ + return ((double) (xvec_length + yvec_length - ctxt.edit_count) + / (xvec_length + yvec_length)); +} diff --git a/contrib/tools/bison/lib/fstrcmp.h b/contrib/tools/bison/lib/fstrcmp.h new file mode 100644 index 0000000000..37df588a3e --- /dev/null +++ b/contrib/tools/bison/lib/fstrcmp.h @@ -0,0 +1,54 @@ +/* Fuzzy string comparison. + Copyright (C) 1995, 2000, 2002-2003, 2006, 2008-2020 Free Software + Foundation, Inc. + + This file was written by Peter Miller <pmiller@agso.gov.au> + +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 <https://www.gnu.org/licenses/>. */ + +#ifndef _FSTRCMP_H +#define _FSTRCMP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Fuzzy compare of S1 and S2. Return a measure for the similarity of S1 + and S1. The higher the result, the more similar the strings are. + The result is bounded between 0 (meaning very dissimilar strings) and + 1 (meaning identical strings). */ +extern double fstrcmp (const char *s1, const char *s2); + +/* Like fstrcmp (S1, S2), except that if the result is < LOWER_BOUND, an + arbitrary other value < LOWER_BOUND can be returned. */ +extern double fstrcmp_bounded (const char *s1, const char *s2, + double lower_bound); + +/* A shortcut for fstrcmp. Avoids a function call. */ +#define fstrcmp(s1,s2) fstrcmp_bounded (s1, s2, 0.0) + +/* Frees the per-thread resources allocated by this module for the current + thread. + You don't need to call this function in threads other than the main thread, + because per-thread resources are reclaimed automatically when the thread + exits. However, per-thread resources allocated by the main thread are + comparable to static allocations; calling this function can be useful to + avoid an error report from valgrind. */ +extern void fstrcmp_free_resources (void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/contrib/tools/bison/lib/get-errno.c b/contrib/tools/bison/lib/get-errno.c index 36e07adaff..ef3b71b4fb 100644 --- a/contrib/tools/bison/lib/get-errno.c +++ b/contrib/tools/bison/lib/get-errno.c @@ -1,6 +1,6 @@ /* get-errno.c - get and set errno. - Copyright (C) 2002, 2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002, 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/get-errno.h b/contrib/tools/bison/lib/get-errno.h index c13ac6b319..b6550852f5 100644 --- a/contrib/tools/bison/lib/get-errno.h +++ b/contrib/tools/bison/lib/get-errno.h @@ -1,6 +1,6 @@ /* get-errno.h - get and set errno. - Copyright (C) 2002, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2009-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/getdtablesize.c b/contrib/tools/bison/lib/getdtablesize.c index 03a92435f0..0fe70921f9 100644 --- a/contrib/tools/bison/lib/getdtablesize.c +++ b/contrib/tools/bison/lib/getdtablesize.c @@ -1,5 +1,5 @@ /* getdtablesize() function: Return maximum possible file descriptor value + 1. - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2008. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/gethrxtime.c b/contrib/tools/bison/lib/gethrxtime.c index 877596257a..88342cb102 100644 --- a/contrib/tools/bison/lib/gethrxtime.c +++ b/contrib/tools/bison/lib/gethrxtime.c @@ -1,6 +1,6 @@ /* gethrxtime -- get high resolution real time - Copyright (C) 2005-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/gethrxtime.h b/contrib/tools/bison/lib/gethrxtime.h index 6491794554..44973397b5 100644 --- a/contrib/tools/bison/lib/gethrxtime.h +++ b/contrib/tools/bison/lib/gethrxtime.h @@ -1,6 +1,6 @@ /* gethrxtime -- get high resolution real time - Copyright (C) 2005, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005, 2009-2020 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 diff --git a/contrib/tools/bison/lib/getopt.c b/contrib/tools/bison/lib/getopt.c index 8ee075a809..a6389d8ea9 100644 --- a/contrib/tools/bison/lib/getopt.c +++ b/contrib/tools/bison/lib/getopt.c @@ -1,5 +1,5 @@ /* Getopt for GNU. - Copyright (C) 1987-2019 Free Software Foundation, Inc. + Copyright (C) 1987-2020 Free Software Foundation, Inc. This file is part of the GNU C Library and is also part of gnulib. Patches to this file should be submitted to both projects. diff --git a/contrib/tools/bison/lib/getopt1.c b/contrib/tools/bison/lib/getopt1.c index 883aa6bbc9..0902efe68e 100644 --- a/contrib/tools/bison/lib/getopt1.c +++ b/contrib/tools/bison/lib/getopt1.c @@ -1,5 +1,5 @@ /* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987-2019 Free Software Foundation, Inc. + Copyright (C) 1987-2020 Free Software Foundation, Inc. This file is part of the GNU C Library and is also part of gnulib. Patches to this file should be submitted to both projects. diff --git a/contrib/tools/bison/lib/getopt_int.h b/contrib/tools/bison/lib/getopt_int.h index e63706f60e..afcd8a67fb 100644 --- a/contrib/tools/bison/lib/getopt_int.h +++ b/contrib/tools/bison/lib/getopt_int.h @@ -1,5 +1,5 @@ /* Internal declarations for getopt. - Copyright (C) 1989-2019 Free Software Foundation, Inc. + Copyright (C) 1989-2020 Free Software Foundation, Inc. This file is part of the GNU C Library and is also part of gnulib. Patches to this file should be submitted to both projects. diff --git a/contrib/tools/bison/lib/getprogname.c b/contrib/tools/bison/lib/getprogname.c index 50fe23cb89..7507e0d757 100644 --- a/contrib/tools/bison/lib/getprogname.c +++ b/contrib/tools/bison/lib/getprogname.c @@ -1,5 +1,5 @@ /* Program name management. - Copyright (C) 2016-2019 Free Software Foundation, Inc. + Copyright (C) 2016-2020 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 @@ -70,10 +70,10 @@ getprogname (void) p = "?"; return last_component (p); # elif HAVE_DECL___ARGV /* mingw, MSVC */ - /* https://msdn.microsoft.com/en-us/library/dn727674.aspx */ + /* https://docs.microsoft.com/en-us/cpp/c-runtime-library/argc-argv-wargv */ const char *p = __argv && __argv[0] ? __argv[0] : "?"; return last_component (p); -# elif HAVE_VAR___PROGNAME /* OpenBSD, QNX */ +# elif HAVE_VAR___PROGNAME /* OpenBSD, Android, QNX */ /* https://man.openbsd.org/style.9 */ /* http://www.qnx.de/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Fp%2F__progname.html */ /* Be careful to declare this only when we absolutely need it @@ -82,7 +82,11 @@ getprogname (void) malfunction (have zero length) with Fedora 25's glibc. */ extern char *__progname; const char *p = __progname; +# if defined __ANDROID__ + return last_component (p); +# else return p && p[0] ? p : "?"; +# endif # elif _AIX /* AIX */ /* Idea by Bastien ROUCARIÈS, https://lists.gnu.org/r/bug-gnulib/2010-12/msg00095.html @@ -229,12 +233,13 @@ getprogname (void) { char *name = buf.pr_fname; size_t namesize = sizeof buf.pr_fname; + /* It may not be NUL-terminated. */ char *namenul = memchr (name, '\0', namesize); size_t namelen = namenul ? namenul - name : namesize; char *namecopy = malloc (namelen + 1); if (namecopy) { - namecopy[namelen] = 0; + namecopy[namelen] = '\0'; return memcpy (namecopy, name, namelen); } } diff --git a/contrib/tools/bison/lib/getprogname.h b/contrib/tools/bison/lib/getprogname.h index 1590b38d3f..676912b4b8 100644 --- a/contrib/tools/bison/lib/getprogname.h +++ b/contrib/tools/bison/lib/getprogname.h @@ -1,5 +1,5 @@ /* Program name management. - Copyright (C) 2016-2019 Free Software Foundation, Inc. + Copyright (C) 2016-2020 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 diff --git a/contrib/tools/bison/lib/gettext.h b/contrib/tools/bison/lib/gettext.h index c7c0fdb531..0bd1e13348 100644 --- a/contrib/tools/bison/lib/gettext.h +++ b/contrib/tools/bison/lib/gettext.h @@ -1,5 +1,5 @@ /* Convenience header for conditional use of GNU <libintl.h>. - Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2019 Free Software + Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/gl_array_list.c b/contrib/tools/bison/lib/gl_array_list.c index 4ac743fde4..49509620f7 100644 --- a/contrib/tools/bison/lib/gl_array_list.c +++ b/contrib/tools/bison/lib/gl_array_list.c @@ -1,5 +1,5 @@ /* Sequential list data type implemented by an array. - Copyright (C) 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2006-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2006. This program is free software: you can redistribute it and/or modify @@ -20,6 +20,7 @@ /* Specification. */ #include "gl_array_list.h" +#include <stdint.h> #include <stdlib.h> /* Get memcpy. */ #include <string.h> @@ -27,10 +28,6 @@ /* Checked size_t computations. */ #include "xsize.h" -#ifndef uintptr_t -# define uintptr_t unsigned long -#endif - /* -------------------------- gl_list_t Data Type -------------------------- */ /* Concrete gl_list_impl type, valid for this file only. */ diff --git a/contrib/tools/bison/lib/gl_array_list.h b/contrib/tools/bison/lib/gl_array_list.h index 98158feb1b..8dd48bd365 100644 --- a/contrib/tools/bison/lib/gl_array_list.h +++ b/contrib/tools/bison/lib/gl_array_list.h @@ -1,5 +1,5 @@ /* Sequential list data type implemented by an array. - Copyright (C) 2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2006, 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2006. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/gl_list.h b/contrib/tools/bison/lib/gl_list.h index 5f2cade22c..39d14401f9 100644 --- a/contrib/tools/bison/lib/gl_list.h +++ b/contrib/tools/bison/lib/gl_list.h @@ -1,5 +1,5 @@ /* Abstract sequential list data type. -*- coding: utf-8 -*- - Copyright (C) 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2006-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2006. This program is free software: you can redistribute it and/or modify @@ -130,7 +130,7 @@ typedef const struct gl_list_implementation * gl_list_implementation_t; #if 0 /* Unless otherwise specified, these are defined inline below. */ -/* Create an empty list. +/* Creates an empty list. IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST, GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST, GL_RBTREEHASH_LIST. @@ -145,14 +145,14 @@ extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation, gl_listelement_hashcode_fn hashcode_fn, gl_listelement_dispose_fn dispose_fn, bool allow_duplicates); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_t gl_list_nx_create_empty (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, gl_listelement_dispose_fn dispose_fn, bool allow_duplicates); -/* Create a list with given contents. +/* Creates a list with given contents. IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST, GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST, GL_RBTREEHASH_LIST. @@ -170,7 +170,7 @@ extern gl_list_t gl_list_create (gl_list_implementation_t implementation, gl_listelement_dispose_fn dispose_fn, bool allow_duplicates, size_t count, const void **contents); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_t gl_list_nx_create (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, @@ -178,17 +178,17 @@ extern gl_list_t gl_list_nx_create (gl_list_implementation_t implementation, bool allow_duplicates, size_t count, const void **contents); -/* Return the current number of elements in a list. */ +/* Returns the current number of elements in a list. */ extern size_t gl_list_size (gl_list_t list); -/* Return the element value represented by a list node. */ +/* Returns the element value represented by a list node. */ extern const void * gl_list_node_value (gl_list_t list, gl_list_node_t node); -/* Replace the element value represented by a list node. */ +/* Replaces the element value represented by a list node. */ /* declared in gl_xlist.h */ extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt); -/* Likewise. Return 0 upon success, -1 upon out-of-memory. */ +/* Likewise. Returns 0 upon success, -1 upon out-of-memory. */ extern int gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node, const void *elt) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) @@ -196,25 +196,25 @@ extern int gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node, #endif ; -/* Return the node immediately after the given node in the list, or NULL +/* Returns the node immediately after the given node in the list, or NULL if the given node is the last (rightmost) one in the list. */ extern gl_list_node_t gl_list_next_node (gl_list_t list, gl_list_node_t node); -/* Return the node immediately before the given node in the list, or NULL +/* Returns the node immediately before the given node in the list, or NULL if the given node is the first (leftmost) one in the list. */ extern gl_list_node_t gl_list_previous_node (gl_list_t list, gl_list_node_t node); -/* Return the element at a given position in the list. +/* Returns the element at a given position in the list. POSITION must be >= 0 and < gl_list_size (list). */ extern const void * gl_list_get_at (gl_list_t list, size_t position); -/* Replace the element at a given position in the list. +/* Replaces the element at a given position in the list. POSITION must be >= 0 and < gl_list_size (list). - Return its node. */ + Returns its node. */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_list_nx_set_at (gl_list_t list, size_t position, const void *elt) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) @@ -222,69 +222,69 @@ extern gl_list_node_t gl_list_nx_set_at (gl_list_t list, size_t position, #endif ; -/* Search whether an element is already in the list. - Return its node if found, or NULL if not present in the list. */ +/* Searches whether an element is already in the list. + Returns its node if found, or NULL if not present in the list. */ extern gl_list_node_t gl_list_search (gl_list_t list, const void *elt); -/* Search whether an element is already in the list, +/* Searches whether an element is already in the list, at a position >= START_INDEX. - Return its node if found, or NULL if not present in the list. */ + Returns its node if found, or NULL if not present in the list. */ extern gl_list_node_t gl_list_search_from (gl_list_t list, size_t start_index, const void *elt); -/* Search whether an element is already in the list, +/* Searches whether an element is already in the list, at a position >= START_INDEX and < END_INDEX. - Return its node if found, or NULL if not present in the list. */ + Returns its node if found, or NULL if not present in the list. */ extern gl_list_node_t gl_list_search_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *elt); -/* Search whether an element is already in the list. - Return its position if found, or (size_t)(-1) if not present in the list. */ +/* Searches whether an element is already in the list. + Returns its position if found, or (size_t)(-1) if not present in the list. */ extern size_t gl_list_indexof (gl_list_t list, const void *elt); -/* Search whether an element is already in the list, +/* Searches whether an element is already in the list, at a position >= START_INDEX. - Return its position if found, or (size_t)(-1) if not present in the list. */ + Returns its position if found, or (size_t)(-1) if not present in the list. */ extern size_t gl_list_indexof_from (gl_list_t list, size_t start_index, const void *elt); -/* Search whether an element is already in the list, +/* Searches whether an element is already in the list, at a position >= START_INDEX and < END_INDEX. - Return its position if found, or (size_t)(-1) if not present in the list. */ + Returns its position if found, or (size_t)(-1) if not present in the list. */ extern size_t gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *elt); -/* Add an element as the first element of the list. - Return its node. */ +/* Adds an element as the first element of the list. + Returns its node. */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_list_nx_add_first (gl_list_t list, const void *elt) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) __attribute__ ((__warn_unused_result__)) #endif ; -/* Add an element as the last element of the list. - Return its node. */ +/* Adds an element as the last element of the list. + Returns its node. */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_list_nx_add_last (gl_list_t list, const void *elt) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) __attribute__ ((__warn_unused_result__)) #endif ; -/* Add an element before a given element node of the list. - Return its node. */ +/* Adds an element before a given element node of the list. + Returns its node. */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_list_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt) @@ -293,12 +293,12 @@ extern gl_list_node_t gl_list_nx_add_before (gl_list_t list, #endif ; -/* Add an element after a given element node of the list. - Return its node. */ +/* Adds an element after a given element node of the list. + Returns its node. */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_list_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) @@ -306,12 +306,12 @@ extern gl_list_node_t gl_list_nx_add_after (gl_list_t list, gl_list_node_t node, #endif ; -/* Add an element at a given position in the list. +/* Adds an element at a given position in the list. POSITION must be >= 0 and <= gl_list_size (list). */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_list_nx_add_at (gl_list_t list, size_t position, const void *elt) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) @@ -319,20 +319,20 @@ extern gl_list_node_t gl_list_nx_add_at (gl_list_t list, size_t position, #endif ; -/* Remove an element from the list. - Return true. */ +/* Removes an element from the list. + Returns true. */ extern bool gl_list_remove_node (gl_list_t list, gl_list_node_t node); -/* Remove an element at a given position from the list. +/* Removes an element at a given position from the list. POSITION must be >= 0 and < gl_list_size (list). - Return true. */ + Returns true. */ extern bool gl_list_remove_at (gl_list_t list, size_t position); -/* Search and remove an element from the list. - Return true if it was found and removed. */ +/* Searches and removes an element from the list. + Returns true if it was found and removed. */ extern bool gl_list_remove (gl_list_t list, const void *elt); -/* Free an entire list. +/* Frees an entire list. (But this call does not free the elements of the list. It only invokes the DISPOSE_FN on each of the elements of the list, and only if the list is not a sublist.) */ @@ -361,12 +361,12 @@ typedef struct #if 0 /* These are defined inline below. */ -/* Create an iterator traversing a list. +/* Creates an iterator traversing a list. The list contents must not be modified while the iterator is in use, except for replacing or removing the last returned element. */ extern gl_list_iterator_t gl_list_iterator (gl_list_t list); -/* Create an iterator traversing the element with indices i, +/* Creates an iterator traversing the element with indices i, start_index <= i < end_index, of a list. The list contents must not be modified while the iterator is in use, except for replacing or removing the last returned element. */ @@ -374,13 +374,13 @@ extern gl_list_iterator_t gl_list_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index); -/* If there is a next element, store the next element in *ELTP, store its - node in *NODEP if NODEP is non-NULL, advance the iterator and return true. - Otherwise, return false. */ +/* If there is a next element, stores the next element in *ELTP, stores its + node in *NODEP if NODEP is non-NULL, advances the iterator and returns true. + Otherwise, returns false. */ extern bool gl_list_iterator_next (gl_list_iterator_t *iterator, const void **eltp, gl_list_node_t *nodep); -/* Free an iterator. */ +/* Frees an iterator. */ extern void gl_list_iterator_free (gl_list_iterator_t *iterator); #endif /* End of inline functions. */ @@ -396,21 +396,21 @@ typedef int (*gl_listelement_compar_fn) (const void *elt1, const void *elt2); #if 0 /* Unless otherwise specified, these are defined inline below. */ -/* Search whether an element is already in the list. +/* Searches whether an element is already in the list. The list is assumed to be sorted with COMPAR. - Return its node if found, or NULL if not present in the list. + Returns its node if found, or NULL if not present in the list. If the list contains several copies of ELT, the node of the leftmost one is returned. */ extern gl_list_node_t gl_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, const void *elt); -/* Search whether an element is already in the list. +/* Searches whether an element is already in the list. The list is assumed to be sorted with COMPAR. Only list elements with indices >= START_INDEX and < END_INDEX are considered; the implementation uses these bounds to minimize the number of COMPAR invocations. - Return its node if found, or NULL if not present in the list. + Returns its node if found, or NULL if not present in the list. If the list contains several copies of ELT, the node of the leftmost one is returned. */ extern gl_list_node_t gl_sortedlist_search_from_to (gl_list_t list, @@ -419,21 +419,21 @@ extern gl_list_node_t gl_sortedlist_search_from_to (gl_list_t list, size_t end_index, const void *elt); -/* Search whether an element is already in the list. +/* Searches whether an element is already in the list. The list is assumed to be sorted with COMPAR. - Return its position if found, or (size_t)(-1) if not present in the list. + Returns its position if found, or (size_t)(-1) if not present in the list. If the list contains several copies of ELT, the position of the leftmost one is returned. */ extern size_t gl_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, const void *elt); -/* Search whether an element is already in the list. +/* Searches whether an element is already in the list. The list is assumed to be sorted with COMPAR. Only list elements with indices >= START_INDEX and < END_INDEX are considered; the implementation uses these bounds to minimize the number of COMPAR invocations. - Return its position if found, or (size_t)(-1) if not present in the list. + Returns its position if found, or (size_t)(-1) if not present in the list. If the list contains several copies of ELT, the position of the leftmost one is returned. */ extern size_t gl_sortedlist_indexof_from_to (gl_list_t list, @@ -442,14 +442,14 @@ extern size_t gl_sortedlist_indexof_from_to (gl_list_t list, size_t end_index, const void *elt); -/* Add an element at the appropriate position in the list. +/* Adds an element at the appropriate position in the list. The list is assumed to be sorted with COMPAR. - Return its node. */ + Returns its node. */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_sortedlist_nx_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt) @@ -458,9 +458,9 @@ extern gl_list_node_t gl_sortedlist_nx_add (gl_list_t list, #endif ; -/* Search and remove an element from the list. +/* Searches and removes an element from the list. The list is assumed to be sorted with COMPAR. - Return true if it was found and removed. + Returns true if it was found and removed. If the list contains several copies of ELT, only the leftmost one is removed. */ extern bool gl_sortedlist_remove (gl_list_t list, diff --git a/contrib/tools/bison/lib/gl_xlist.h b/contrib/tools/bison/lib/gl_xlist.h index 87885c33c8..ef6b93f6a5 100644 --- a/contrib/tools/bison/lib/gl_xlist.h +++ b/contrib/tools/bison/lib/gl_xlist.h @@ -1,5 +1,5 @@ /* Abstract sequential list data type, with out-of-memory checking. - Copyright (C) 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2009. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/glthread/lock.c b/contrib/tools/bison/lib/glthread/lock.c new file mode 100644 index 0000000000..10af6f2e1f --- /dev/null +++ b/contrib/tools/bison/lib/glthread/lock.c @@ -0,0 +1,749 @@ +/* Locking in multithreaded situations. + Copyright (C) 2005-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. + Based on GCC's gthr-posix.h, gthr-posix95.h. */ + +#include <config.h> + +#include "glthread/lock.h" + +/* ========================================================================= */ + +#if USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +int +glthread_lock_init (gl_lock_t *lock) +{ + if (mtx_init (&lock->mutex, mtx_plain) != thrd_success) + return ENOMEM; + lock->init_needed = 0; + return 0; +} + +int +glthread_lock_lock (gl_lock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_lock (&lock->mutex) != thrd_success) + return EAGAIN; + return 0; +} + +int +glthread_lock_unlock (gl_lock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_unlock (&lock->mutex) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_lock_destroy (gl_lock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + mtx_destroy (&lock->mutex); + return 0; +} + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +int +glthread_rwlock_init (gl_rwlock_t *lock) +{ + if (mtx_init (&lock->lock, mtx_plain) != thrd_success + || cnd_init (&lock->waiting_readers) != thrd_success + || cnd_init (&lock->waiting_writers) != thrd_success) + return ENOMEM; + lock->waiting_writers_count = 0; + lock->runcount = 0; + lock->init_needed = 0; + return 0; +} + +int +glthread_rwlock_rdlock (gl_rwlock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_lock (&lock->lock) != thrd_success) + return EAGAIN; + /* Test whether only readers are currently running, and whether the runcount + field will not overflow, and whether no writer is waiting. The latter + condition is because POSIX recommends that "write locks shall take + precedence over read locks", to avoid "writer starvation". */ + while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_readers. */ + if (cnd_wait (&lock->waiting_readers, &lock->lock) != thrd_success) + { + mtx_unlock (&lock->lock); + return EINVAL; + } + } + lock->runcount++; + if (mtx_unlock (&lock->lock) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_rwlock_wrlock (gl_rwlock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_lock (&lock->lock) != thrd_success) + return EAGAIN; + /* Test whether no readers or writers are currently running. */ + while (!(lock->runcount == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_writers. */ + lock->waiting_writers_count++; + if (cnd_wait (&lock->waiting_writers, &lock->lock) != thrd_success) + { + lock->waiting_writers_count--; + mtx_unlock (&lock->lock); + return EINVAL; + } + lock->waiting_writers_count--; + } + lock->runcount--; /* runcount becomes -1 */ + if (mtx_unlock (&lock->lock) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_rwlock_unlock (gl_rwlock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_lock (&lock->lock) != thrd_success) + return EAGAIN; + if (lock->runcount < 0) + { + /* Drop a writer lock. */ + if (!(lock->runcount == -1)) + { + mtx_unlock (&lock->lock); + return EINVAL; + } + lock->runcount = 0; + } + else + { + /* Drop a reader lock. */ + if (!(lock->runcount > 0)) + { + mtx_unlock (&lock->lock); + return EINVAL; + } + lock->runcount--; + } + if (lock->runcount == 0) + { + /* POSIX recommends that "write locks shall take precedence over read + locks", to avoid "writer starvation". */ + if (lock->waiting_writers_count > 0) + { + /* Wake up one of the waiting writers. */ + if (cnd_signal (&lock->waiting_writers) != thrd_success) + { + mtx_unlock (&lock->lock); + return EINVAL; + } + } + else + { + /* Wake up all waiting readers. */ + if (cnd_broadcast (&lock->waiting_readers) != thrd_success) + { + mtx_unlock (&lock->lock); + return EINVAL; + } + } + } + if (mtx_unlock (&lock->lock) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_rwlock_destroy (gl_rwlock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + mtx_destroy (&lock->lock); + cnd_destroy (&lock->waiting_readers); + cnd_destroy (&lock->waiting_writers); + return 0; +} + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +int +glthread_recursive_lock_init (gl_recursive_lock_t *lock) +{ + if (mtx_init (&lock->mutex, mtx_plain | mtx_recursive) != thrd_success) + return ENOMEM; + lock->init_needed = 0; + return 0; +} + +int +glthread_recursive_lock_lock (gl_recursive_lock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_lock (&lock->mutex) != thrd_success) + return EAGAIN; + return 0; +} + +int +glthread_recursive_lock_unlock (gl_recursive_lock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_unlock (&lock->mutex) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_recursive_lock_destroy (gl_recursive_lock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + mtx_destroy (&lock->mutex); + return 0; +} + +/* -------------------------- gl_once_t datatype -------------------------- */ + +#endif + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +# if HAVE_PTHREAD_RWLOCK && (HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER || (defined PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP && (__GNU_LIBRARY__ > 1))) + +# if defined PTHREAD_RWLOCK_INITIALIZER || defined PTHREAD_RWLOCK_INITIALIZER_NP + +# if !HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER + /* glibc with bug https://sourceware.org/bugzilla/show_bug.cgi?id=13701 */ + +int +glthread_rwlock_init_for_glibc (pthread_rwlock_t *lock) +{ + pthread_rwlockattr_t attributes; + int err; + + err = pthread_rwlockattr_init (&attributes); + if (err != 0) + return err; + /* Note: PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP is the only value that + causes the writer to be preferred. PTHREAD_RWLOCK_PREFER_WRITER_NP does not + do this; see + http://man7.org/linux/man-pages/man3/pthread_rwlockattr_setkind_np.3.html */ + err = pthread_rwlockattr_setkind_np (&attributes, + PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP); + if (err == 0) + err = pthread_rwlock_init(lock, &attributes); + /* pthread_rwlockattr_destroy always returns 0. It cannot influence the + return value. */ + pthread_rwlockattr_destroy (&attributes); + return err; +} + +# endif +# else + +int +glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_rwlock_init (&lock->rwlock, NULL); + if (err != 0) + return err; + lock->initialized = 1; + return 0; +} + +int +glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) +{ + if (!lock->initialized) + { + int err; + + err = pthread_mutex_lock (&lock->guard); + if (err != 0) + return err; + if (!lock->initialized) + { + err = glthread_rwlock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } + err = pthread_mutex_unlock (&lock->guard); + if (err != 0) + return err; + } + return pthread_rwlock_rdlock (&lock->rwlock); +} + +int +glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) +{ + if (!lock->initialized) + { + int err; + + err = pthread_mutex_lock (&lock->guard); + if (err != 0) + return err; + if (!lock->initialized) + { + err = glthread_rwlock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } + err = pthread_mutex_unlock (&lock->guard); + if (err != 0) + return err; + } + return pthread_rwlock_wrlock (&lock->rwlock); +} + +int +glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) +{ + if (!lock->initialized) + return EINVAL; + return pthread_rwlock_unlock (&lock->rwlock); +} + +int +glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) +{ + int err; + + if (!lock->initialized) + return EINVAL; + err = pthread_rwlock_destroy (&lock->rwlock); + if (err != 0) + return err; + lock->initialized = 0; + return 0; +} + +# endif + +# else + +int +glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_init (&lock->lock, NULL); + if (err != 0) + return err; + err = pthread_cond_init (&lock->waiting_readers, NULL); + if (err != 0) + return err; + err = pthread_cond_init (&lock->waiting_writers, NULL); + if (err != 0) + return err; + lock->waiting_writers_count = 0; + lock->runcount = 0; + return 0; +} + +int +glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_lock (&lock->lock); + if (err != 0) + return err; + /* Test whether only readers are currently running, and whether the runcount + field will not overflow, and whether no writer is waiting. The latter + condition is because POSIX recommends that "write locks shall take + precedence over read locks", to avoid "writer starvation". */ + while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_readers. */ + err = pthread_cond_wait (&lock->waiting_readers, &lock->lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } + lock->runcount++; + return pthread_mutex_unlock (&lock->lock); +} + +int +glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_lock (&lock->lock); + if (err != 0) + return err; + /* Test whether no readers or writers are currently running. */ + while (!(lock->runcount == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_writers. */ + lock->waiting_writers_count++; + err = pthread_cond_wait (&lock->waiting_writers, &lock->lock); + if (err != 0) + { + lock->waiting_writers_count--; + pthread_mutex_unlock (&lock->lock); + return err; + } + lock->waiting_writers_count--; + } + lock->runcount--; /* runcount becomes -1 */ + return pthread_mutex_unlock (&lock->lock); +} + +int +glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_lock (&lock->lock); + if (err != 0) + return err; + if (lock->runcount < 0) + { + /* Drop a writer lock. */ + if (!(lock->runcount == -1)) + { + pthread_mutex_unlock (&lock->lock); + return EINVAL; + } + lock->runcount = 0; + } + else + { + /* Drop a reader lock. */ + if (!(lock->runcount > 0)) + { + pthread_mutex_unlock (&lock->lock); + return EINVAL; + } + lock->runcount--; + } + if (lock->runcount == 0) + { + /* POSIX recommends that "write locks shall take precedence over read + locks", to avoid "writer starvation". */ + if (lock->waiting_writers_count > 0) + { + /* Wake up one of the waiting writers. */ + err = pthread_cond_signal (&lock->waiting_writers); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } + else + { + /* Wake up all waiting readers. */ + err = pthread_cond_broadcast (&lock->waiting_readers); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } + } + return pthread_mutex_unlock (&lock->lock); +} + +int +glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_destroy (&lock->lock); + if (err != 0) + return err; + err = pthread_cond_destroy (&lock->waiting_readers); + if (err != 0) + return err; + err = pthread_cond_destroy (&lock->waiting_writers); + if (err != 0) + return err; + return 0; +} + +# endif + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +# if HAVE_PTHREAD_MUTEX_RECURSIVE + +# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + pthread_mutexattr_t attributes; + int err; + + err = pthread_mutexattr_init (&attributes); + if (err != 0) + return err; + err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutex_init (lock, &attributes); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutexattr_destroy (&attributes); + if (err != 0) + return err; + return 0; +} + +# else + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + pthread_mutexattr_t attributes; + int err; + + err = pthread_mutexattr_init (&attributes); + if (err != 0) + return err; + err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutex_init (&lock->recmutex, &attributes); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutexattr_destroy (&attributes); + if (err != 0) + return err; + lock->initialized = 1; + return 0; +} + +int +glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) +{ + if (!lock->initialized) + { + int err; + + err = pthread_mutex_lock (&lock->guard); + if (err != 0) + return err; + if (!lock->initialized) + { + err = glthread_recursive_lock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } + err = pthread_mutex_unlock (&lock->guard); + if (err != 0) + return err; + } + return pthread_mutex_lock (&lock->recmutex); +} + +int +glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) +{ + if (!lock->initialized) + return EINVAL; + return pthread_mutex_unlock (&lock->recmutex); +} + +int +glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) +{ + int err; + + if (!lock->initialized) + return EINVAL; + err = pthread_mutex_destroy (&lock->recmutex); + if (err != 0) + return err; + lock->initialized = 0; + return 0; +} + +# endif + +# else + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + int err; + + err = pthread_mutex_init (&lock->mutex, NULL); + if (err != 0) + return err; + lock->owner = (pthread_t) 0; + lock->depth = 0; + return 0; +} + +int +glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) +{ + pthread_t self = pthread_self (); + if (lock->owner != self) + { + int err; + + err = pthread_mutex_lock (&lock->mutex); + if (err != 0) + return err; + lock->owner = self; + } + if (++(lock->depth) == 0) /* wraparound? */ + { + lock->depth--; + return EAGAIN; + } + return 0; +} + +int +glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) +{ + if (lock->owner != pthread_self ()) + return EPERM; + if (lock->depth == 0) + return EINVAL; + if (--(lock->depth) == 0) + { + lock->owner = (pthread_t) 0; + return pthread_mutex_unlock (&lock->mutex); + } + else + return 0; +} + +int +glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) +{ + if (lock->owner != (pthread_t) 0) + return EBUSY; + return pthread_mutex_destroy (&lock->mutex); +} + +# endif + +/* -------------------------- gl_once_t datatype -------------------------- */ + +static const pthread_once_t fresh_once = PTHREAD_ONCE_INIT; + +int +glthread_once_singlethreaded (pthread_once_t *once_control) +{ + /* We don't know whether pthread_once_t is an integer type, a floating-point + type, a pointer type, or a structure type. */ + char *firstbyte = (char *)once_control; + if (*firstbyte == *(const char *)&fresh_once) + { + /* First time use of once_control. Invert the first byte. */ + *firstbyte = ~ *(const char *)&fresh_once; + return 1; + } + else + return 0; +} + +# if !(PTHREAD_IN_USE_DETECTION_HARD || USE_POSIX_THREADS_WEAK) + +int +glthread_once_multithreaded (pthread_once_t *once_control, + void (*init_function) (void)) +{ + int err = pthread_once (once_control, init_function); + if (err == ENOSYS) + { + /* This happens on FreeBSD 11: The pthread_once function in libc returns + ENOSYS. */ + if (glthread_once_singlethreaded (once_control)) + init_function (); + return 0; + } + return err; +} + +# endif + +#endif + +/* ========================================================================= */ + +#if USE_WINDOWS_THREADS + +#endif + +/* ========================================================================= */ diff --git a/contrib/tools/bison/lib/glthread/lock.h b/contrib/tools/bison/lib/glthread/lock.h new file mode 100644 index 0000000000..59485f2601 --- /dev/null +++ b/contrib/tools/bison/lib/glthread/lock.h @@ -0,0 +1,789 @@ +/* Locking in multithreaded situations. + Copyright (C) 2005-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. + Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-win32.h. */ + +/* This file contains locking primitives for use with a given thread library. + It does not contain primitives for creating threads or for other + synchronization primitives. + + Normal (non-recursive) locks: + Type: gl_lock_t + Declaration: gl_lock_define(extern, name) + Initializer: gl_lock_define_initialized(, name) + Initialization: gl_lock_init (name); + Taking the lock: gl_lock_lock (name); + Releasing the lock: gl_lock_unlock (name); + De-initialization: gl_lock_destroy (name); + Equivalent functions with control of error handling: + Initialization: err = glthread_lock_init (&name); + Taking the lock: err = glthread_lock_lock (&name); + Releasing the lock: err = glthread_lock_unlock (&name); + De-initialization: err = glthread_lock_destroy (&name); + + Read-Write (non-recursive) locks: + Type: gl_rwlock_t + Declaration: gl_rwlock_define(extern, name) + Initializer: gl_rwlock_define_initialized(, name) + Initialization: gl_rwlock_init (name); + Taking the lock: gl_rwlock_rdlock (name); + gl_rwlock_wrlock (name); + Releasing the lock: gl_rwlock_unlock (name); + De-initialization: gl_rwlock_destroy (name); + Equivalent functions with control of error handling: + Initialization: err = glthread_rwlock_init (&name); + Taking the lock: err = glthread_rwlock_rdlock (&name); + err = glthread_rwlock_wrlock (&name); + Releasing the lock: err = glthread_rwlock_unlock (&name); + De-initialization: err = glthread_rwlock_destroy (&name); + + Recursive locks: + Type: gl_recursive_lock_t + Declaration: gl_recursive_lock_define(extern, name) + Initializer: gl_recursive_lock_define_initialized(, name) + Initialization: gl_recursive_lock_init (name); + Taking the lock: gl_recursive_lock_lock (name); + Releasing the lock: gl_recursive_lock_unlock (name); + De-initialization: gl_recursive_lock_destroy (name); + Equivalent functions with control of error handling: + Initialization: err = glthread_recursive_lock_init (&name); + Taking the lock: err = glthread_recursive_lock_lock (&name); + Releasing the lock: err = glthread_recursive_lock_unlock (&name); + De-initialization: err = glthread_recursive_lock_destroy (&name); + + Once-only execution: + Type: gl_once_t + Initializer: gl_once_define(extern, name) + Execution: gl_once (name, initfunction); + Equivalent functions with control of error handling: + Execution: err = glthread_once (&name, initfunction); +*/ + + +#ifndef _LOCK_H +#define _LOCK_H + +#include <errno.h> +#include <stdlib.h> + +#if !defined c11_threads_in_use +# if HAVE_THREADS_H && USE_POSIX_THREADS_WEAK +# include <threads.h> +# pragma weak thrd_exit +# define c11_threads_in_use() (thrd_exit != NULL) +# else +# define c11_threads_in_use() 0 +# endif +#endif + +/* ========================================================================= */ + +#if USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS + +/* Use the ISO C threads library. */ + +# include <threads.h> + +# ifdef __cplusplus +extern "C" { +# endif + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef struct + { + int volatile init_needed; + once_flag init_once; + void (*init_func) (void); + mtx_t mutex; + } + gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_lock_t NAME; +# define gl_lock_define_initialized(STORAGECLASS, NAME) \ + static void _atomic_init_##NAME (void); \ + STORAGECLASS gl_lock_t NAME = \ + { 1, ONCE_FLAG_INIT, _atomic_init_##NAME }; \ + static void _atomic_init_##NAME (void) \ + { \ + if (glthread_lock_init (&(NAME))) \ + abort (); \ + } +extern int glthread_lock_init (gl_lock_t *lock); +extern int glthread_lock_lock (gl_lock_t *lock); +extern int glthread_lock_unlock (gl_lock_t *lock); +extern int glthread_lock_destroy (gl_lock_t *lock); + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +typedef struct + { + int volatile init_needed; + once_flag init_once; + void (*init_func) (void); + mtx_t lock; /* protects the remaining fields */ + cnd_t waiting_readers; /* waiting readers */ + cnd_t waiting_writers; /* waiting writers */ + unsigned int waiting_writers_count; /* number of waiting writers */ + int runcount; /* number of readers running, or -1 when a writer runs */ + } + gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + static void _atomic_init_##NAME (void); \ + STORAGECLASS gl_rwlock_t NAME = \ + { 1, ONCE_FLAG_INIT, _atomic_init_##NAME }; \ + static void _atomic_init_##NAME (void) \ + { \ + if (glthread_rwlock_init (&(NAME))) \ + abort (); \ + } +extern int glthread_rwlock_init (gl_rwlock_t *lock); +extern int glthread_rwlock_rdlock (gl_rwlock_t *lock); +extern int glthread_rwlock_wrlock (gl_rwlock_t *lock); +extern int glthread_rwlock_unlock (gl_rwlock_t *lock); +extern int glthread_rwlock_destroy (gl_rwlock_t *lock); + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +typedef struct + { + int volatile init_needed; + once_flag init_once; + void (*init_func) (void); + mtx_t mutex; + } + gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + static void _atomic_init_##NAME (void); \ + STORAGECLASS gl_recursive_lock_t NAME = \ + { 1, ONCE_FLAG_INIT, _atomic_init_##NAME }; \ + static void _atomic_init_##NAME (void) \ + { \ + if (glthread_recursive_lock_init (&(NAME))) \ + abort (); \ + } +extern int glthread_recursive_lock_init (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_lock (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_unlock (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_destroy (gl_recursive_lock_t *lock); + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef once_flag gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS once_flag NAME = ONCE_FLAG_INIT; +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (call_once (ONCE_CONTROL, INITFUNCTION), 0) + +# ifdef __cplusplus +} +# endif + +#endif + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +/* Use the POSIX threads library. */ + +# include <pthread.h> + +# ifdef __cplusplus +extern "C" { +# endif + +# if PTHREAD_IN_USE_DETECTION_HARD + +/* The pthread_in_use() detection needs to be done at runtime. */ +# define pthread_in_use() \ + glthread_in_use () +extern int glthread_in_use (void); + +# endif + +# if USE_POSIX_THREADS_WEAK + +/* Use weak references to the POSIX threads library. */ + +/* Weak references avoid dragging in external libraries if the other parts + of the program don't use them. Here we use them, because we don't want + every program that uses libintl to depend on libpthread. This assumes + that libpthread would not be loaded after libintl; i.e. if libintl is + loaded first, by an executable that does not depend on libpthread, and + then a module is dynamically loaded that depends on libpthread, libintl + will not be multithread-safe. */ + +/* The way to test at runtime whether libpthread is present is to test + whether a function pointer's value, such as &pthread_mutex_init, is + non-NULL. However, some versions of GCC have a bug through which, in + PIC mode, &foo != NULL always evaluates to true if there is a direct + call to foo(...) in the same function. To avoid this, we test the + address of a function in libpthread that we don't use. */ + +# pragma weak pthread_mutex_init +# pragma weak pthread_mutex_lock +# pragma weak pthread_mutex_unlock +# pragma weak pthread_mutex_destroy +# pragma weak pthread_rwlock_init +# pragma weak pthread_rwlock_rdlock +# pragma weak pthread_rwlock_wrlock +# pragma weak pthread_rwlock_unlock +# pragma weak pthread_rwlock_destroy +# pragma weak pthread_once +# pragma weak pthread_cond_init +# pragma weak pthread_cond_wait +# pragma weak pthread_cond_signal +# pragma weak pthread_cond_broadcast +# pragma weak pthread_cond_destroy +# pragma weak pthread_mutexattr_init +# pragma weak pthread_mutexattr_settype +# pragma weak pthread_mutexattr_destroy +# pragma weak pthread_rwlockattr_init +# if __GNU_LIBRARY__ > 1 +# pragma weak pthread_rwlockattr_setkind_np +# endif +# pragma weak pthread_rwlockattr_destroy +# ifndef pthread_self +# pragma weak pthread_self +# endif + +# if !PTHREAD_IN_USE_DETECTION_HARD + /* Considering all platforms with USE_POSIX_THREADS_WEAK, only few symbols + can be used to determine whether libpthread is in use. These are: + pthread_mutexattr_gettype + pthread_rwlockattr_destroy + pthread_rwlockattr_init + */ +# pragma weak pthread_mutexattr_gettype +# define pthread_in_use() \ + (pthread_mutexattr_gettype != NULL || c11_threads_in_use ()) +# endif + +# else + +# if !PTHREAD_IN_USE_DETECTION_HARD +# define pthread_in_use() 1 +# endif + +# endif + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef pthread_mutex_t gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS pthread_mutex_t NAME; +# define gl_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS pthread_mutex_t NAME = gl_lock_initializer; +# define gl_lock_initializer \ + PTHREAD_MUTEX_INITIALIZER +# define glthread_lock_init(LOCK) \ + (pthread_in_use () ? pthread_mutex_init (LOCK, NULL) : 0) +# define glthread_lock_lock(LOCK) \ + (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0) +# define glthread_lock_unlock(LOCK) \ + (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0) +# define glthread_lock_destroy(LOCK) \ + (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0) + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +# if HAVE_PTHREAD_RWLOCK && (HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER || (defined PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP && (__GNU_LIBRARY__ > 1))) + +# if defined PTHREAD_RWLOCK_INITIALIZER || defined PTHREAD_RWLOCK_INITIALIZER_NP + +typedef pthread_rwlock_t gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS pthread_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS pthread_rwlock_t NAME = gl_rwlock_initializer; +# if HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER +# if defined PTHREAD_RWLOCK_INITIALIZER +# define gl_rwlock_initializer \ + PTHREAD_RWLOCK_INITIALIZER +# else +# define gl_rwlock_initializer \ + PTHREAD_RWLOCK_INITIALIZER_NP +# endif +# define glthread_rwlock_init(LOCK) \ + (pthread_in_use () ? pthread_rwlock_init (LOCK, NULL) : 0) +# else /* glibc with bug https://sourceware.org/bugzilla/show_bug.cgi?id=13701 */ +# define gl_rwlock_initializer \ + PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP +# define glthread_rwlock_init(LOCK) \ + (pthread_in_use () ? glthread_rwlock_init_for_glibc (LOCK) : 0) +extern int glthread_rwlock_init_for_glibc (pthread_rwlock_t *lock); +# endif +# define glthread_rwlock_rdlock(LOCK) \ + (pthread_in_use () ? pthread_rwlock_rdlock (LOCK) : 0) +# define glthread_rwlock_wrlock(LOCK) \ + (pthread_in_use () ? pthread_rwlock_wrlock (LOCK) : 0) +# define glthread_rwlock_unlock(LOCK) \ + (pthread_in_use () ? pthread_rwlock_unlock (LOCK) : 0) +# define glthread_rwlock_destroy(LOCK) \ + (pthread_in_use () ? pthread_rwlock_destroy (LOCK) : 0) + +# else + +typedef struct + { + int initialized; + pthread_mutex_t guard; /* protects the initialization */ + pthread_rwlock_t rwlock; /* read-write lock */ + } + gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; +# define gl_rwlock_initializer \ + { 0, PTHREAD_MUTEX_INITIALIZER } +# define glthread_rwlock_init(LOCK) \ + (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0) +# define glthread_rwlock_rdlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_wrlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_unlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_destroy(LOCK) \ + (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0) +extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock); + +# endif + +# else + +typedef struct + { + pthread_mutex_t lock; /* protects the remaining fields */ + pthread_cond_t waiting_readers; /* waiting readers */ + pthread_cond_t waiting_writers; /* waiting writers */ + unsigned int waiting_writers_count; /* number of waiting writers */ + int runcount; /* number of readers running, or -1 when a writer runs */ + } + gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; +# define gl_rwlock_initializer \ + { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0 } +# define glthread_rwlock_init(LOCK) \ + (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0) +# define glthread_rwlock_rdlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_wrlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_unlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_destroy(LOCK) \ + (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0) +extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock); + +# endif + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +# if HAVE_PTHREAD_MUTEX_RECURSIVE + +# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP + +typedef pthread_mutex_t gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS pthread_mutex_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS pthread_mutex_t NAME = gl_recursive_lock_initializer; +# ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER +# define gl_recursive_lock_initializer \ + PTHREAD_RECURSIVE_MUTEX_INITIALIZER +# else +# define gl_recursive_lock_initializer \ + PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP +# endif +# define glthread_recursive_lock_init(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_lock(LOCK) \ + (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0) +# define glthread_recursive_lock_unlock(LOCK) \ + (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0) +# define glthread_recursive_lock_destroy(LOCK) \ + (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0) +extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); + +# else + +typedef struct + { + pthread_mutex_t recmutex; /* recursive mutex */ + pthread_mutex_t guard; /* protects the initialization */ + int initialized; + } + gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; +# define gl_recursive_lock_initializer \ + { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, 0 } +# define glthread_recursive_lock_init(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_lock(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_unlock(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_destroy(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0) +extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock); + +# endif + +# else + +/* Old versions of POSIX threads on Solaris did not have recursive locks. + We have to implement them ourselves. */ + +typedef struct + { + pthread_mutex_t mutex; + pthread_t owner; + unsigned long depth; + } + gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; +# define gl_recursive_lock_initializer \ + { PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0, 0 } +# define glthread_recursive_lock_init(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_lock(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_unlock(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_destroy(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0) +extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock); + +# endif + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef pthread_once_t gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT; +# if PTHREAD_IN_USE_DETECTION_HARD || USE_POSIX_THREADS_WEAK +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (pthread_in_use () \ + ? pthread_once (ONCE_CONTROL, INITFUNCTION) \ + : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0)) +# else +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (pthread_in_use () \ + ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \ + : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0)) +extern int glthread_once_multithreaded (pthread_once_t *once_control, + void (*init_function) (void)); +# endif +extern int glthread_once_singlethreaded (pthread_once_t *once_control); + +# ifdef __cplusplus +} +# endif + +#endif + +/* ========================================================================= */ + +#if USE_WINDOWS_THREADS + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include <windows.h> + +# include "windows-mutex.h" +# include "windows-rwlock.h" +# include "windows-recmutex.h" +# include "windows-once.h" + +# ifdef __cplusplus +extern "C" { +# endif + +/* We can use CRITICAL_SECTION directly, rather than the native Windows Event, + Mutex, Semaphore types, because + - we need only to synchronize inside a single process (address space), + not inter-process locking, + - we don't need to support trylock operations. (TryEnterCriticalSection + does not work on Windows 95/98/ME. Packages that need trylock usually + define their own mutex type.) */ + +/* There is no way to statically initialize a CRITICAL_SECTION. It needs + to be done lazily, once only. For this we need spinlocks. */ + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef glwthread_mutex_t gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_lock_t NAME; +# define gl_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_lock_t NAME = gl_lock_initializer; +# define gl_lock_initializer \ + GLWTHREAD_MUTEX_INIT +# define glthread_lock_init(LOCK) \ + (glwthread_mutex_init (LOCK), 0) +# define glthread_lock_lock(LOCK) \ + glwthread_mutex_lock (LOCK) +# define glthread_lock_unlock(LOCK) \ + glwthread_mutex_unlock (LOCK) +# define glthread_lock_destroy(LOCK) \ + glwthread_mutex_destroy (LOCK) + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +typedef glwthread_rwlock_t gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; +# define gl_rwlock_initializer \ + GLWTHREAD_RWLOCK_INIT +# define glthread_rwlock_init(LOCK) \ + (glwthread_rwlock_init (LOCK), 0) +# define glthread_rwlock_rdlock(LOCK) \ + glwthread_rwlock_rdlock (LOCK) +# define glthread_rwlock_wrlock(LOCK) \ + glwthread_rwlock_wrlock (LOCK) +# define glthread_rwlock_unlock(LOCK) \ + glwthread_rwlock_unlock (LOCK) +# define glthread_rwlock_destroy(LOCK) \ + glwthread_rwlock_destroy (LOCK) + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +typedef glwthread_recmutex_t gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; +# define gl_recursive_lock_initializer \ + GLWTHREAD_RECMUTEX_INIT +# define glthread_recursive_lock_init(LOCK) \ + (glwthread_recmutex_init (LOCK), 0) +# define glthread_recursive_lock_lock(LOCK) \ + glwthread_recmutex_lock (LOCK) +# define glthread_recursive_lock_unlock(LOCK) \ + glwthread_recmutex_unlock (LOCK) +# define glthread_recursive_lock_destroy(LOCK) \ + glwthread_recmutex_destroy (LOCK) + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef glwthread_once_t gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_once_t NAME = GLWTHREAD_ONCE_INIT; +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (glwthread_once (ONCE_CONTROL, INITFUNCTION), 0) + +# ifdef __cplusplus +} +# endif + +#endif + +/* ========================================================================= */ + +#if !(USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS) + +/* Provide dummy implementation if threads are not supported. */ + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef int gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) +# define gl_lock_define_initialized(STORAGECLASS, NAME) +# define glthread_lock_init(NAME) 0 +# define glthread_lock_lock(NAME) 0 +# define glthread_lock_unlock(NAME) 0 +# define glthread_lock_destroy(NAME) 0 + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +typedef int gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) +# define glthread_rwlock_init(NAME) 0 +# define glthread_rwlock_rdlock(NAME) 0 +# define glthread_rwlock_wrlock(NAME) 0 +# define glthread_rwlock_unlock(NAME) 0 +# define glthread_rwlock_destroy(NAME) 0 + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +typedef int gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) +# define glthread_recursive_lock_init(NAME) 0 +# define glthread_recursive_lock_lock(NAME) 0 +# define glthread_recursive_lock_unlock(NAME) 0 +# define glthread_recursive_lock_destroy(NAME) 0 + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef int gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_once_t NAME = 0; +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (*(ONCE_CONTROL) == 0 ? (*(ONCE_CONTROL) = ~ 0, INITFUNCTION (), 0) : 0) + +#endif + +/* ========================================================================= */ + +/* Macros with built-in error handling. */ + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +#define gl_lock_init(NAME) \ + do \ + { \ + if (glthread_lock_init (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_lock_lock(NAME) \ + do \ + { \ + if (glthread_lock_lock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_lock_unlock(NAME) \ + do \ + { \ + if (glthread_lock_unlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_lock_destroy(NAME) \ + do \ + { \ + if (glthread_lock_destroy (&NAME)) \ + abort (); \ + } \ + while (0) + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +#define gl_rwlock_init(NAME) \ + do \ + { \ + if (glthread_rwlock_init (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_rwlock_rdlock(NAME) \ + do \ + { \ + if (glthread_rwlock_rdlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_rwlock_wrlock(NAME) \ + do \ + { \ + if (glthread_rwlock_wrlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_rwlock_unlock(NAME) \ + do \ + { \ + if (glthread_rwlock_unlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_rwlock_destroy(NAME) \ + do \ + { \ + if (glthread_rwlock_destroy (&NAME)) \ + abort (); \ + } \ + while (0) + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +#define gl_recursive_lock_init(NAME) \ + do \ + { \ + if (glthread_recursive_lock_init (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_recursive_lock_lock(NAME) \ + do \ + { \ + if (glthread_recursive_lock_lock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_recursive_lock_unlock(NAME) \ + do \ + { \ + if (glthread_recursive_lock_unlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_recursive_lock_destroy(NAME) \ + do \ + { \ + if (glthread_recursive_lock_destroy (&NAME)) \ + abort (); \ + } \ + while (0) + +/* -------------------------- gl_once_t datatype -------------------------- */ + +#define gl_once(NAME, INITFUNCTION) \ + do \ + { \ + if (glthread_once (&NAME, INITFUNCTION)) \ + abort (); \ + } \ + while (0) + +/* ========================================================================= */ + +#endif /* _LOCK_H */ diff --git a/contrib/tools/bison/lib/glthread/threadlib.c b/contrib/tools/bison/lib/glthread/threadlib.c new file mode 100644 index 0000000000..28bf3c6f76 --- /dev/null +++ b/contrib/tools/bison/lib/glthread/threadlib.c @@ -0,0 +1,73 @@ +/* Multithreading primitives. + Copyright (C) 2005-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. */ + +#include <config.h> + +/* ========================================================================= */ + +#if USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS + +/* Use the POSIX threads library. */ + +# include <pthread.h> +# include <stdlib.h> + +# if PTHREAD_IN_USE_DETECTION_HARD + +/* The function to be executed by a dummy thread. */ +static void * +dummy_thread_func (void *arg) +{ + return arg; +} + +int +glthread_in_use (void) +{ + static int tested; + static int result; /* 1: linked with -lpthread, 0: only with libc */ + + if (!tested) + { + pthread_t thread; + + if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0) + /* Thread creation failed. */ + result = 0; + else + { + /* Thread creation works. */ + void *retval; + if (pthread_join (thread, &retval) != 0) + abort (); + result = 1; + } + tested = 1; + } + return result; +} + +# endif + +#endif + +/* ========================================================================= */ + +/* This declaration is solely to ensure that after preprocessing + this file is never empty. */ +typedef int dummy; diff --git a/contrib/tools/bison/lib/glthread/tls.c b/contrib/tools/bison/lib/glthread/tls.c new file mode 100644 index 0000000000..2492b00c0e --- /dev/null +++ b/contrib/tools/bison/lib/glthread/tls.c @@ -0,0 +1,41 @@ +/* Thread-local storage in multithreaded situations. + Copyright (C) 2005-2020 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. */ + +#include <config.h> + +#include "glthread/tls.h" + +/* ========================================================================= */ + +#if USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS + +#endif + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +#endif + +/* ========================================================================= */ + +#if USE_WINDOWS_THREADS + +#endif + +/* ========================================================================= */ diff --git a/contrib/tools/bison/lib/glthread/tls.h b/contrib/tools/bison/lib/glthread/tls.h new file mode 100644 index 0000000000..d11e89bac8 --- /dev/null +++ b/contrib/tools/bison/lib/glthread/tls.h @@ -0,0 +1,228 @@ +/* Thread-local storage in multithreaded situations. + Copyright (C) 2005, 2007-2020 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. */ + +/* This file contains thread-local storage primitives for use with a given + thread library. It does not contain primitives for creating threads or + for other multithreading primitives. + + Type: gl_tls_key_t + Initialization: gl_tls_key_init (name, destructor); + Getting per-thread value: gl_tls_get (name) + Setting per-thread value: gl_tls_set (name, pointer); + De-initialization: gl_tls_key_destroy (name); + Equivalent functions with control of error handling: + Initialization: err = glthread_tls_key_init (&name, destructor); + Setting per-thread value: err = glthread_tls_set (&name, pointer); + De-initialization: err = glthread_tls_key_destroy (&name); + + A per-thread value is of type 'void *'. + + A destructor is a function pointer of type 'void (*) (void *)', called + when a thread exits, and taking the last per-thread value as argument. It + is unspecified whether the destructor function is called when the last + per-thread value is NULL. On some platforms, the destructor function is + not called at all. +*/ + + +#ifndef _TLS_H +#define _TLS_H + +#include <errno.h> +#include <stdlib.h> + +#if !defined c11_threads_in_use +# if HAVE_THREADS_H && USE_POSIX_THREADS_WEAK +# include <threads.h> +# pragma weak thrd_exit +# define c11_threads_in_use() (thrd_exit != NULL) +# else +# define c11_threads_in_use() 0 +# endif +#endif + +/* ========================================================================= */ + +#if USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS + +/* Use the ISO C threads library. */ + +# include <threads.h> + +/* ------------------------- gl_tls_key_t datatype ------------------------- */ + +typedef tss_t gl_tls_key_t; +# define glthread_tls_key_init(KEY, DESTRUCTOR) \ + (tss_create (KEY, DESTRUCTOR) != thrd_success ? EAGAIN : 0) +# define gl_tls_get(NAME) \ + tss_get (NAME) +# define glthread_tls_set(KEY, POINTER) \ + (tss_set (*(KEY), (POINTER)) != thrd_success ? ENOMEM : 0) +# define glthread_tls_key_destroy(KEY) \ + (tss_delete (*(KEY)), 0) + +#endif + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +/* Use the POSIX threads library. */ + +# include <pthread.h> + +# if PTHREAD_IN_USE_DETECTION_HARD + +/* The pthread_in_use() detection needs to be done at runtime. */ +# define pthread_in_use() \ + glthread_in_use () +extern int glthread_in_use (void); + +# endif + +# if USE_POSIX_THREADS_WEAK + +/* Use weak references to the POSIX threads library. */ + +# pragma weak pthread_key_create +# pragma weak pthread_getspecific +# pragma weak pthread_setspecific +# pragma weak pthread_key_delete +# ifndef pthread_self +# pragma weak pthread_self +# endif + +# if !PTHREAD_IN_USE_DETECTION_HARD +# pragma weak pthread_mutexattr_gettype +# define pthread_in_use() \ + (pthread_mutexattr_gettype != NULL || c11_threads_in_use ()) +# endif + +# else + +# if !PTHREAD_IN_USE_DETECTION_HARD +# define pthread_in_use() 1 +# endif + +# endif + +/* ------------------------- gl_tls_key_t datatype ------------------------- */ + +typedef union + { + void *singlethread_value; + pthread_key_t key; + } + gl_tls_key_t; +# define glthread_tls_key_init(KEY, DESTRUCTOR) \ + (pthread_in_use () \ + ? pthread_key_create (&(KEY)->key, DESTRUCTOR) \ + : ((KEY)->singlethread_value = NULL, 0)) +# define gl_tls_get(NAME) \ + (pthread_in_use () \ + ? pthread_getspecific ((NAME).key) \ + : (NAME).singlethread_value) +# define glthread_tls_set(KEY, POINTER) \ + (pthread_in_use () \ + ? pthread_setspecific ((KEY)->key, (POINTER)) \ + : ((KEY)->singlethread_value = (POINTER), 0)) +# define glthread_tls_key_destroy(KEY) \ + (pthread_in_use () ? pthread_key_delete ((KEY)->key) : 0) + +#endif + +/* ========================================================================= */ + +#if USE_WINDOWS_THREADS + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include <windows.h> + +# include "windows-tls.h" + +/* ------------------------- gl_tls_key_t datatype ------------------------- */ + +typedef glwthread_tls_key_t gl_tls_key_t; +# define glthread_tls_key_init(KEY, DESTRUCTOR) \ + glwthread_tls_key_create (KEY, DESTRUCTOR) +# define gl_tls_get(NAME) \ + TlsGetValue (NAME) +# define glthread_tls_set(KEY, POINTER) \ + (!TlsSetValue (*(KEY), POINTER) ? EINVAL : 0) +# define glthread_tls_key_destroy(KEY) \ + glwthread_tls_key_delete (*(KEY)) + +#endif + +/* ========================================================================= */ + +#if !(USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS) + +/* Provide dummy implementation if threads are not supported. */ + +/* ------------------------- gl_tls_key_t datatype ------------------------- */ + +typedef struct + { + void *singlethread_value; + } + gl_tls_key_t; +# define glthread_tls_key_init(KEY, DESTRUCTOR) \ + ((KEY)->singlethread_value = NULL, \ + (void) (DESTRUCTOR), \ + 0) +# define gl_tls_get(NAME) \ + (NAME).singlethread_value +# define glthread_tls_set(KEY, POINTER) \ + ((KEY)->singlethread_value = (POINTER), 0) +# define glthread_tls_key_destroy(KEY) \ + 0 + +#endif + +/* ========================================================================= */ + +/* Macros with built-in error handling. */ + +/* ------------------------- gl_tls_key_t datatype ------------------------- */ + +#define gl_tls_key_init(NAME, DESTRUCTOR) \ + do \ + { \ + if (glthread_tls_key_init (&NAME, DESTRUCTOR)) \ + abort (); \ + } \ + while (0) +#define gl_tls_set(NAME, POINTER) \ + do \ + { \ + if (glthread_tls_set (&NAME, POINTER)) \ + abort (); \ + } \ + while (0) +#define gl_tls_key_destroy(NAME) \ + do \ + { \ + if (glthread_tls_key_destroy (&NAME)) \ + abort (); \ + } \ + while (0) + +/* ========================================================================= */ + +#endif /* _TLS_H */ diff --git a/contrib/tools/bison/lib/hard-locale.c b/contrib/tools/bison/lib/hard-locale.c index dcfcad62ee..237f875b3a 100644 --- a/contrib/tools/bison/lib/hard-locale.c +++ b/contrib/tools/bison/lib/hard-locale.c @@ -1,6 +1,6 @@ /* hard-locale.c -- Determine whether a locale is hard. - Copyright (C) 1997-1999, 2002-2004, 2006-2007, 2009-2019 Free Software + Copyright (C) 1997-1999, 2002-2004, 2006-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -19,54 +19,18 @@ #include <config.h> #include "hard-locale.h" +#include "setlocale_null.h" #include <locale.h> -#include <stdlib.h> #include <string.h> -#ifdef __GLIBC__ -# define GLIBC_VERSION __GLIBC__ -#elif defined __UCLIBC__ -# define GLIBC_VERSION 2 -#else -# define GLIBC_VERSION 0 -#endif - -/* Return true if the current CATEGORY locale is hard, i.e. if you - can't get away with assuming traditional C or POSIX behavior. */ bool hard_locale (int category) { - bool hard = true; - char const *p = setlocale (category, NULL); - - if (p) - { - if (2 <= GLIBC_VERSION) - { - if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0) - hard = false; - } - else - { - char *locale = strdup (p); - if (locale) - { - /* Temporarily set the locale to the "C" and "POSIX" locales - to find their names, so that we can determine whether one - or the other is the caller's locale. */ - if (((p = setlocale (category, "C")) - && strcmp (p, locale) == 0) - || ((p = setlocale (category, "POSIX")) - && strcmp (p, locale) == 0)) - hard = false; + char locale[SETLOCALE_NULL_MAX]; - /* Restore the caller's locale. */ - setlocale (category, locale); - free (locale); - } - } - } + if (setlocale_null_r (category, locale, sizeof (locale))) + return false; - return hard; + return !(strcmp (locale, "C") == 0 || strcmp (locale, "POSIX") == 0); } diff --git a/contrib/tools/bison/lib/hard-locale.h b/contrib/tools/bison/lib/hard-locale.h index 8f1da96e2f..1886eaae92 100644 --- a/contrib/tools/bison/lib/hard-locale.h +++ b/contrib/tools/bison/lib/hard-locale.h @@ -1,6 +1,6 @@ /* Determine whether a locale is hard. - Copyright (C) 1999, 2003-2004, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1999, 2003-2004, 2009-2020 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 @@ -20,6 +20,9 @@ # include <stdbool.h> -bool hard_locale (int); +/* Return true if the specified CATEGORY of the current locale is hard, i.e. + different from the C or POSIX locale that has a fixed behavior. + CATEGORY must be one of the LC_* values, but not LC_ALL. */ +extern bool hard_locale (int category); #endif /* HARD_LOCALE_H_ */ diff --git a/contrib/tools/bison/lib/hash.c b/contrib/tools/bison/lib/hash.c index 9e1f8e8417..7aaf106267 100644 --- a/contrib/tools/bison/lib/hash.c +++ b/contrib/tools/bison/lib/hash.c @@ -1,6 +1,6 @@ /* hash - hashing table processing. - Copyright (C) 1998-2004, 2006-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1998-2004, 2006-2007, 2009-2020 Free Software Foundation, Inc. Written by Jim Meyering, 1992. diff --git a/contrib/tools/bison/lib/hash.h b/contrib/tools/bison/lib/hash.h index a1a483a359..2ff4266a4f 100644 --- a/contrib/tools/bison/lib/hash.h +++ b/contrib/tools/bison/lib/hash.h @@ -1,5 +1,5 @@ /* hash - hashing table processing. - Copyright (C) 1998-1999, 2001, 2003, 2009-2019 Free Software Foundation, + Copyright (C) 1998-1999, 2001, 2003, 2009-2020 Free Software Foundation, Inc. Written by Jim Meyering <meyering@ascend.com>, 1998. @@ -89,6 +89,9 @@ void hash_reset_tuning (Hash_tuning *); Hash_table *hash_initialize (size_t, const Hash_tuning *, Hash_hasher, Hash_comparator, Hash_data_freer) _GL_ATTRIBUTE_WUR; +Hash_table *hash_xinitialize (size_t, const Hash_tuning *, + Hash_hasher, Hash_comparator, + Hash_data_freer) _GL_ATTRIBUTE_WUR; void hash_clear (Hash_table *); void hash_free (Hash_table *); diff --git a/contrib/tools/bison/lib/intprops.h b/contrib/tools/bison/lib/intprops.h new file mode 100644 index 0000000000..dfbcaae73e --- /dev/null +++ b/contrib/tools/bison/lib/intprops.h @@ -0,0 +1,584 @@ +/* intprops.h -- properties of integer types + + Copyright (C) 2001-2020 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#ifndef _GL_INTPROPS_H +#define _GL_INTPROPS_H + +#include <limits.h> + +/* Return a value with the common real type of E and V and the value of V. + Do not evaluate E. */ +#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v)) + +/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see + <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00406.html>. */ +#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v)) + +/* The extra casts in the following macros work around compiler bugs, + e.g., in Cray C 5.0.3.0. */ + +/* True if the arithmetic type T is an integer type. bool counts as + an integer. */ +#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1) + +/* True if the real type T is signed. */ +#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) + +/* Return 1 if the real expression E, after promotion, has a + signed or floating type. Do not evaluate E. */ +#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0) + + +/* Minimum and maximum values for integer types and expressions. */ + +/* The width in bits of the integer type or expression T. + Do not evaluate T. + Padding bits are not supported; this is checked at compile-time below. */ +#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT) + +/* 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 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1))) + +/* The maximum and minimum values for the type of the expression E, + after integer promotion. E is not evaluated. */ +#define _GL_INT_MINIMUM(e) \ + (EXPR_SIGNED (e) \ + ? ~ _GL_SIGNED_INT_MAXIMUM (e) \ + : _GL_INT_CONVERT (e, 0)) +#define _GL_INT_MAXIMUM(e) \ + (EXPR_SIGNED (e) \ + ? _GL_SIGNED_INT_MAXIMUM (e) \ + : _GL_INT_NEGATE_CONVERT (e, 1)) +#define _GL_SIGNED_INT_MAXIMUM(e) \ + (((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH ((e) + 0) - 2)) - 1) * 2 + 1) + +/* Work around OpenVMS incompatibility with C99. */ +#if !defined LLONG_MAX && defined __INT64_MAX +# define LLONG_MAX __INT64_MAX +# define LLONG_MIN __INT64_MIN +#endif + +/* 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. + This assumption is tested by the intprops-tests module. */ + +/* 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__ \ + || (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \ + || (0x5110 <= __SUNPRO_C && !__STDC__)) +# define _GL_HAVE___TYPEOF__ 1 +#else +# define _GL_HAVE___TYPEOF__ 0 +#endif + +/* Return 1 if the integer type or expression T might be signed. Return 0 + if it is definitely unsigned. This macro does not evaluate its argument, + and expands to an integer constant expression. */ +#if _GL_HAVE___TYPEOF__ +# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t)) +#else +# define _GL_SIGNED_TYPE_OR_EXPR(t) 1 +#endif + +/* Bound on length of the string representing an unsigned integer + value representable in B bits. log10 (2.0) < 146/485. The + smallest value of B where this bound is not tight is 2621. */ +#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485) + +/* Bound on length of the string representing an integer type or expression T. + Subtract 1 for the sign bit if T is signed, and then add 1 more for + a minus sign if needed. + + Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 1 when its argument is + unsigned, this macro may overestimate the true bound by one byte when + applied to unsigned types of size 2, 4, 16, ... bytes. */ +#define INT_STRLEN_BOUND(t) \ + (INT_BITS_STRLEN_BOUND (TYPE_WIDTH (t) - _GL_SIGNED_TYPE_OR_EXPR (t)) \ + + _GL_SIGNED_TYPE_OR_EXPR (t)) + +/* Bound on buffer size needed to represent an integer type or expression T, + including the terminating null. */ +#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1) + + +/* Range overflow checks. + + The INT_<op>_RANGE_OVERFLOW macros return 1 if the corresponding C + operators might not yield numerically correct answers due to + arithmetic overflow. They do not rely on undefined or + implementation-defined behavior. Their implementations are simple + and straightforward, but they are a bit harder to use than the + INT_<op>_OVERFLOW macros described below. + + Example usage: + + long int i = ...; + long int j = ...; + if (INT_MULTIPLY_RANGE_OVERFLOW (i, j, LONG_MIN, LONG_MAX)) + printf ("multiply would overflow"); + else + printf ("product is %ld", i * j); + + Restrictions on *_RANGE_OVERFLOW macros: + + These macros do not check for all possible numerical problems or + undefined or unspecified behavior: they do not check for division + by zero, for bad shift counts, or for shifting negative numbers. + + These macros may evaluate their arguments zero or multiple times, + so the arguments should not have side effects. The arithmetic + arguments (including the MIN and MAX arguments) must be of the same + integer type after the usual arithmetic conversions, and the type + must have minimum value MIN and maximum MAX. Unsigned types should + use a zero MIN of the proper type. + + These macros are tuned for constant MIN and MAX. For commutative + operations such as A + B, they are also tuned for constant B. */ + +/* Return 1 if A + B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_ADD_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? (a) < (min) - (b) \ + : (max) - (b) < (a)) + +/* Return 1 if A - B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_SUBTRACT_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? (max) + (b) < (a) \ + : (a) < (min) + (b)) + +/* Return 1 if - A would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_NEGATE_RANGE_OVERFLOW(a, min, max) \ + ((min) < 0 \ + ? (a) < - (max) \ + : 0 < (a)) + +/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Avoid && and || as they tickle + bugs in Sun C 5.11 2010/08/13 and other compilers; see + <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00401.html>. */ +#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? ((a) < 0 \ + ? (a) < (max) / (b) \ + : (b) == -1 \ + ? 0 \ + : (min) / (b) < (a)) \ + : (b) == 0 \ + ? 0 \ + : ((a) < 0 \ + ? (a) < (min) / (b) \ + : (max) / (b) < (a))) + +/* Return 1 if A / B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Do not check for division by zero. */ +#define INT_DIVIDE_RANGE_OVERFLOW(a, b, min, max) \ + ((min) < 0 && (b) == -1 && (a) < - (max)) + +/* Return 1 if A % B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Do not check for division by zero. + Mathematically, % should never overflow, but on x86-like hosts + INT_MIN % -1 traps, and the C standard permits this, so treat this + as an overflow too. */ +#define INT_REMAINDER_RANGE_OVERFLOW(a, b, min, max) \ + INT_DIVIDE_RANGE_OVERFLOW (a, b, min, max) + +/* Return 1 if A << B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Here, MIN and MAX are for A only, and B need + not be of the same type as the other arguments. The C standard says that + behavior is undefined for shifts unless 0 <= B < wordwidth, and that when + A is negative then A << B has undefined behavior and A >> B has + implementation-defined behavior, but do not check these other + restrictions. */ +#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max) \ + ((a) < 0 \ + ? (a) < (min) >> (b) \ + : (max) >> (b) < (a)) + +/* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow + (A, B, P) work when P is non-null. */ +#if 5 <= __GNUC__ && !defined __ICC +# define _GL_HAS_BUILTIN_ADD_OVERFLOW 1 +#elif defined __has_builtin +# define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow) +#else +# define _GL_HAS_BUILTIN_ADD_OVERFLOW 0 +#endif + +/* True if __builtin_mul_overflow (A, B, P) works when P is non-null. */ +#ifdef __clang__ +/* Work around Clang bug <https://bugs.llvm.org/show_bug.cgi?id=16404>. */ +# define _GL_HAS_BUILTIN_MUL_OVERFLOW 0 +#else +# define _GL_HAS_BUILTIN_MUL_OVERFLOW _GL_HAS_BUILTIN_ADD_OVERFLOW +#endif + +/* True if __builtin_add_overflow_p (A, B, C) works, and similarly for + __builtin_mul_overflow_p and __builtin_mul_overflow_p. */ +#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__) + +/* The _GL*_OVERFLOW macros have the same restrictions as the + *_RANGE_OVERFLOW macros, except that they do not assume that operands + (e.g., A and B) have the same type as MIN and MAX. Instead, they assume + that the result (e.g., A + B) has that type. */ +#if _GL_HAS_BUILTIN_OVERFLOW_P +# define _GL_ADD_OVERFLOW(a, b, min, max) \ + __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0) +# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ + __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0) +# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ + __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0) +#else +# define _GL_ADD_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ + : (a) < 0 ? (b) <= (a) + (b) \ + : (b) < 0 ? (a) <= (a) + (b) \ + : (a) + (b) < (b)) +# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \ + : (a) < 0 ? 1 \ + : (b) < 0 ? (a) - (b) <= (a) \ + : (a) < (b)) +# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ + (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \ + || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max)) +#endif +#define _GL_DIVIDE_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ + : (a) < 0 ? (b) <= (a) + (b) - 1 \ + : (b) < 0 && (a) + (b) <= (a)) +#define _GL_REMAINDER_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ + : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \ + : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max)) + +/* Return a nonzero value if A is a mathematical multiple of B, where + A is unsigned, B is negative, and MAX is the maximum value of A's + type. A's type must be the same as (A % B)'s type. Normally (A % + -B == 0) suffices, but things get tricky if -B would overflow. */ +#define _GL_UNSIGNED_NEG_MULTIPLE(a, b, max) \ + (((b) < -_GL_SIGNED_INT_MAXIMUM (b) \ + ? (_GL_SIGNED_INT_MAXIMUM (b) == (max) \ + ? (a) \ + : (a) % (_GL_INT_CONVERT (a, _GL_SIGNED_INT_MAXIMUM (b)) + 1)) \ + : (a) % - (b)) \ + == 0) + +/* Check for integer overflow, and report low order bits of answer. + + The INT_<op>_OVERFLOW macros return 1 if the corresponding C operators + might not yield numerically correct answers due to arithmetic overflow. + The INT_<op>_WRAPV macros compute the low-order bits of the sum, + difference, and product of two C integers, and return 1 if these + low-order bits are not numerically correct. + These macros work correctly on all known practical hosts, and do not rely + on undefined behavior due to signed arithmetic overflow. + + Example usage, assuming A and B are long int: + + if (INT_MULTIPLY_OVERFLOW (a, b)) + printf ("result would overflow\n"); + else + printf ("result is %ld (no overflow)\n", a * b); + + Example usage with WRAPV flavor: + + long int result; + bool overflow = INT_MULTIPLY_WRAPV (a, b, &result); + printf ("result is %ld (%s)\n", result, + overflow ? "after overflow" : "no overflow"); + + Restrictions on these macros: + + These macros do not check for all possible numerical problems or + undefined or unspecified behavior: they do not check for division + by zero, for bad shift counts, or for shifting negative numbers. + + These macros may evaluate their arguments zero or multiple times, so the + arguments should not have side effects. + + The WRAPV macros are not constant expressions. They support only + +, binary -, and *. Because the WRAPV macros convert the result, + they report overflow in different circumstances than the OVERFLOW + macros do. + + These macros are tuned for their last input argument being a constant. + + Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B, + A % B, and A << B would overflow, respectively. */ + +#define INT_ADD_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW) +#define INT_SUBTRACT_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) +#if _GL_HAS_BUILTIN_OVERFLOW_P +# define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a) +#else +# define INT_NEGATE_OVERFLOW(a) \ + INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a)) +#endif +#define INT_MULTIPLY_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW) +#define INT_DIVIDE_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_DIVIDE_OVERFLOW) +#define INT_REMAINDER_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_REMAINDER_OVERFLOW) +#define INT_LEFT_SHIFT_OVERFLOW(a, b) \ + INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \ + _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a)) + +/* Return 1 if the expression A <op> B would overflow, + where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test, + assuming MIN and MAX are the minimum and maximum for the result type. + Arguments should be free of side effects. */ +#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ + op_result_overflow (a, b, \ + _GL_INT_MINIMUM (_GL_INT_CONVERT (a, b)), \ + _GL_INT_MAXIMUM (_GL_INT_CONVERT (a, b))) + +/* Store the low-order bits of A + B, A - B, A * B, respectively, into *R. + Return 1 if the result overflows. See above for restrictions. */ +#if _GL_HAS_BUILTIN_ADD_OVERFLOW +# define INT_ADD_WRAPV(a, b, r) __builtin_add_overflow (a, b, r) +# define INT_SUBTRACT_WRAPV(a, b, r) __builtin_sub_overflow (a, b, r) +#else +# define INT_ADD_WRAPV(a, b, r) \ + _GL_INT_OP_WRAPV (a, b, r, +, _GL_INT_ADD_RANGE_OVERFLOW) +# define INT_SUBTRACT_WRAPV(a, b, r) \ + _GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW) +#endif +#if _GL_HAS_BUILTIN_MUL_OVERFLOW +# if (9 < __GNUC__ + (3 <= __GNUC_MINOR__) \ + || (__GNUC__ == 8 && 4 <= __GNUC_MINOR__)) +# define INT_MULTIPLY_WRAPV(a, b, r) __builtin_mul_overflow (a, b, r) +# else + /* Work around GCC bug 91450. */ +# define INT_MULTIPLY_WRAPV(a, b, r) \ + ((!_GL_SIGNED_TYPE_OR_EXPR (*(r)) && EXPR_SIGNED (a) && EXPR_SIGNED (b) \ + && _GL_INT_MULTIPLY_RANGE_OVERFLOW (a, b, 0, (__typeof__ (*(r))) -1)) \ + ? ((void) __builtin_mul_overflow (a, b, r), 1) \ + : __builtin_mul_overflow (a, b, r)) +# endif +#else +# define INT_MULTIPLY_WRAPV(a, b, r) \ + _GL_INT_OP_WRAPV (a, b, r, *, _GL_INT_MULTIPLY_RANGE_OVERFLOW) +#endif + +/* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See: + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193 + https://llvm.org/bugs/show_bug.cgi?id=25390 + For now, assume all versions of GCC-like compilers generate bogus + warnings for _Generic. This matters only for compilers that + lack relevant builtins. */ +#if __GNUC__ +# define _GL__GENERIC_BOGUS 1 +#else +# define _GL__GENERIC_BOGUS 0 +#endif + +/* Store the low-order bits of A <op> B into *R, where OP specifies + the operation and OVERFLOW the overflow predicate. Return 1 if the + result overflows. See above for restrictions. */ +#if 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS +# define _GL_INT_OP_WRAPV(a, b, r, op, overflow) \ + (_Generic \ + (*(r), \ + signed char: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + signed char, SCHAR_MIN, SCHAR_MAX), \ + unsigned char: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + unsigned char, 0, UCHAR_MAX), \ + short int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + short int, SHRT_MIN, SHRT_MAX), \ + unsigned short int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + unsigned short int, 0, USHRT_MAX), \ + int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + int, INT_MIN, INT_MAX), \ + unsigned int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + unsigned int, 0, UINT_MAX), \ + long int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + long int, LONG_MIN, LONG_MAX), \ + unsigned long int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + unsigned long int, 0, ULONG_MAX), \ + long long int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \ + long long int, LLONG_MIN, LLONG_MAX), \ + unsigned long long int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \ + unsigned long long int, 0, ULLONG_MAX))) +#else +/* Store the low-order bits of A <op> B into *R, where OP specifies + the operation and OVERFLOW the overflow predicate. If *R is + signed, its type is ST with bounds SMIN..SMAX; otherwise its type + is UT with bounds U..UMAX. ST and UT are narrower than int. + Return 1 if the result overflows. See above for restrictions. */ +# if _GL_HAVE___TYPEOF__ +# define _GL_INT_OP_WRAPV_SMALLISH(a,b,r,op,overflow,st,smin,smax,ut,umax) \ + (TYPE_SIGNED (__typeof__ (*(r))) \ + ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, st, smin, smax) \ + : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, ut, 0, umax)) +# else +# define _GL_INT_OP_WRAPV_SMALLISH(a,b,r,op,overflow,st,smin,smax,ut,umax) \ + (overflow (a, b, smin, smax) \ + ? (overflow (a, b, 0, umax) \ + ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st), 1) \ + : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st)) < 0) \ + : (overflow (a, b, 0, umax) \ + ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st)) >= 0 \ + : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st), 0))) +# endif + +# define _GL_INT_OP_WRAPV(a, b, r, op, overflow) \ + (sizeof *(r) == sizeof (signed char) \ + ? _GL_INT_OP_WRAPV_SMALLISH (a, b, r, op, overflow, \ + signed char, SCHAR_MIN, SCHAR_MAX, \ + unsigned char, UCHAR_MAX) \ + : sizeof *(r) == sizeof (short int) \ + ? _GL_INT_OP_WRAPV_SMALLISH (a, b, r, op, overflow, \ + short int, SHRT_MIN, SHRT_MAX, \ + unsigned short int, USHRT_MAX) \ + : sizeof *(r) == sizeof (int) \ + ? (EXPR_SIGNED (*(r)) \ + ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + int, INT_MIN, INT_MAX) \ + : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + unsigned int, 0, UINT_MAX)) \ + : _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow)) +# ifdef LLONG_MAX +# define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \ + (sizeof *(r) == sizeof (long int) \ + ? (EXPR_SIGNED (*(r)) \ + ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + long int, LONG_MIN, LONG_MAX) \ + : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + unsigned long int, 0, ULONG_MAX)) \ + : (EXPR_SIGNED (*(r)) \ + ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \ + long long int, LLONG_MIN, LLONG_MAX) \ + : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \ + unsigned long long int, 0, ULLONG_MAX))) +# else +# define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \ + (EXPR_SIGNED (*(r)) \ + ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + long int, LONG_MIN, LONG_MAX) \ + : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + unsigned long int, 0, ULONG_MAX)) +# endif +#endif + +/* Store the low-order bits of A <op> B into *R, where the operation + is given by OP. Use the unsigned type UT for calculation to avoid + overflow problems. *R's type is T, with extrema TMIN and TMAX. + T must be a signed integer type. Return 1 if the result overflows. */ +#define _GL_INT_OP_CALC(a, b, r, op, overflow, ut, t, tmin, tmax) \ + (overflow (a, b, tmin, tmax) \ + ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 1) \ + : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 0)) + +/* Return the low-order bits of A <op> B, where the operation is given + by OP. Use the unsigned type UT for calculation to avoid undefined + behavior on signed integer overflow, and convert the result to type T. + UT is at least as wide as T and is no narrower than unsigned int, + T is two's complement, and there is no padding or trap representations. + Assume that converting UT to T yields the low-order bits, as is + done in all known two's-complement C compilers. E.g., see: + https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html + + According to the C standard, converting UT to T yields an + implementation-defined result or signal for values outside T's + range. However, code that works around this theoretical problem + runs afoul of a compiler bug in Oracle Studio 12.3 x86. See: + https://lists.gnu.org/r/bug-gnulib/2017-04/msg00049.html + As the compiler bug is real, don't try to work around the + theoretical problem. */ + +#define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t) \ + ((t) ((ut) (a) op (ut) (b))) + +/* Return true if the numeric values A + B, A - B, A * B fall outside + the range TMIN..TMAX. Arguments should be integer expressions + without side effects. TMIN should be signed and nonpositive. + TMAX should be positive, and should be signed unless TMIN is zero. */ +#define _GL_INT_ADD_RANGE_OVERFLOW(a, b, tmin, tmax) \ + ((b) < 0 \ + ? (((tmin) \ + ? ((EXPR_SIGNED (_GL_INT_CONVERT (a, (tmin) - (b))) || (b) < (tmin)) \ + && (a) < (tmin) - (b)) \ + : (a) <= -1 - (b)) \ + || ((EXPR_SIGNED (a) ? 0 <= (a) : (tmax) < (a)) && (tmax) < (a) + (b))) \ + : (a) < 0 \ + ? (((tmin) \ + ? ((EXPR_SIGNED (_GL_INT_CONVERT (b, (tmin) - (a))) || (a) < (tmin)) \ + && (b) < (tmin) - (a)) \ + : (b) <= -1 - (a)) \ + || ((EXPR_SIGNED (_GL_INT_CONVERT (a, b)) || (tmax) < (b)) \ + && (tmax) < (a) + (b))) \ + : (tmax) < (b) || (tmax) - (b) < (a)) +#define _GL_INT_SUBTRACT_RANGE_OVERFLOW(a, b, tmin, tmax) \ + (((a) < 0) == ((b) < 0) \ + ? ((a) < (b) \ + ? !(tmin) || -1 - (tmin) < (b) - (a) - 1 \ + : (tmax) < (a) - (b)) \ + : (a) < 0 \ + ? ((!EXPR_SIGNED (_GL_INT_CONVERT ((a) - (tmin), b)) && (a) - (tmin) < 0) \ + || (a) - (tmin) < (b)) \ + : ((! (EXPR_SIGNED (_GL_INT_CONVERT (tmax, b)) \ + && EXPR_SIGNED (_GL_INT_CONVERT ((tmax) + (b), a))) \ + && (tmax) <= -1 - (b)) \ + || (tmax) + (b) < (a))) +#define _GL_INT_MULTIPLY_RANGE_OVERFLOW(a, b, tmin, tmax) \ + ((b) < 0 \ + ? ((a) < 0 \ + ? (EXPR_SIGNED (_GL_INT_CONVERT (tmax, b)) \ + ? (a) < (tmax) / (b) \ + : ((INT_NEGATE_OVERFLOW (b) \ + ? _GL_INT_CONVERT (b, tmax) >> (TYPE_WIDTH (b) - 1) \ + : (tmax) / -(b)) \ + <= -1 - (a))) \ + : INT_NEGATE_OVERFLOW (_GL_INT_CONVERT (b, tmin)) && (b) == -1 \ + ? (EXPR_SIGNED (a) \ + ? 0 < (a) + (tmin) \ + : 0 < (a) && -1 - (tmin) < (a) - 1) \ + : (tmin) / (b) < (a)) \ + : (b) == 0 \ + ? 0 \ + : ((a) < 0 \ + ? (INT_NEGATE_OVERFLOW (_GL_INT_CONVERT (a, tmin)) && (a) == -1 \ + ? (EXPR_SIGNED (b) ? 0 < (b) + (tmin) : -1 - (tmin) < (b) - 1) \ + : (tmin) / (a) < (b)) \ + : (tmax) / (b) < (a))) + +#endif /* _GL_INTPROPS_H */ diff --git a/contrib/tools/bison/lib/isnand-nolibm.h b/contrib/tools/bison/lib/isnand-nolibm.h index 174c61ebd2..cbabed4c10 100644 --- a/contrib/tools/bison/lib/isnand-nolibm.h +++ b/contrib/tools/bison/lib/isnand-nolibm.h @@ -1,5 +1,5 @@ /* Test for NaN that does not need libm. - Copyright (C) 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2007-2020 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 diff --git a/contrib/tools/bison/lib/isnanl-nolibm.h b/contrib/tools/bison/lib/isnanl-nolibm.h index fdedf56b62..c45e3ab2c7 100644 --- a/contrib/tools/bison/lib/isnanl-nolibm.h +++ b/contrib/tools/bison/lib/isnanl-nolibm.h @@ -1,5 +1,5 @@ /* Test for NaN that does not need libm. - Copyright (C) 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2007-2020 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 diff --git a/contrib/tools/bison/lib/localcharset.c b/contrib/tools/bison/lib/localcharset.c index 579972bc2f..38026dffed 100644 --- a/contrib/tools/bison/lib/localcharset.c +++ b/contrib/tools/bison/lib/localcharset.c @@ -1,6 +1,6 @@ /* Determine a canonical name for the current locale's character encoding. - Copyright (C) 2000-2006, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2000-2006, 2008-2020 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 @@ -58,6 +58,9 @@ #elif defined WINDOWS_NATIVE # define WIN32_LEAN_AND_MEAN # include <windows.h> + /* For the use of setlocale() below, the Gnulib override in setlocale.c is + not needed; see the platform lists in setlocale_null.m4. */ +# undef setlocale #endif #if defined OS2 # define INCL_DOS @@ -150,7 +153,8 @@ static const struct table_entry alias_table[] = { "ISO8859-2", "ISO-8859-2" }, { "ISO8859-4", "ISO-8859-4" }, { "ISO8859-5", "ISO-8859-5" }, - { "ISO8859-7", "ISO-8859-7" } + { "ISO8859-7", "ISO-8859-7" }, + { "US-ASCII", "ASCII" } # define alias_table_defined # endif # if defined __APPLE__ && defined __MACH__ /* Mac OS X */ @@ -377,27 +381,164 @@ static const struct table_entry alias_table[] = /* The list of encodings is taken from "List of OS/2 Codepages" by Alex Taylor: <http://altsan.org/os2/toolkits/uls/index.html#codepages>. - See also "IBM Globalization - Code page identifiers": - <https://www-01.ibm.com/software/globalization/cp/cp_cpgid.html>. */ - { "CP1089", "ISO-8859-6" }, - { "CP1208", "UTF-8" }, - { "CP1381", "GB2312" }, - { "CP1386", "GBK" }, - { "CP3372", "EUC-JP" }, - { "CP813", "ISO-8859-7" }, - { "CP819", "ISO-8859-1" }, - { "CP878", "KOI8-R" }, - { "CP912", "ISO-8859-2" }, - { "CP913", "ISO-8859-3" }, - { "CP914", "ISO-8859-4" }, - { "CP915", "ISO-8859-5" }, - { "CP916", "ISO-8859-8" }, - { "CP920", "ISO-8859-9" }, - { "CP921", "ISO-8859-13" }, - { "CP923", "ISO-8859-15" }, - { "CP954", "EUC-JP" }, - { "CP964", "EUC-TW" }, - { "CP970", "EUC-KR" } + See also "__convcp() of kLIBC": + <https://github.com/bitwiseworks/libc/blob/master/src/emx/src/lib/locale/__convcp.c>. */ + { "CP1004", "CP1252" }, + /*{ "CP1041", "CP943" },*/ + /*{ "CP1088", "CP949" },*/ + { "CP1089", "ISO-8859-6" }, + /*{ "CP1114", "CP950" },*/ + /*{ "CP1115", "GB2312" },*/ + { "CP1208", "UTF-8" }, + /*{ "CP1380", "GB2312" },*/ + { "CP1381", "GB2312" }, + { "CP1383", "GB2312" }, + { "CP1386", "GBK" }, + /*{ "CP301", "CP943" },*/ + { "CP3372", "EUC-JP" }, + { "CP4946", "CP850" }, + /*{ "CP5048", "JIS_X0208-1990" },*/ + /*{ "CP5049", "JIS_X0212-1990" },*/ + /*{ "CP5067", "KS_C_5601-1987" },*/ + { "CP813", "ISO-8859-7" }, + { "CP819", "ISO-8859-1" }, + { "CP878", "KOI8-R" }, + /*{ "CP897", "CP943" },*/ + { "CP912", "ISO-8859-2" }, + { "CP913", "ISO-8859-3" }, + { "CP914", "ISO-8859-4" }, + { "CP915", "ISO-8859-5" }, + { "CP916", "ISO-8859-8" }, + { "CP920", "ISO-8859-9" }, + { "CP921", "ISO-8859-13" }, + { "CP923", "ISO-8859-15" }, + /*{ "CP941", "CP943" },*/ + /*{ "CP947", "CP950" },*/ + /*{ "CP951", "CP949" },*/ + /*{ "CP952", "JIS_X0208-1990" },*/ + /*{ "CP953", "JIS_X0212-1990" },*/ + { "CP954", "EUC-JP" }, + { "CP964", "EUC-TW" }, + { "CP970", "EUC-KR" }, + /*{ "CP971", "KS_C_5601-1987" },*/ + { "IBM-1004", "CP1252" }, + /*{ "IBM-1006", "?" },*/ + /*{ "IBM-1008", "?" },*/ + /*{ "IBM-1041", "CP943" },*/ + /*{ "IBM-1051", "?" },*/ + /*{ "IBM-1088", "CP949" },*/ + { "IBM-1089", "ISO-8859-6" }, + /*{ "IBM-1098", "?" },*/ + /*{ "IBM-1114", "CP950" },*/ + /*{ "IBM-1115", "GB2312" },*/ + /*{ "IBM-1116", "?" },*/ + /*{ "IBM-1117", "?" },*/ + /*{ "IBM-1118", "?" },*/ + /*{ "IBM-1119", "?" },*/ + { "IBM-1124", "CP1124" }, + { "IBM-1125", "CP1125" }, + { "IBM-1131", "CP1131" }, + { "IBM-1208", "UTF-8" }, + { "IBM-1250", "CP1250" }, + { "IBM-1251", "CP1251" }, + { "IBM-1252", "CP1252" }, + { "IBM-1253", "CP1253" }, + { "IBM-1254", "CP1254" }, + { "IBM-1255", "CP1255" }, + { "IBM-1256", "CP1256" }, + { "IBM-1257", "CP1257" }, + /*{ "IBM-1275", "?" },*/ + /*{ "IBM-1276", "?" },*/ + /*{ "IBM-1277", "?" },*/ + /*{ "IBM-1280", "?" },*/ + /*{ "IBM-1281", "?" },*/ + /*{ "IBM-1282", "?" },*/ + /*{ "IBM-1283", "?" },*/ + /*{ "IBM-1380", "GB2312" },*/ + { "IBM-1381", "GB2312" }, + { "IBM-1383", "GB2312" }, + { "IBM-1386", "GBK" }, + /*{ "IBM-301", "CP943" },*/ + { "IBM-3372", "EUC-JP" }, + { "IBM-367", "ASCII" }, + { "IBM-437", "CP437" }, + { "IBM-4946", "CP850" }, + /*{ "IBM-5048", "JIS_X0208-1990" },*/ + /*{ "IBM-5049", "JIS_X0212-1990" },*/ + /*{ "IBM-5067", "KS_C_5601-1987" },*/ + { "IBM-813", "ISO-8859-7" }, + { "IBM-819", "ISO-8859-1" }, + { "IBM-850", "CP850" }, + /*{ "IBM-851", "?" },*/ + { "IBM-852", "CP852" }, + { "IBM-855", "CP855" }, + { "IBM-856", "CP856" }, + { "IBM-857", "CP857" }, + /*{ "IBM-859", "?" },*/ + { "IBM-860", "CP860" }, + { "IBM-861", "CP861" }, + { "IBM-862", "CP862" }, + { "IBM-863", "CP863" }, + { "IBM-864", "CP864" }, + { "IBM-865", "CP865" }, + { "IBM-866", "CP866" }, + /*{ "IBM-868", "?" },*/ + { "IBM-869", "CP869" }, + { "IBM-874", "CP874" }, + { "IBM-878", "KOI8-R" }, + /*{ "IBM-895", "?" },*/ + /*{ "IBM-897", "CP943" },*/ + /*{ "IBM-907", "?" },*/ + /*{ "IBM-909", "?" },*/ + { "IBM-912", "ISO-8859-2" }, + { "IBM-913", "ISO-8859-3" }, + { "IBM-914", "ISO-8859-4" }, + { "IBM-915", "ISO-8859-5" }, + { "IBM-916", "ISO-8859-8" }, + { "IBM-920", "ISO-8859-9" }, + { "IBM-921", "ISO-8859-13" }, + { "IBM-922", "CP922" }, + { "IBM-923", "ISO-8859-15" }, + { "IBM-932", "CP932" }, + /*{ "IBM-941", "CP943" },*/ + /*{ "IBM-942", "?" },*/ + { "IBM-943", "CP943" }, + /*{ "IBM-947", "CP950" },*/ + { "IBM-949", "CP949" }, + { "IBM-950", "CP950" }, + /*{ "IBM-951", "CP949" },*/ + /*{ "IBM-952", "JIS_X0208-1990" },*/ + /*{ "IBM-953", "JIS_X0212-1990" },*/ + { "IBM-954", "EUC-JP" }, + /*{ "IBM-955", "?" },*/ + { "IBM-964", "EUC-TW" }, + { "IBM-970", "EUC-KR" }, + /*{ "IBM-971", "KS_C_5601-1987" },*/ + { "IBM-eucCN", "GB2312" }, + { "IBM-eucJP", "EUC-JP" }, + { "IBM-eucKR", "EUC-KR" }, + { "IBM-eucTW", "EUC-TW" }, + { "IBM33722", "EUC-JP" }, + { "ISO8859-1", "ISO-8859-1" }, + { "ISO8859-2", "ISO-8859-2" }, + { "ISO8859-3", "ISO-8859-3" }, + { "ISO8859-4", "ISO-8859-4" }, + { "ISO8859-5", "ISO-8859-5" }, + { "ISO8859-6", "ISO-8859-6" }, + { "ISO8859-7", "ISO-8859-7" }, + { "ISO8859-8", "ISO-8859-8" }, + { "ISO8859-9", "ISO-8859-9" }, + /*{ "JISX0201-1976", "JISX0201-1976" },*/ + /*{ "JISX0208-1978", "?" },*/ + /*{ "JISX0208-1983", "JIS_X0208-1983" },*/ + /*{ "JISX0208-1990", "JIS_X0208-1990" },*/ + /*{ "JISX0212-1990", "JIS_X0212-1990" },*/ + /*{ "KSC5601-1987", "KS_C_5601-1987" },*/ + { "SJIS-1", "CP943" }, + { "SJIS-2", "CP943" }, + { "eucJP", "EUC-JP" }, + { "eucKR", "EUC-KR" }, + { "eucTW-1993", "EUC-TW" } # define alias_table_defined # endif # if defined VMS /* OpenVMS */ @@ -675,8 +816,11 @@ static const struct table_entry locale_table[] = /* Determine the current locale's character encoding, and canonicalize it - into one of the canonical names listed in localcharset.h. - The result must not be freed; it is statically allocated. + into one of the canonical names listed below. + The result must not be freed; it is statically allocated. The result + becomes invalid when setlocale() is used to change the global locale, or + when the value of one of the environment variables LC_ALL, LC_CTYPE, LANG + is changed; threads in multithreaded programs should not do this. If the canonical name cannot be determined, the result is a non-canonical name. */ @@ -688,6 +832,13 @@ locale_charset (void) { const char *codeset; + /* This function must be multithread-safe. To achieve this without using + thread-local storage, we use a simple strcpy or memcpy to fill this static + buffer. Filling it through, for example, strcpy + strcat would not be + guaranteed to leave the buffer's contents intact if another thread is + currently accessing it. If necessary, the contents is first assembled in + a stack-allocated buffer. */ + #if HAVE_LANGINFO_CODESET || defined WINDOWS_NATIVE || defined OS2 # if HAVE_LANGINFO_CODESET @@ -702,7 +853,7 @@ locale_charset (void) if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0) { const char *locale; - static char buf[2 + 10 + 1]; + static char resultbuf[2 + 10 + 1]; locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') @@ -726,11 +877,12 @@ locale_charset (void) modifier = strchr (dot, '@'); if (modifier == NULL) return dot; - if (modifier - dot < sizeof (buf)) + if (modifier - dot < sizeof (resultbuf)) { - memcpy (buf, dot, modifier - dot); - buf [modifier - dot] = '\0'; - return buf; + /* This way of filling resultbuf is multithread-safe. */ + memcpy (resultbuf, dot, modifier - dot); + resultbuf [modifier - dot] = '\0'; + return resultbuf; } } } @@ -746,8 +898,13 @@ locale_charset (void) converting to GetConsoleOutputCP(). This leads to correct results, except when SetConsoleOutputCP has been called and a raster font is in use. */ - sprintf (buf, "CP%u", GetACP ()); - codeset = buf; + { + char buf[2 + 10 + 1]; + + sprintf (buf, "CP%u", GetACP ()); + strcpy (resultbuf, buf); + codeset = resultbuf; + } } # endif @@ -757,42 +914,44 @@ locale_charset (void) # elif defined WINDOWS_NATIVE - static char buf[2 + 10 + 1]; + char buf[2 + 10 + 1]; + static char resultbuf[2 + 10 + 1]; /* The Windows API has a function returning the locale's codepage as a number, but the value doesn't change according to what the 'setlocale' call specified. So we use it as a last resort, in case the string returned by 'setlocale' doesn't specify the codepage. */ - char *current_locale = setlocale (LC_ALL, NULL); - char *pdot; + char *current_locale = setlocale (LC_CTYPE, NULL); + char *pdot = strrchr (current_locale, '.'); - /* If they set different locales for different categories, - 'setlocale' will return a semi-colon separated list of locale - values. To make sure we use the correct one, we choose LC_CTYPE. */ - if (strchr (current_locale, ';')) - current_locale = setlocale (LC_CTYPE, NULL); - - pdot = strrchr (current_locale, '.'); if (pdot && 2 + strlen (pdot + 1) + 1 <= sizeof (buf)) sprintf (buf, "CP%s", pdot + 1); else { /* The Windows API has a function returning the locale's codepage as a - number: GetACP(). - When the output goes to a console window, it needs to be provided in - GetOEMCP() encoding if the console is using a raster font, or in - GetConsoleOutputCP() encoding if it is using a TrueType font. - But in GUI programs and for output sent to files and pipes, GetACP() - encoding is the best bet. */ + number: GetACP(). + When the output goes to a console window, it needs to be provided in + GetOEMCP() encoding if the console is using a raster font, or in + GetConsoleOutputCP() encoding if it is using a TrueType font. + But in GUI programs and for output sent to files and pipes, GetACP() + encoding is the best bet. */ sprintf (buf, "CP%u", GetACP ()); } - codeset = buf; + /* For a locale name such as "French_France.65001", in Windows 10, + setlocale now returns "French_France.utf8" instead. */ + if (strcmp (buf + 2, "65001") == 0 || strcmp (buf + 2, "utf8") == 0) + codeset = "UTF-8"; + else + { + strcpy (resultbuf, buf); + codeset = resultbuf; + } # elif defined OS2 const char *locale; - static char buf[2 + 10 + 1]; + static char resultbuf[2 + 10 + 1]; ULONG cp[3]; ULONG cplen; @@ -821,11 +980,12 @@ locale_charset (void) modifier = strchr (dot, '@'); if (modifier == NULL) return dot; - if (modifier - dot < sizeof (buf)) + if (modifier - dot < sizeof (resultbuf)) { - memcpy (buf, dot, modifier - dot); - buf [modifier - dot] = '\0'; - return buf; + /* This way of filling resultbuf is multithread-safe. */ + memcpy (resultbuf, dot, modifier - dot); + resultbuf [modifier - dot] = '\0'; + return resultbuf; } } @@ -841,8 +1001,11 @@ locale_charset (void) codeset = ""; else { + char buf[2 + 10 + 1]; + sprintf (buf, "CP%u", cp[0]); - codeset = buf; + strcpy (resultbuf, buf); + codeset = resultbuf; } } diff --git a/contrib/tools/bison/lib/localcharset.h b/contrib/tools/bison/lib/localcharset.h index 7d0d7711db..aa623be07a 100644 --- a/contrib/tools/bison/lib/localcharset.h +++ b/contrib/tools/bison/lib/localcharset.h @@ -1,5 +1,5 @@ /* Determine a canonical name for the current locale's character encoding. - Copyright (C) 2000-2003, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2000-2003, 2009-2020 Free Software Foundation, Inc. This file is part of the GNU CHARSET Library. This program is free software; you can redistribute it and/or modify @@ -26,7 +26,10 @@ extern "C" { /* Determine the current locale's character encoding, and canonicalize it into one of the canonical names listed below. - The result must not be freed; it is statically allocated. + The result must not be freed; it is statically allocated. The result + becomes invalid when setlocale() is used to change the global locale, or + when the value of one of the environment variables LC_ALL, LC_CTYPE, LANG + is changed; threads in multithreaded programs should not do this. If the canonical name cannot be determined, the result is a non-canonical name. */ extern const char * locale_charset (void); @@ -45,15 +48,15 @@ extern const char * locale_charset (void); (darwin = Mac OS X, windows = native Windows) ASCII, ANSI_X3.4-1968 glibc solaris freebsd netbsd darwin minix cygwin - ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin - ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin + ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos + ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos ISO-8859-3 Y glibc solaris cygwin ISO-8859-4 Y hpux osf solaris freebsd netbsd openbsd darwin - ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin + ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos ISO-8859-6 Y glibc aix hpux solaris cygwin - ISO-8859-7 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin - ISO-8859-8 Y glibc aix hpux osf solaris cygwin - ISO-8859-9 Y glibc aix hpux irix osf solaris freebsd darwin cygwin + ISO-8859-7 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos + ISO-8859-8 Y glibc aix hpux osf solaris cygwin zos + ISO-8859-9 Y glibc aix hpux irix osf solaris freebsd darwin cygwin zos ISO-8859-13 glibc hpux solaris freebsd netbsd openbsd darwin cygwin ISO-8859-14 glibc cygwin ISO-8859-15 glibc aix irix osf solaris freebsd netbsd openbsd darwin cygwin @@ -76,7 +79,7 @@ extern const char * locale_charset (void); CP874 windows dos CP922 aix CP932 aix cygwin windows dos - CP943 aix + CP943 aix zos CP949 osf darwin windows dos CP950 windows dos CP1046 aix @@ -92,17 +95,17 @@ extern const char * locale_charset (void); CP1255 glibc windows CP1256 windows CP1257 windows - GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin cygwin + GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin cygwin zos EUC-JP Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin - EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin + EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin zos EUC-TW glibc aix hpux irix osf solaris netbsd - BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin cygwin + BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin cygwin zos BIG5-HKSCS glibc hpux solaris netbsd darwin GBK glibc aix osf solaris freebsd darwin cygwin windows dos GB18030 glibc hpux solaris freebsd netbsd darwin SHIFT_JIS Y hpux osf solaris freebsd netbsd darwin JOHAB glibc solaris windows - TIS-620 glibc aix hpux osf solaris cygwin + TIS-620 glibc aix hpux osf solaris cygwin zos VISCII Y glibc TCVN5712-1 glibc ARMSCII-8 glibc freebsd netbsd darwin @@ -116,7 +119,7 @@ extern const char * locale_charset (void); HP-KANA8 hpux DEC-KANJI osf DEC-HANYU osf - UTF-8 Y glibc aix hpux osf solaris netbsd darwin cygwin + UTF-8 Y glibc aix hpux osf solaris netbsd darwin cygwin zos Note: Names which are not marked as being a MIME name should not be used in Internet protocols for information interchange (mail, news, etc.). diff --git a/contrib/tools/bison/lib/mbchar.c b/contrib/tools/bison/lib/mbchar.c new file mode 100644 index 0000000000..bd5c93215d --- /dev/null +++ b/contrib/tools/bison/lib/mbchar.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2001, 2006, 2009-2020 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 <https://www.gnu.org/licenses/>. */ + + +#include <config.h> + +#define MBCHAR_INLINE _GL_EXTERN_INLINE + +#include <limits.h> + +#include "mbchar.h" + +#if IS_BASIC_ASCII + +/* Bit table of characters in the ISO C "basic character set". */ +const unsigned int is_basic_table [UCHAR_MAX / 32 + 1] = +{ + 0x00001a00, /* '\t' '\v' '\f' */ + 0xffffffef, /* ' '...'#' '%'...'?' */ + 0xfffffffe, /* 'A'...'Z' '[' '\\' ']' '^' '_' */ + 0x7ffffffe /* 'a'...'z' '{' '|' '}' '~' */ + /* The remaining bits are 0. */ +}; + +#endif /* IS_BASIC_ASCII */ diff --git a/contrib/tools/bison/lib/mbchar.h b/contrib/tools/bison/lib/mbchar.h new file mode 100644 index 0000000000..8ff58bf519 --- /dev/null +++ b/contrib/tools/bison/lib/mbchar.h @@ -0,0 +1,360 @@ +/* Multibyte character data type. + Copyright (C) 2001, 2005-2007, 2009-2020 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>. */ + +/* A multibyte character is a short subsequence of a char* string, + representing a single wide character. + + We use multibyte characters instead of wide characters because of + the following goals: + 1) correct multibyte handling, i.e. operate according to the LC_CTYPE + locale, + 2) ease of maintenance, i.e. the maintainer needs not know all details + of the ISO C 99 standard, + 3) don't fail grossly if the input is not in the encoding set by the + locale, because often different encodings are in use in the same + countries (ISO-8859-1/UTF-8, EUC-JP/Shift_JIS, ...), + 4) fast in the case of ASCII characters, + 5) portability, i.e. don't make unportable assumptions about wchar_t. + + Multibyte characters are only accessed through the mb* macros. + + mb_ptr (mbc) + return a pointer to the beginning of the multibyte sequence. + + mb_len (mbc) + returns the number of bytes occupied by the multibyte sequence. + Always > 0. + + mb_iseq (mbc, sc) + returns true if mbc is the standard ASCII character sc. + + mb_isnul (mbc) + returns true if mbc is the nul character. + + mb_cmp (mbc1, mbc2) + returns a positive, zero, or negative value depending on whether mbc1 + sorts after, same or before mbc2. + + mb_casecmp (mbc1, mbc2) + returns a positive, zero, or negative value depending on whether mbc1 + sorts after, same or before mbc2, modulo upper/lowercase conversion. + + mb_equal (mbc1, mbc2) + returns true if mbc1 and mbc2 are equal. + + mb_caseequal (mbc1, mbc2) + returns true if mbc1 and mbc2 are equal modulo upper/lowercase conversion. + + mb_isalnum (mbc) + returns true if mbc is alphanumeric. + + mb_isalpha (mbc) + returns true if mbc is alphabetic. + + mb_isascii(mbc) + returns true if mbc is plain ASCII. + + mb_isblank (mbc) + returns true if mbc is a blank. + + mb_iscntrl (mbc) + returns true if mbc is a control character. + + mb_isdigit (mbc) + returns true if mbc is a decimal digit. + + mb_isgraph (mbc) + returns true if mbc is a graphic character. + + mb_islower (mbc) + returns true if mbc is lowercase. + + mb_isprint (mbc) + returns true if mbc is a printable character. + + mb_ispunct (mbc) + returns true if mbc is a punctuation character. + + mb_isspace (mbc) + returns true if mbc is a space character. + + mb_isupper (mbc) + returns true if mbc is uppercase. + + mb_isxdigit (mbc) + returns true if mbc is a hexadecimal digit. + + mb_width (mbc) + returns the number of columns on the output device occupied by mbc. + Always >= 0. + + mb_putc (mbc, stream) + outputs mbc on stream, a byte oriented FILE stream opened for output. + + mb_setascii (&mbc, sc) + assigns the standard ASCII character sc to mbc. + + mb_copy (&destmbc, &srcmbc) + copies srcmbc to destmbc. + + Here are the function prototypes of the macros. + + extern const char * mb_ptr (const mbchar_t mbc); + extern size_t mb_len (const mbchar_t mbc); + extern bool mb_iseq (const mbchar_t mbc, char sc); + extern bool mb_isnul (const mbchar_t mbc); + extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2); + extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_isalnum (const mbchar_t mbc); + extern bool mb_isalpha (const mbchar_t mbc); + extern bool mb_isascii (const mbchar_t mbc); + extern bool mb_isblank (const mbchar_t mbc); + extern bool mb_iscntrl (const mbchar_t mbc); + extern bool mb_isdigit (const mbchar_t mbc); + extern bool mb_isgraph (const mbchar_t mbc); + extern bool mb_islower (const mbchar_t mbc); + extern bool mb_isprint (const mbchar_t mbc); + extern bool mb_ispunct (const mbchar_t mbc); + extern bool mb_isspace (const mbchar_t mbc); + extern bool mb_isupper (const mbchar_t mbc); + extern bool mb_isxdigit (const mbchar_t mbc); + extern int mb_width (const mbchar_t mbc); + extern void mb_putc (const mbchar_t mbc, FILE *stream); + extern void mb_setascii (mbchar_t *new, char sc); + extern void mb_copy (mbchar_t *new, const mbchar_t *old); + */ + +#ifndef _MBCHAR_H +#define _MBCHAR_H 1 + +#include <stdbool.h> +#include <string.h> + +/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before + <wchar.h>. + BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before + <wchar.h>. */ +#include <stdio.h> +#include <time.h> +#include <wchar.h> +#include <wctype.h> + +#ifndef _GL_INLINE_HEADER_BEGIN + #error "Please include config.h first." +#endif +_GL_INLINE_HEADER_BEGIN +#ifndef MBCHAR_INLINE +# define MBCHAR_INLINE _GL_INLINE +#endif + +#define MBCHAR_BUF_SIZE 24 + +struct mbchar +{ + const char *ptr; /* pointer to current character */ + size_t bytes; /* number of bytes of current character, > 0 */ + bool wc_valid; /* true if wc is a valid wide character */ + wchar_t wc; /* if wc_valid: the current character */ + char buf[MBCHAR_BUF_SIZE]; /* room for the bytes, used for file input only */ +}; + +/* EOF (not a real character) is represented with bytes = 0 and + wc_valid = false. */ + +typedef struct mbchar mbchar_t; + +/* Access the current character. */ +#define mb_ptr(mbc) ((mbc).ptr) +#define mb_len(mbc) ((mbc).bytes) + +/* Comparison of characters. */ +#define mb_iseq(mbc, sc) ((mbc).wc_valid && (mbc).wc == (sc)) +#define mb_isnul(mbc) ((mbc).wc_valid && (mbc).wc == 0) +#define mb_cmp(mbc1, mbc2) \ + ((mbc1).wc_valid \ + ? ((mbc2).wc_valid \ + ? (int) (mbc1).wc - (int) (mbc2).wc \ + : -1) \ + : ((mbc2).wc_valid \ + ? 1 \ + : (mbc1).bytes == (mbc2).bytes \ + ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ + : (mbc1).bytes < (mbc2).bytes \ + ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ + : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) +#define mb_casecmp(mbc1, mbc2) \ + ((mbc1).wc_valid \ + ? ((mbc2).wc_valid \ + ? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \ + : -1) \ + : ((mbc2).wc_valid \ + ? 1 \ + : (mbc1).bytes == (mbc2).bytes \ + ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ + : (mbc1).bytes < (mbc2).bytes \ + ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ + : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) +#define mb_equal(mbc1, mbc2) \ + ((mbc1).wc_valid && (mbc2).wc_valid \ + ? (mbc1).wc == (mbc2).wc \ + : (mbc1).bytes == (mbc2).bytes \ + && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) +#define mb_caseequal(mbc1, mbc2) \ + ((mbc1).wc_valid && (mbc2).wc_valid \ + ? towlower ((mbc1).wc) == towlower ((mbc2).wc) \ + : (mbc1).bytes == (mbc2).bytes \ + && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) + +/* <ctype.h>, <wctype.h> classification. */ +#define mb_isascii(mbc) \ + ((mbc).wc_valid && (mbc).wc >= 0 && (mbc).wc <= 127) +#define mb_isalnum(mbc) ((mbc).wc_valid && iswalnum ((mbc).wc)) +#define mb_isalpha(mbc) ((mbc).wc_valid && iswalpha ((mbc).wc)) +#define mb_isblank(mbc) ((mbc).wc_valid && iswblank ((mbc).wc)) +#define mb_iscntrl(mbc) ((mbc).wc_valid && iswcntrl ((mbc).wc)) +#define mb_isdigit(mbc) ((mbc).wc_valid && iswdigit ((mbc).wc)) +#define mb_isgraph(mbc) ((mbc).wc_valid && iswgraph ((mbc).wc)) +#define mb_islower(mbc) ((mbc).wc_valid && iswlower ((mbc).wc)) +#define mb_isprint(mbc) ((mbc).wc_valid && iswprint ((mbc).wc)) +#define mb_ispunct(mbc) ((mbc).wc_valid && iswpunct ((mbc).wc)) +#define mb_isspace(mbc) ((mbc).wc_valid && iswspace ((mbc).wc)) +#define mb_isupper(mbc) ((mbc).wc_valid && iswupper ((mbc).wc)) +#define mb_isxdigit(mbc) ((mbc).wc_valid && iswxdigit ((mbc).wc)) + +/* Extra <wchar.h> function. */ + +/* Unprintable characters appear as a small box of width 1. */ +#define MB_UNPRINTABLE_WIDTH 1 + +MBCHAR_INLINE int +mb_width_aux (wint_t wc) +{ + int w = wcwidth (wc); + /* For unprintable characters, arbitrarily return 0 for control characters + and MB_UNPRINTABLE_WIDTH otherwise. */ + return (w >= 0 ? w : iswcntrl (wc) ? 0 : MB_UNPRINTABLE_WIDTH); +} + +#define mb_width(mbc) \ + ((mbc).wc_valid ? mb_width_aux ((mbc).wc) : MB_UNPRINTABLE_WIDTH) + +/* Output. */ +#define mb_putc(mbc, stream) fwrite ((mbc).ptr, 1, (mbc).bytes, (stream)) + +/* Assignment. */ +#define mb_setascii(mbc, sc) \ + ((mbc)->ptr = (mbc)->buf, (mbc)->bytes = 1, (mbc)->wc_valid = 1, \ + (mbc)->wc = (mbc)->buf[0] = (sc)) + +/* Copying a character. */ +MBCHAR_INLINE void +mb_copy (mbchar_t *new_mbc, const mbchar_t *old_mbc) +{ + if (old_mbc->ptr == &old_mbc->buf[0]) + { + memcpy (&new_mbc->buf[0], &old_mbc->buf[0], old_mbc->bytes); + new_mbc->ptr = &new_mbc->buf[0]; + } + else + new_mbc->ptr = old_mbc->ptr; + new_mbc->bytes = old_mbc->bytes; + if ((new_mbc->wc_valid = old_mbc->wc_valid)) + new_mbc->wc = old_mbc->wc; +} + + +/* is_basic(c) tests whether the single-byte character c is in the + ISO C "basic character set". + This is a convenience function, and is in this file only to share code + between mbiter_multi.h and mbfile_multi.h. */ +#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ + && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ + && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ + && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ + && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ + && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ + && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ + && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ + && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ + && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ + && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ + && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ + && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ + && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ + && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ + && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ + && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ + && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ + && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ + && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ + && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ + && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126) +/* The character set is ISO-646, not EBCDIC. */ +# define IS_BASIC_ASCII 1 + +extern const unsigned int is_basic_table[]; + +MBCHAR_INLINE bool +is_basic (char c) +{ + return (is_basic_table [(unsigned char) c >> 5] >> ((unsigned char) c & 31)) + & 1; +} + +#else + +MBCHAR_INLINE bool +is_basic (char c) +{ + switch (c) + { + case '\t': case '\v': case '\f': + case ' ': case '!': case '"': case '#': case '%': + case '&': case '\'': case '(': case ')': case '*': + case '+': case ',': case '-': case '.': case '/': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case ':': case ';': case '<': case '=': case '>': + case '?': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '[': case '\\': case ']': case '^': case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': case '{': case '|': case '}': case '~': + return 1; + default: + return 0; + } +} + +#endif + +_GL_INLINE_HEADER_END + +#endif /* _MBCHAR_H */ diff --git a/contrib/tools/bison/lib/mbfile.c b/contrib/tools/bison/lib/mbfile.c new file mode 100644 index 0000000000..b0a468efa6 --- /dev/null +++ b/contrib/tools/bison/lib/mbfile.c @@ -0,0 +1,3 @@ +#include <config.h> +#define MBFILE_INLINE _GL_EXTERN_INLINE +#include "mbfile.h" diff --git a/contrib/tools/bison/lib/mbfile.h b/contrib/tools/bison/lib/mbfile.h new file mode 100644 index 0000000000..6c86116f1c --- /dev/null +++ b/contrib/tools/bison/lib/mbfile.h @@ -0,0 +1,252 @@ +/* Multibyte character I/O: macros for multi-byte encodings. + Copyright (C) 2001, 2005, 2009-2020 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Mitsuru Chinen <mchinen@yamato.ibm.com> + and Bruno Haible <bruno@clisp.org>. */ + +/* The macros in this file implement multi-byte character input from a + stream. + + mb_file_t + is the type for multibyte character input stream, usable for variable + declarations. + + mbf_char_t + is the type for multibyte character or EOF, usable for variable + declarations. + + mbf_init (mbf, stream) + initializes the MB_FILE for reading from stream. + + mbf_getc (mbc, mbf) + reads the next multibyte character from mbf and stores it in mbc. + + mb_iseof (mbc) + returns true if mbc represents the EOF value. + + Here are the function prototypes of the macros. + + extern void mbf_init (mb_file_t mbf, FILE *stream); + extern void mbf_getc (mbf_char_t mbc, mb_file_t mbf); + extern bool mb_iseof (const mbf_char_t mbc); + */ + +#ifndef _MBFILE_H +#define _MBFILE_H 1 + +#include <assert.h> +#include <stdbool.h> +#include <stdio.h> +#include <string.h> + +/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before + <wchar.h>. + BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before + <wchar.h>. */ +#include <stdio.h> +#include <time.h> +#include <wchar.h> + +#include "mbchar.h" + +#ifndef _GL_INLINE_HEADER_BEGIN + #error "Please include config.h first." +#endif +_GL_INLINE_HEADER_BEGIN +#ifndef MBFILE_INLINE +# define MBFILE_INLINE _GL_INLINE +#endif + +struct mbfile_multi { + FILE *fp; + bool eof_seen; + bool have_pushback; + mbstate_t state; + unsigned int bufcount; + char buf[MBCHAR_BUF_SIZE]; + struct mbchar pushback; +}; + +MBFILE_INLINE void +mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf) +{ + size_t bytes; + + /* If EOF has already been seen, don't use getc. This matters if + mbf->fp is connected to an interactive tty. */ + if (mbf->eof_seen) + goto eof; + + /* Return character pushed back, if there is one. */ + if (mbf->have_pushback) + { + mb_copy (mbc, &mbf->pushback); + mbf->have_pushback = false; + return; + } + + /* Before using mbrtowc, we need at least one byte. */ + if (mbf->bufcount == 0) + { + int c = getc (mbf->fp); + if (c == EOF) + { + mbf->eof_seen = true; + goto eof; + } + mbf->buf[0] = (unsigned char) c; + mbf->bufcount++; + } + + /* Handle most ASCII characters quickly, without calling mbrtowc(). */ + if (mbf->bufcount == 1 && mbsinit (&mbf->state) && is_basic (mbf->buf[0])) + { + /* These characters are part of the basic character set. ISO C 99 + guarantees that their wide character code is identical to their + char code. */ + mbc->wc = mbc->buf[0] = mbf->buf[0]; + mbc->wc_valid = true; + mbc->ptr = &mbc->buf[0]; + mbc->bytes = 1; + mbf->bufcount = 0; + return; + } + + /* Use mbrtowc on an increasing number of bytes. Read only as many bytes + from mbf->fp as needed. This is needed to give reasonable interactive + behaviour when mbf->fp is connected to an interactive tty. */ + for (;;) + { + /* We don't know whether the 'mbrtowc' function updates the state when + it returns -2, - this is the ISO C 99 and glibc-2.2 behaviour - or + not - amended ANSI C, glibc-2.1 and Solaris 2.7 behaviour. We + don't have an autoconf test for this, yet. + The new behaviour would allow us to feed the bytes one by one into + mbrtowc. But the old behaviour forces us to feed all bytes since + the end of the last character into mbrtowc. Since we want to retry + with more bytes when mbrtowc returns -2, we must backup the state + before calling mbrtowc, because implementations with the new + behaviour will clobber it. */ + mbstate_t backup_state = mbf->state; + + bytes = mbrtowc (&mbc->wc, &mbf->buf[0], mbf->bufcount, &mbf->state); + + if (bytes == (size_t) -1) + { + /* An invalid multibyte sequence was encountered. */ + /* Return a single byte. */ + bytes = 1; + mbc->wc_valid = false; + break; + } + else if (bytes == (size_t) -2) + { + /* An incomplete multibyte character. */ + mbf->state = backup_state; + if (mbf->bufcount == MBCHAR_BUF_SIZE) + { + /* An overlong incomplete multibyte sequence was encountered. */ + /* Return a single byte. */ + bytes = 1; + mbc->wc_valid = false; + break; + } + else + { + /* Read one more byte and retry mbrtowc. */ + int c = getc (mbf->fp); + if (c == EOF) + { + /* An incomplete multibyte character at the end. */ + mbf->eof_seen = true; + bytes = mbf->bufcount; + mbc->wc_valid = false; + break; + } + mbf->buf[mbf->bufcount] = (unsigned char) c; + mbf->bufcount++; + } + } + else + { + if (bytes == 0) + { + /* A null wide character was encountered. */ + bytes = 1; + assert (mbf->buf[0] == '\0'); + assert (mbc->wc == 0); + } + mbc->wc_valid = true; + break; + } + } + + /* Return the multibyte sequence mbf->buf[0..bytes-1]. */ + mbc->ptr = &mbc->buf[0]; + memcpy (&mbc->buf[0], &mbf->buf[0], bytes); + mbc->bytes = bytes; + + mbf->bufcount -= bytes; + if (mbf->bufcount > 0) + { + /* It's not worth calling memmove() for so few bytes. */ + unsigned int count = mbf->bufcount; + char *p = &mbf->buf[0]; + + do + { + *p = *(p + bytes); + p++; + } + while (--count > 0); + } + return; + +eof: + /* An mbchar_t with bytes == 0 is used to indicate EOF. */ + mbc->ptr = NULL; + mbc->bytes = 0; + mbc->wc_valid = false; + return; +} + +MBFILE_INLINE void +mbfile_multi_ungetc (const struct mbchar *mbc, struct mbfile_multi *mbf) +{ + mb_copy (&mbf->pushback, mbc); + mbf->have_pushback = true; +} + +typedef struct mbfile_multi mb_file_t; + +typedef mbchar_t mbf_char_t; + +#define mbf_init(mbf, stream) \ + ((mbf).fp = (stream), \ + (mbf).eof_seen = false, \ + (mbf).have_pushback = false, \ + memset (&(mbf).state, '\0', sizeof (mbstate_t)), \ + (mbf).bufcount = 0) + +#define mbf_getc(mbc, mbf) mbfile_multi_getc (&(mbc), &(mbf)) + +#define mbf_ungetc(mbc, mbf) mbfile_multi_ungetc (&(mbc), &(mbf)) + +#define mb_iseof(mbc) ((mbc).bytes == 0) + +_GL_INLINE_HEADER_END + +#endif /* _MBFILE_H */ diff --git a/contrib/tools/bison/lib/mbrtowc.c b/contrib/tools/bison/lib/mbrtowc.c index bbe3f7a3b9..08e181bc3b 100644 --- a/contrib/tools/bison/lib/mbrtowc.c +++ b/contrib/tools/bison/lib/mbrtowc.c @@ -1,5 +1,5 @@ /* Convert multibyte character to wide character. - Copyright (C) 1999-2002, 2005-2019 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2005-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2008. This program is free software: you can redistribute it and/or modify @@ -20,20 +20,39 @@ /* Specification. */ #include <wchar.h> -#if C_LOCALE_MAYBE_EILSEQ -# include "hard-locale.h" -# include <locale.h> -#endif - #if GNULIB_defined_mbstate_t -/* Implement mbrtowc() on top of mbtowc(). */ +/* Implement mbrtowc() on top of mbtowc() for the non-UTF-8 locales + and directly for the UTF-8 locales. */ # include <errno.h> +# include <stdint.h> # include <stdlib.h> -# include "localcharset.h" -# include "streq.h" +# if defined _WIN32 && !defined __CYGWIN__ + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include <windows.h> + +# elif HAVE_PTHREAD_API + +# include <pthread.h> +# if HAVE_THREADS_H && HAVE_WEAK_SYMBOLS +# include <threads.h> +# pragma weak thrd_exit +# define c11_threads_in_use() (thrd_exit != NULL) +# else +# define c11_threads_in_use() 0 +# endif + +# elif HAVE_THREADS_H + +# include <threads.h> + +# endif + # include "verify.h" +# error #include "lc-charset-dispatch.h" +# error #include "mbtowc-lock.h" # ifndef FALLTHROUGH # if __GNUC__ < 7 @@ -43,342 +62,24 @@ # endif # endif -/* Returns a classification of special values of the encoding of the current - locale. */ -typedef enum { - enc_other, /* other */ - enc_utf8, /* UTF-8 */ - enc_eucjp, /* EUC-JP */ - enc_94, /* EUC-KR, GB2312, BIG5 */ - enc_euctw, /* EUC-TW */ - enc_gb18030, /* GB18030 */ - enc_sjis /* SJIS */ -} enc_t; -static inline enc_t -locale_enc (void) -{ - const char *encoding = locale_charset (); - if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0)) - return enc_utf8; - if (STREQ_OPT (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)) - return enc_eucjp; - if (STREQ_OPT (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) - || STREQ_OPT (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0) - || STREQ_OPT (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)) - return enc_94; - if (STREQ_OPT (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)) - return enc_euctw; - if (STREQ_OPT (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0)) - return enc_gb18030; - if (STREQ_OPT (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0)) - return enc_sjis; - return enc_other; -} - -#if GNULIB_WCHAR_SINGLE -/* When we know that the locale does not change, provide a speedup by - caching the value of locale_enc. */ -static int cached_locale_enc = -1; -static inline enc_t -locale_enc_cached (void) -{ - if (cached_locale_enc < 0) - cached_locale_enc = locale_enc (); - return cached_locale_enc; -} -#else -/* By default, don't make assumptions, hence no caching. */ -# define locale_enc_cached locale_enc -#endif - verify (sizeof (mbstate_t) >= 4); - static char internal_state[4]; size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) { - char *pstate = (char *)ps; - - if (s == NULL) - { - pwc = NULL; - s = ""; - n = 1; - } - - if (n == 0) - return (size_t)(-2); - - /* Here n > 0. */ - - if (pstate == NULL) - pstate = internal_state; - - { - size_t nstate = pstate[0]; - char buf[4]; - const char *p; - size_t m; - - switch (nstate) - { - case 0: - p = s; - m = n; - break; - case 3: - buf[2] = pstate[3]; - FALLTHROUGH; - case 2: - buf[1] = pstate[2]; - FALLTHROUGH; - case 1: - buf[0] = pstate[1]; - p = buf; - m = nstate; - buf[m++] = s[0]; - if (n >= 2 && m < 4) - { - buf[m++] = s[1]; - if (n >= 3 && m < 4) - buf[m++] = s[2]; - } - break; - default: - errno = EINVAL; - return (size_t)(-1); - } - - /* Here m > 0. */ - -# if __GLIBC__ || defined __UCLIBC__ - /* Work around bug <https://sourceware.org/bugzilla/show_bug.cgi?id=9674> */ - mbtowc (NULL, NULL, 0); -# endif - { - int res = mbtowc (pwc, p, m); - - if (res >= 0) - { - if (pwc != NULL && ((*pwc == 0) != (res == 0))) - abort (); - if (nstate >= (res > 0 ? res : 1)) - abort (); - res -= nstate; - pstate[0] = 0; - return res; - } - - /* mbtowc does not distinguish between invalid and incomplete multibyte - sequences. But mbrtowc needs to make this distinction. - There are two possible approaches: - - Use iconv() and its return value. - - Use built-in knowledge about the possible encodings. - Given the low quality of implementation of iconv() on the systems that - lack mbrtowc(), we use the second approach. - The possible encodings are: - - 8-bit encodings, - - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS, - - UTF-8. - Use specialized code for each. */ - if (m >= 4 || m >= MB_CUR_MAX) - goto invalid; - /* Here MB_CUR_MAX > 1 and 0 < m < 4. */ - switch (locale_enc_cached ()) - { - case enc_utf8: /* UTF-8 */ - { - /* Cf. unistr/u8-mblen.c. */ - unsigned char c = (unsigned char) p[0]; - - if (c >= 0xc2) - { - if (c < 0xe0) - { - if (m == 1) - goto incomplete; - } - else if (c < 0xf0) - { - if (m == 1) - goto incomplete; - if (m == 2) - { - unsigned char c2 = (unsigned char) p[1]; - - if ((c2 ^ 0x80) < 0x40 - && (c >= 0xe1 || c2 >= 0xa0) - && (c != 0xed || c2 < 0xa0)) - goto incomplete; - } - } - else if (c <= 0xf4) - { - if (m == 1) - goto incomplete; - else /* m == 2 || m == 3 */ - { - unsigned char c2 = (unsigned char) p[1]; - - if ((c2 ^ 0x80) < 0x40 - && (c >= 0xf1 || c2 >= 0x90) - && (c < 0xf4 || (c == 0xf4 && c2 < 0x90))) - { - if (m == 2) - goto incomplete; - else /* m == 3 */ - { - unsigned char c3 = (unsigned char) p[2]; - - if ((c3 ^ 0x80) < 0x40) - goto incomplete; - } - } - } - } - } - goto invalid; - } - - /* As a reference for this code, you can use the GNU libiconv - implementation. Look for uses of the RET_TOOFEW macro. */ - - case enc_eucjp: /* EUC-JP */ - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f) - goto incomplete; - } - if (m == 2) - { - unsigned char c = (unsigned char) p[0]; - - if (c == 0x8f) - { - unsigned char c2 = (unsigned char) p[1]; - - if (c2 >= 0xa1 && c2 < 0xff) - goto incomplete; - } - } - goto invalid; - } - - case enc_94: /* EUC-KR, GB2312, BIG5 */ - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if (c >= 0xa1 && c < 0xff) - goto incomplete; - } - goto invalid; - } - - case enc_euctw: /* EUC-TW */ - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if ((c >= 0xa1 && c < 0xff) || c == 0x8e) - goto incomplete; - } - else /* m == 2 || m == 3 */ - { - unsigned char c = (unsigned char) p[0]; - - if (c == 0x8e) - goto incomplete; - } - goto invalid; - } - - case enc_gb18030: /* GB18030 */ - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe)) - goto incomplete; - } - else /* m == 2 || m == 3 */ - { - unsigned char c = (unsigned char) p[0]; - - if (c >= 0x90 && c <= 0xe3) - { - unsigned char c2 = (unsigned char) p[1]; - - if (c2 >= 0x30 && c2 <= 0x39) - { - if (m == 2) - goto incomplete; - else /* m == 3 */ - { - unsigned char c3 = (unsigned char) p[2]; - - if (c3 >= 0x81 && c3 <= 0xfe) - goto incomplete; - } - } - } - } - goto invalid; - } - - case enc_sjis: /* SJIS */ - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea) - || (c >= 0xf0 && c <= 0xf9)) - goto incomplete; - } - goto invalid; - } - - default: - /* An unknown multibyte encoding. */ - goto incomplete; - } - - incomplete: - { - size_t k = nstate; - /* Here 0 <= k < m < 4. */ - pstate[++k] = s[0]; - if (k < m) - { - pstate[++k] = s[1]; - if (k < m) - pstate[++k] = s[2]; - } - if (k != m) - abort (); - } - pstate[0] = m; - return (size_t)(-2); - - invalid: - errno = EILSEQ; - /* The conversion state is undefined, says POSIX. */ - return (size_t)(-1); - } - } +# define FITS_IN_CHAR_TYPE(wc) ((wc) <= WCHAR_MAX) +# error #include "mbrtowc-impl.h" } #else /* Override the system's mbrtowc() function. */ +# if MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ +# include "hard-locale.h" +# include <locale.h> +# endif + # undef mbrtowc size_t @@ -436,14 +137,20 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) } # endif +# if MBRTOWC_STORES_INCOMPLETE_BUG + ret = mbrtowc (&wc, s, n, ps); + if (ret < (size_t) -2 && pwc != NULL) + *pwc = wc; +# else ret = mbrtowc (pwc, s, n, ps); +# endif # if MBRTOWC_NUL_RETVAL_BUG if (ret < (size_t) -2 && !*pwc) return 0; # endif -# if C_LOCALE_MAYBE_EILSEQ +# if MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ if ((size_t) -2 <= ret && n != 0 && ! hard_locale (LC_CTYPE)) { unsigned char uc = *s; diff --git a/contrib/tools/bison/lib/mbswidth.c b/contrib/tools/bison/lib/mbswidth.c index 408a15e344..a3f2099bee 100644 --- a/contrib/tools/bison/lib/mbswidth.c +++ b/contrib/tools/bison/lib/mbswidth.c @@ -1,5 +1,5 @@ /* Determine the number of screen columns needed for a string. - Copyright (C) 2000-2019 Free Software Foundation, Inc. + Copyright (C) 2000-2020 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 diff --git a/contrib/tools/bison/lib/mbswidth.h b/contrib/tools/bison/lib/mbswidth.h index 2b5c53c372..50ef747da8 100644 --- a/contrib/tools/bison/lib/mbswidth.h +++ b/contrib/tools/bison/lib/mbswidth.h @@ -1,5 +1,5 @@ /* Determine the number of screen columns needed for a string. - Copyright (C) 2000-2004, 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2000-2004, 2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/minmax.h b/contrib/tools/bison/lib/minmax.h index d7f6bea061..b9477767b0 100644 --- a/contrib/tools/bison/lib/minmax.h +++ b/contrib/tools/bison/lib/minmax.h @@ -1,5 +1,5 @@ /* MIN, MAX macros. - Copyright (C) 1995, 1998, 2001, 2003, 2005, 2009-2019 Free Software + Copyright (C) 1995, 1998, 2001, 2003, 2005, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/msvc-inval.c b/contrib/tools/bison/lib/msvc-inval.c index 75b5a070ab..863668889c 100644 --- a/contrib/tools/bison/lib/msvc-inval.c +++ b/contrib/tools/bison/lib/msvc-inval.c @@ -1,5 +1,5 @@ /* Invalid parameter handler for MSVC runtime libraries. - Copyright (C) 2011-2019 Free Software Foundation, Inc. + Copyright (C) 2011-2020 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 diff --git a/contrib/tools/bison/lib/msvc-inval.h b/contrib/tools/bison/lib/msvc-inval.h index e31cf65091..93ee7859ca 100644 --- a/contrib/tools/bison/lib/msvc-inval.h +++ b/contrib/tools/bison/lib/msvc-inval.h @@ -1,5 +1,5 @@ /* Invalid parameter handler for MSVC runtime libraries. - Copyright (C) 2011-2019 Free Software Foundation, Inc. + Copyright (C) 2011-2020 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 @@ -95,7 +95,7 @@ extern void gl_msvc_inval_ensure_handler (void); /* Gnulib can define its own status codes, as described in the page "Raising Software Exceptions" on microsoft.com - <https://msdn.microsoft.com/en-us/library/het71c37.aspx>. + <https://docs.microsoft.com/en-us/cpp/cpp/raising-software-exceptions>. Our status codes are composed of - 0xE0000000, mandatory for all user-defined status codes, - 0x474E550, a API identifier ("GNU"), @@ -106,7 +106,7 @@ extern void gl_msvc_inval_ensure_handler (void); # if defined _MSC_VER /* A compiler that supports __try/__except, as described in the page "try-except statement" on microsoft.com - <https://msdn.microsoft.com/en-us/library/s58ftw19.aspx>. + <https://docs.microsoft.com/en-us/cpp/cpp/try-except-statement>. With __try/__except, we can use the multithread-safe exception handling. */ # ifdef __cplusplus diff --git a/contrib/tools/bison/lib/msvc-nothrow.c b/contrib/tools/bison/lib/msvc-nothrow.c index 49b709ca4a..bf93b88241 100644 --- a/contrib/tools/bison/lib/msvc-nothrow.c +++ b/contrib/tools/bison/lib/msvc-nothrow.c @@ -1,6 +1,6 @@ /* Wrappers that don't throw invalid parameter notifications with MSVC runtime libraries. - Copyright (C) 2011-2019 Free Software Foundation, Inc. + Copyright (C) 2011-2020 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 diff --git a/contrib/tools/bison/lib/msvc-nothrow.h b/contrib/tools/bison/lib/msvc-nothrow.h index 8d3ca7892e..fca541573f 100644 --- a/contrib/tools/bison/lib/msvc-nothrow.h +++ b/contrib/tools/bison/lib/msvc-nothrow.h @@ -1,6 +1,6 @@ /* Wrappers that don't throw invalid parameter notifications with MSVC runtime libraries. - Copyright (C) 2011-2019 Free Software Foundation, Inc. + Copyright (C) 2011-2020 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 diff --git a/contrib/tools/bison/lib/obstack.c b/contrib/tools/bison/lib/obstack.c index 411de47429..780cda7b52 100644 --- a/contrib/tools/bison/lib/obstack.c +++ b/contrib/tools/bison/lib/obstack.c @@ -1,5 +1,5 @@ /* obstack.c - subroutines used implicitly by object stack macros - Copyright (C) 1988-2019 Free Software Foundation, Inc. + Copyright (C) 1988-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or diff --git a/contrib/tools/bison/lib/obstack.h b/contrib/tools/bison/lib/obstack.h index 90ba66004b..3a7beb0ca3 100644 --- a/contrib/tools/bison/lib/obstack.h +++ b/contrib/tools/bison/lib/obstack.h @@ -1,5 +1,5 @@ /* obstack.h - object stack macros - Copyright (C) 1988-2019 Free Software Foundation, Inc. + Copyright (C) 1988-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or diff --git a/contrib/tools/bison/lib/obstack_printf.c b/contrib/tools/bison/lib/obstack_printf.c index 0d59a8bcff..cdb9ecdabe 100644 --- a/contrib/tools/bison/lib/obstack_printf.c +++ b/contrib/tools/bison/lib/obstack_printf.c @@ -1,5 +1,5 @@ /* Formatted output to obstacks. - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 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 diff --git a/contrib/tools/bison/lib/open.c b/contrib/tools/bison/lib/open.c index 655260572d..487194f665 100644 --- a/contrib/tools/bison/lib/open.c +++ b/contrib/tools/bison/lib/open.c @@ -1,5 +1,5 @@ /* Open a descriptor to a file. - Copyright (C) 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2007-2020 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 @@ -92,22 +92,19 @@ open (const char *filename, int flags, ...) #endif #if OPEN_TRAILING_SLASH_BUG - /* If the filename ends in a slash and one of O_CREAT, O_WRONLY, O_RDWR - is specified, then fail. - Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html> - says that - "A pathname that contains at least one non-slash character and that - ends with one or more trailing slashes shall be resolved as if a - single dot character ( '.' ) were appended to the pathname." - and - "The special filename dot shall refer to the directory specified by - its predecessor." + /* Fail if one of O_CREAT, O_WRONLY, O_RDWR is specified and the filename + ends in a slash, as POSIX says such a filename must name a directory + <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>: + "A pathname that contains at least one non-<slash> character and that + ends with one or more trailing <slash> characters shall not be resolved + successfully unless the last pathname component before the trailing + <slash> characters names an existing directory" If the named file already exists as a directory, then - if O_CREAT is specified, open() must fail because of the semantics of O_CREAT, - if O_WRONLY or O_RDWR is specified, open() must fail because POSIX - <http://www.opengroup.org/susv3/functions/open.html> says that it - fails with errno = EISDIR in this case. + <https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html> + says that it fails with errno = EISDIR in this case. If the named file does not exist or does not name a directory, then - if O_CREAT is specified, open() must fail since open() cannot create directories, @@ -171,14 +168,12 @@ open (const char *filename, int flags, ...) #if OPEN_TRAILING_SLASH_BUG /* If the filename ends in a slash and fd does not refer to a directory, then fail. - Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html> - says that - "A pathname that contains at least one non-slash character and that - ends with one or more trailing slashes shall be resolved as if a - single dot character ( '.' ) were appended to the pathname." - and - "The special filename dot shall refer to the directory specified by - its predecessor." + Rationale: POSIX says such a filename must name a directory + <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>: + "A pathname that contains at least one non-<slash> character and that + ends with one or more trailing <slash> characters shall not be resolved + successfully unless the last pathname component before the trailing + <slash> characters names an existing directory" If the named file without the slash is not a directory, open() must fail with ENOTDIR. */ if (fd >= 0) diff --git a/contrib/tools/bison/lib/path-join.c b/contrib/tools/bison/lib/path-join.c index 727874222a..411f331603 100644 --- a/contrib/tools/bison/lib/path-join.c +++ b/contrib/tools/bison/lib/path-join.c @@ -1,5 +1,5 @@ /* Concatenate path components. - Copyright (C) 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2018-2020 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 diff --git a/contrib/tools/bison/lib/path-join.h b/contrib/tools/bison/lib/path-join.h index 0ac7055ff0..c4444a472c 100644 --- a/contrib/tools/bison/lib/path-join.h +++ b/contrib/tools/bison/lib/path-join.h @@ -1,5 +1,5 @@ /* Concatenate path components. - Copyright (C) 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2018-2020 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 diff --git a/contrib/tools/bison/lib/pipe-safer.c b/contrib/tools/bison/lib/pipe-safer.c index 62017397c6..5a597c5270 100644 --- a/contrib/tools/bison/lib/pipe-safer.c +++ b/contrib/tools/bison/lib/pipe-safer.c @@ -1,5 +1,5 @@ /* Invoke pipe, but avoid some glitches. - Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/pipe2-safer.c b/contrib/tools/bison/lib/pipe2-safer.c index 390d96b51c..b644daa38c 100644 --- a/contrib/tools/bison/lib/pipe2-safer.c +++ b/contrib/tools/bison/lib/pipe2-safer.c @@ -1,5 +1,5 @@ /* Invoke pipe2, but avoid some glitches. - Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/pipe2.c b/contrib/tools/bison/lib/pipe2.c index 15a5dec985..591e94db4c 100644 --- a/contrib/tools/bison/lib/pipe2.c +++ b/contrib/tools/bison/lib/pipe2.c @@ -1,5 +1,5 @@ /* Create a pipe, with specific opening flags. - Copyright (C) 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2020 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 @@ -107,7 +107,7 @@ pipe2 (int fd[2], int flags) if (pipe (fd) < 0) return -1; - /* POSIX <http://www.opengroup.org/onlinepubs/9699919799/functions/pipe.html> + /* POSIX <https://pubs.opengroup.org/onlinepubs/9699919799/functions/pipe.html> says that initially, the O_NONBLOCK and FD_CLOEXEC flags are cleared on both fd[0] and fd[1]. */ diff --git a/contrib/tools/bison/lib/platform/win64/sys/ioctl.h b/contrib/tools/bison/lib/platform/win64/sys/ioctl.h new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/contrib/tools/bison/lib/platform/win64/sys/ioctl.h diff --git a/contrib/tools/bison/lib/platform/win64/sys/stat.h b/contrib/tools/bison/lib/platform/win64/sys/stat.h index bf7dc29f6e..7a9004a80d 100644 --- a/contrib/tools/bison/lib/platform/win64/sys/stat.h +++ b/contrib/tools/bison/lib/platform/win64/sys/stat.h @@ -653,8 +653,8 @@ _GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - " #endif -#if 1 -# if 1 +#if 0 +# if 0 # if !(defined __cplusplus && defined GNULIB_NAMESPACE) # undef fstat # define fstat rpl_fstat @@ -665,7 +665,7 @@ _GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf)); _GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf)); # endif _GL_CXXALIASWARN (fstat); -#elif 1 +#elif 0 /* Above, we define stat to _stati64. */ # define fstat _fstati64 #elif defined GNULIB_POSIXCHECK diff --git a/contrib/tools/bison/lib/platform/win64/termios.h b/contrib/tools/bison/lib/platform/win64/termios.h new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/contrib/tools/bison/lib/platform/win64/termios.h diff --git a/contrib/tools/bison/lib/printf-args.c b/contrib/tools/bison/lib/printf-args.c index e45cfbede1..943b77c23c 100644 --- a/contrib/tools/bison/lib/printf-args.c +++ b/contrib/tools/bison/lib/printf-args.c @@ -1,5 +1,5 @@ /* Decomposed printf argument list. - Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2019 Free Software + Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -65,14 +65,12 @@ PRINTF_FETCHARGS (va_list args, arguments *a) case TYPE_ULONGINT: ap->a.a_ulongint = va_arg (args, unsigned long int); break; -#if HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: ap->a.a_longlongint = va_arg (args, long long int); break; case TYPE_ULONGLONGINT: ap->a.a_ulonglongint = va_arg (args, unsigned long long int); break; -#endif case TYPE_DOUBLE: ap->a.a_double = va_arg (args, double); break; @@ -135,11 +133,9 @@ PRINTF_FETCHARGS (va_list args, arguments *a) case TYPE_COUNT_LONGINT_POINTER: ap->a.a_count_longint_pointer = va_arg (args, long int *); break; -#if HAVE_LONG_LONG_INT case TYPE_COUNT_LONGLONGINT_POINTER: ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); break; -#endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ case TYPE_U8_STRING: diff --git a/contrib/tools/bison/lib/printf-args.h b/contrib/tools/bison/lib/printf-args.h index 866cba04d8..781f572382 100644 --- a/contrib/tools/bison/lib/printf-args.h +++ b/contrib/tools/bison/lib/printf-args.h @@ -1,5 +1,5 @@ /* Decomposed printf argument list. - Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2019 Free Software + Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -57,10 +57,8 @@ typedef enum TYPE_UINT, TYPE_LONGINT, TYPE_ULONGINT, -#if HAVE_LONG_LONG_INT TYPE_LONGLONGINT, TYPE_ULONGLONGINT, -#endif TYPE_DOUBLE, TYPE_LONGDOUBLE, TYPE_CHAR, @@ -75,10 +73,8 @@ typedef enum TYPE_COUNT_SCHAR_POINTER, TYPE_COUNT_SHORT_POINTER, TYPE_COUNT_INT_POINTER, - TYPE_COUNT_LONGINT_POINTER -#if HAVE_LONG_LONG_INT -, TYPE_COUNT_LONGLONGINT_POINTER -#endif + TYPE_COUNT_LONGINT_POINTER, + TYPE_COUNT_LONGLONGINT_POINTER #if ENABLE_UNISTDIO /* The unistdio extensions. */ , TYPE_U8_STRING @@ -101,10 +97,8 @@ typedef struct unsigned int a_uint; long int a_longint; unsigned long int a_ulongint; -#if HAVE_LONG_LONG_INT long long int a_longlongint; unsigned long long int a_ulonglongint; -#endif float a_float; double a_double; long double a_longdouble; @@ -121,9 +115,7 @@ typedef struct short * a_count_short_pointer; int * a_count_int_pointer; long int * a_count_longint_pointer; -#if HAVE_LONG_LONG_INT long long int * a_count_longlongint_pointer; -#endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ const uint8_t * a_u8_string; diff --git a/contrib/tools/bison/lib/printf-frexp.c b/contrib/tools/bison/lib/printf-frexp.c index 77eafab544..6e1e647b44 100644 --- a/contrib/tools/bison/lib/printf-frexp.c +++ b/contrib/tools/bison/lib/printf-frexp.c @@ -1,5 +1,5 @@ /* Split a double into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/printf-frexp.h b/contrib/tools/bison/lib/printf-frexp.h index 93107343ad..321ea602dc 100644 --- a/contrib/tools/bison/lib/printf-frexp.h +++ b/contrib/tools/bison/lib/printf-frexp.h @@ -1,5 +1,5 @@ /* Split a double into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/printf-frexpl.c b/contrib/tools/bison/lib/printf-frexpl.c index 693b88976d..7992cbb4b6 100644 --- a/contrib/tools/bison/lib/printf-frexpl.c +++ b/contrib/tools/bison/lib/printf-frexpl.c @@ -1,5 +1,5 @@ /* Split a 'long double' into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/printf-frexpl.h b/contrib/tools/bison/lib/printf-frexpl.h index 2760769442..be729dd45e 100644 --- a/contrib/tools/bison/lib/printf-frexpl.h +++ b/contrib/tools/bison/lib/printf-frexpl.h @@ -1,5 +1,5 @@ /* Split a 'long double' into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/printf-parse.c b/contrib/tools/bison/lib/printf-parse.c index 8596fd5f30..99ddbc37a8 100644 --- a/contrib/tools/bison/lib/printf-parse.c +++ b/contrib/tools/bison/lib/printf-parse.c @@ -1,5 +1,5 @@ /* Formatted output to strings. - Copyright (C) 1999-2000, 2002-2003, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002-2003, 2006-2020 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 @@ -447,14 +447,12 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) switch (c) { case 'd': case 'i': -#if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ + /* If 'long long' is larger than 'long': */ if (flags >= 16 || (flags & 4)) type = TYPE_LONGLONGINT; else -#endif - /* If 'long long' exists and is the same as 'long', we parse - "lld" into TYPE_LONGINT. */ + /* If 'long long' is the same as 'long', we parse "lld" into + TYPE_LONGINT. */ if (flags >= 8) type = TYPE_LONGINT; else if (flags & 2) @@ -465,14 +463,12 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) type = TYPE_INT; break; case 'o': case 'u': case 'x': case 'X': -#if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ + /* If 'unsigned long long' is larger than 'unsigned long': */ if (flags >= 16 || (flags & 4)) type = TYPE_ULONGLONGINT; else -#endif - /* If 'unsigned long long' exists and is the same as - 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ + /* If 'unsigned long long' is the same as 'unsigned long', we + parse "llu" into TYPE_ULONGINT. */ if (flags >= 8) type = TYPE_ULONGINT; else if (flags & 2) @@ -525,14 +521,12 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) type = TYPE_POINTER; break; case 'n': -#if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ + /* If 'long long' is larger than 'long': */ if (flags >= 16 || (flags & 4)) type = TYPE_COUNT_LONGLONGINT_POINTER; else -#endif - /* If 'long long' exists and is the same as 'long', we parse - "lln" into TYPE_COUNT_LONGINT_POINTER. */ + /* If 'long long' is the same as 'long', we parse "lln" into + TYPE_COUNT_LONGINT_POINTER. */ if (flags >= 8) type = TYPE_COUNT_LONGINT_POINTER; else if (flags & 2) diff --git a/contrib/tools/bison/lib/printf-parse.h b/contrib/tools/bison/lib/printf-parse.h index 746bb3fe0f..34b91f4f76 100644 --- a/contrib/tools/bison/lib/printf-parse.h +++ b/contrib/tools/bison/lib/printf-parse.h @@ -1,5 +1,5 @@ /* Parse printf format string. - Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2019 Free Software + Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/progname.c b/contrib/tools/bison/lib/progname.c index a42b7fa2f7..d59d969ba6 100644 --- a/contrib/tools/bison/lib/progname.c +++ b/contrib/tools/bison/lib/progname.c @@ -1,5 +1,5 @@ /* Program name management. - Copyright (C) 2001-2003, 2005-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/progname.h b/contrib/tools/bison/lib/progname.h index c726e97e90..bc276cc8e7 100644 --- a/contrib/tools/bison/lib/progname.h +++ b/contrib/tools/bison/lib/progname.h @@ -1,5 +1,5 @@ /* Program name management. - Copyright (C) 2001-2004, 2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006, 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2001. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/quote.h b/contrib/tools/bison/lib/quote.h index 5cef8ff1e0..391ff1a353 100644 --- a/contrib/tools/bison/lib/quote.h +++ b/contrib/tools/bison/lib/quote.h @@ -1,6 +1,6 @@ /* quote.h - prototypes for quote.c - Copyright (C) 1998-2001, 2003, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1998-2001, 2003, 2009-2020 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 diff --git a/contrib/tools/bison/lib/quotearg.c b/contrib/tools/bison/lib/quotearg.c index 773d53f115..c78fc1670f 100644 --- a/contrib/tools/bison/lib/quotearg.c +++ b/contrib/tools/bison/lib/quotearg.c @@ -1,6 +1,6 @@ /* quotearg.c - quote arguments for output - Copyright (C) 1998-2002, 2004-2019 Free Software Foundation, Inc. + Copyright (C) 1998-2002, 2004-2020 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 diff --git a/contrib/tools/bison/lib/quotearg.h b/contrib/tools/bison/lib/quotearg.h index 0f07e0211e..3bf149b397 100644 --- a/contrib/tools/bison/lib/quotearg.h +++ b/contrib/tools/bison/lib/quotearg.h @@ -1,6 +1,6 @@ /* quotearg.h - quote arguments for output - Copyright (C) 1998-2002, 2004, 2006, 2008-2019 Free Software Foundation, + Copyright (C) 1998-2002, 2004, 2006, 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -323,7 +323,7 @@ void set_custom_quoting (struct quoting_options *o, On output, BUFFER might contain embedded null bytes if ARGSIZE was not -1, the style of O does not use backslash escapes, and the flags of O do not request elision of null bytes.*/ -size_t quotearg_buffer (char *buffer, size_t buffersize, +size_t quotearg_buffer (char *restrict buffer, size_t buffersize, char const *arg, size_t argsize, struct quoting_options const *o); diff --git a/contrib/tools/bison/lib/raise.c b/contrib/tools/bison/lib/raise.c index e750b7a4c6..1b93e529a7 100644 --- a/contrib/tools/bison/lib/raise.c +++ b/contrib/tools/bison/lib/raise.c @@ -1,6 +1,6 @@ /* Provide a non-threads replacement for the POSIX raise function. - Copyright (C) 2002-2003, 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2003, 2005-2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/relocatable.h b/contrib/tools/bison/lib/relocatable.h index 896a7e59c0..ffb8cdb2ec 100644 --- a/contrib/tools/bison/lib/relocatable.h +++ b/contrib/tools/bison/lib/relocatable.h @@ -1,5 +1,5 @@ /* Provide relocatable packages. - Copyright (C) 2003, 2005, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2003, 2005, 2008-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/setlocale_null.c b/contrib/tools/bison/lib/setlocale_null.c new file mode 100644 index 0000000000..64b1cef794 --- /dev/null +++ b/contrib/tools/bison/lib/setlocale_null.c @@ -0,0 +1,413 @@ +/* Query the name of the current global locale. + Copyright (C) 2019-2020 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2019. */ + +#include <config.h> + +/* Specification. */ +#include "setlocale_null.h" + +#include <errno.h> +#include <locale.h> +#include <stdlib.h> +#include <string.h> +#if defined _WIN32 && !defined __CYGWIN__ +# include <wchar.h> +#endif + +#if !(SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE) +# if defined _WIN32 && !defined __CYGWIN__ + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include <windows.h> + +# elif HAVE_PTHREAD_API + +# include <pthread.h> +# if HAVE_THREADS_H && HAVE_WEAK_SYMBOLS +# include <threads.h> +# pragma weak thrd_exit +# define c11_threads_in_use() (thrd_exit != NULL) +# else +# define c11_threads_in_use() 0 +# endif + +# elif HAVE_THREADS_H + +# include <threads.h> + +# endif +#endif + +/* Use the system's setlocale() function, not the gnulib override, here. */ +#undef setlocale + +static const char * +setlocale_null_androidfix (int category) +{ + const char *result = setlocale (category, NULL); + +#ifdef __ANDROID__ + if (result == NULL) + switch (category) + { + case LC_CTYPE: + case LC_NUMERIC: + case LC_TIME: + case LC_COLLATE: + case LC_MONETARY: + case LC_MESSAGES: + case LC_ALL: + case LC_PAPER: + case LC_NAME: + case LC_ADDRESS: + case LC_TELEPHONE: + case LC_MEASUREMENT: + result = "C"; + break; + default: + break; + } +#endif + + return result; +} + +static int +setlocale_null_unlocked (int category, char *buf, size_t bufsize) +{ +#if defined _WIN32 && !defined __CYGWIN__ && defined _MSC_VER + /* On native Windows, nowadays, the setlocale() implementation is based + on _wsetlocale() and uses malloc() for the result. We are better off + using _wsetlocale() directly. */ + const wchar_t *result = _wsetlocale (category, NULL); + + if (result == NULL) + { + /* CATEGORY is invalid. */ + if (bufsize > 0) + /* Return an empty string in BUF. + This is a convenience for callers that don't want to write explicit + code for handling EINVAL. */ + buf[0] = '\0'; + return EINVAL; + } + else + { + size_t length = wcslen (result); + if (length < bufsize) + { + size_t i; + + /* Convert wchar_t[] -> char[], assuming plain ASCII. */ + for (i = 0; i <= length; i++) + buf[i] = result[i]; + + return 0; + } + else + { + if (bufsize > 0) + { + /* Return a truncated result in BUF. + This is a convenience for callers that don't want to write + explicit code for handling ERANGE. */ + size_t i; + + /* Convert wchar_t[] -> char[], assuming plain ASCII. */ + for (i = 0; i < bufsize; i++) + buf[i] = result[i]; + buf[bufsize - 1] = '\0'; + } + return ERANGE; + } + } +#else + const char *result = setlocale_null_androidfix (category); + + if (result == NULL) + { + /* CATEGORY is invalid. */ + if (bufsize > 0) + /* Return an empty string in BUF. + This is a convenience for callers that don't want to write explicit + code for handling EINVAL. */ + buf[0] = '\0'; + return EINVAL; + } + else + { + size_t length = strlen (result); + if (length < bufsize) + { + memcpy (buf, result, length + 1); + return 0; + } + else + { + if (bufsize > 0) + { + /* Return a truncated result in BUF. + This is a convenience for callers that don't want to write + explicit code for handling ERANGE. */ + memcpy (buf, result, bufsize - 1); + buf[bufsize - 1] = '\0'; + } + return ERANGE; + } + } +#endif +} + +#if !(SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE) /* musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin */ + +/* Use a lock, so that no two threads can invoke setlocale_null_unlocked + at the same time. */ + +/* Prohibit renaming this symbol. */ +# undef gl_get_setlocale_null_lock + +# if defined _WIN32 && !defined __CYGWIN__ + +extern __declspec(dllimport) CRITICAL_SECTION *gl_get_setlocale_null_lock (void); + +static int +setlocale_null_with_lock (int category, char *buf, size_t bufsize) +{ + CRITICAL_SECTION *lock = gl_get_setlocale_null_lock (); + int ret; + + EnterCriticalSection (lock); + ret = setlocale_null_unlocked (category, buf, bufsize); + LeaveCriticalSection (lock); + + return ret; +} + +# elif HAVE_PTHREAD_API /* musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin */ + +extern +# if defined _WIN32 || defined __CYGWIN__ + __declspec(dllimport) +# endif + pthread_mutex_t *gl_get_setlocale_null_lock (void); + +# if HAVE_WEAK_SYMBOLS /* musl libc, FreeBSD, NetBSD, OpenBSD, Haiku */ + + /* Avoid the need to link with '-lpthread'. */ +# pragma weak pthread_mutex_lock +# pragma weak pthread_mutex_unlock + + /* Determine whether libpthread is in use. */ +# pragma weak pthread_mutexattr_gettype + /* See the comments in lock.h. */ +# define pthread_in_use() \ + (pthread_mutexattr_gettype != NULL || c11_threads_in_use ()) + +# else +# define pthread_in_use() 1 +# endif + +static int +setlocale_null_with_lock (int category, char *buf, size_t bufsize) +{ + if (pthread_in_use()) + { + pthread_mutex_t *lock = gl_get_setlocale_null_lock (); + int ret; + + if (pthread_mutex_lock (lock)) + abort (); + ret = setlocale_null_unlocked (category, buf, bufsize); + if (pthread_mutex_unlock (lock)) + abort (); + + return ret; + } + else + return setlocale_null_unlocked (category, buf, bufsize); +} + +# elif HAVE_THREADS_H + +extern mtx_t *gl_get_setlocale_null_lock (void); + +static int +setlocale_null_with_lock (int category, char *buf, size_t bufsize) +{ + mtx_t *lock = gl_get_setlocale_null_lock (); + int ret; + + if (mtx_lock (lock) != thrd_success) + abort (); + ret = setlocale_null_unlocked (category, buf, bufsize); + if (mtx_unlock (lock) != thrd_success) + abort (); + + return ret; +} + +# endif + +#endif + +int +setlocale_null_r (int category, char *buf, size_t bufsize) +{ +#if SETLOCALE_NULL_ALL_MTSAFE +# if SETLOCALE_NULL_ONE_MTSAFE + + return setlocale_null_unlocked (category, buf, bufsize); + +# else + + if (category == LC_ALL) + return setlocale_null_unlocked (category, buf, bufsize); + else + return setlocale_null_with_lock (category, buf, bufsize); + +# endif +#else +# if SETLOCALE_NULL_ONE_MTSAFE + + if (category == LC_ALL) + return setlocale_null_with_lock (category, buf, bufsize); + else + return setlocale_null_unlocked (category, buf, bufsize); + +# else + + return setlocale_null_with_lock (category, buf, bufsize); + +# endif +#endif +} + +const char * +setlocale_null (int category) +{ +#if SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE + return setlocale_null_androidfix (category); +#else + + /* This call must be multithread-safe. To achieve this without using + thread-local storage: + 1. We use a specific static buffer for each possible CATEGORY + argument. So that different threads can call setlocale_mtsafe + with different CATEGORY arguments, without interfering. + 2. We use a simple strcpy or memcpy to fill this static buffer. + Filling it through, for example, strcpy + strcat would not be + guaranteed to leave the buffer's contents intact if another thread + is currently accessing it. If necessary, the contents is first + assembled in a stack-allocated buffer. */ + if (category == LC_ALL) + { +# if SETLOCALE_NULL_ALL_MTSAFE + return setlocale_null_androidfix (LC_ALL); +# else + char buf[SETLOCALE_NULL_ALL_MAX]; + static char resultbuf[SETLOCALE_NULL_ALL_MAX]; + + if (setlocale_null_r (LC_ALL, buf, sizeof (buf))) + return "C"; + strcpy (resultbuf, buf); + return resultbuf; +# endif + } + else + { +# if SETLOCALE_NULL_ONE_MTSAFE + return setlocale_null_androidfix (category); +# else + enum + { + LC_CTYPE_INDEX, + LC_NUMERIC_INDEX, + LC_TIME_INDEX, + LC_COLLATE_INDEX, + LC_MONETARY_INDEX, + LC_MESSAGES_INDEX, +# ifdef LC_PAPER + LC_PAPER_INDEX, +# endif +# ifdef LC_NAME + LC_NAME_INDEX, +# endif +# ifdef LC_ADDRESS + LC_ADDRESS_INDEX, +# endif +# ifdef LC_TELEPHONE + LC_TELEPHONE_INDEX, +# endif +# ifdef LC_MEASUREMENT + LC_MEASUREMENT_INDEX, +# endif +# ifdef LC_IDENTIFICATION + LC_IDENTIFICATION_INDEX, +# endif + LC_INDICES_COUNT + } + i; + char buf[SETLOCALE_NULL_MAX]; + static char resultbuf[LC_INDICES_COUNT][SETLOCALE_NULL_MAX]; + int err; + + err = setlocale_null_r (category, buf, sizeof (buf)); + if (err == EINVAL) + return NULL; + if (err) + return "C"; + + switch (category) + { + case LC_CTYPE: i = LC_CTYPE_INDEX; break; + case LC_NUMERIC: i = LC_NUMERIC_INDEX; break; + case LC_TIME: i = LC_TIME_INDEX; break; + case LC_COLLATE: i = LC_COLLATE_INDEX; break; + case LC_MONETARY: i = LC_MONETARY_INDEX; break; +# ifdef LC_MESSAGES + case LC_MESSAGES: i = LC_MESSAGES_INDEX; break; +# endif +# ifdef LC_PAPER + case LC_PAPER: i = LC_PAPER_INDEX; break; +# endif +# ifdef LC_NAME + case LC_NAME: i = LC_NAME_INDEX; break; +# endif +# ifdef LC_ADDRESS + case LC_ADDRESS: i = LC_ADDRESS_INDEX; break; +# endif +# ifdef LC_TELEPHONE + case LC_TELEPHONE: i = LC_TELEPHONE_INDEX; break; +# endif +# ifdef LC_MEASUREMENT + case LC_MEASUREMENT: i = LC_MEASUREMENT_INDEX; break; +# endif +# ifdef LC_IDENTIFICATION + case LC_IDENTIFICATION: i = LC_IDENTIFICATION_INDEX; break; +# endif + default: + /* If you get here, a #ifdef LC_xxx is missing. */ + abort (); + } + + strcpy (resultbuf[i], buf); + return resultbuf[i]; +# endif + } +#endif +} diff --git a/contrib/tools/bison/lib/setlocale_null.h b/contrib/tools/bison/lib/setlocale_null.h new file mode 100644 index 0000000000..6844be5fac --- /dev/null +++ b/contrib/tools/bison/lib/setlocale_null.h @@ -0,0 +1,82 @@ +/* Query the name of the current global locale. + Copyright (C) 2019-2020 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2019. */ + +#ifndef _SETLOCALE_NULL_H +#define _SETLOCALE_NULL_H + +#include <stddef.h> + +#include "arg-nonnull.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Recommended size of a buffer for a locale name for a single category. + On glibc systems, you can have locale names that are relative file names; + assume a maximum length 256. + In native Windows, in 2018 the longest locale name was of length 58 + ("FYRO Macedonian_Former Yugoslav Republic of Macedonia.1251"). */ +#define SETLOCALE_NULL_MAX (256+1) + +/* Recommended size of a buffer for a locale name with all categories. + On glibc systems, you can have locale names that are relative file names; + assume maximum length 256 for each. There are 12 categories; so, the + maximum total length is 148+12*256. + In native Windows, there are 5 categories, and the maximum total length is + 55+5*58. */ +#define SETLOCALE_NULL_ALL_MAX (148+12*256+1) + +/* setlocale_null_r (CATEGORY, BUF, BUFSIZE) is like setlocale (CATEGORY, NULL), + except that + - it is guaranteed to be multithread-safe, + - it returns the resulting locale category name or locale name in the + user-supplied buffer BUF, which must be BUFSIZE bytes long. + The recommended minimum buffer size is + - SETLOCALE_NULL_MAX for CATEGORY != LC_ALL, and + - SETLOCALE_NULL_ALL_MAX for CATEGORY == LC_ALL. + The return value is an error code: 0 if the call is successful, EINVAL if + CATEGORY is invalid, or ERANGE if BUFSIZE is smaller than the length needed + size (including the trailing NUL byte). In the latter case, a truncated + result is returned in BUF, but still NUL-terminated if BUFSIZE > 0. + For this call to be multithread-safe, *all* calls to + setlocale (CATEGORY, NULL) in all other threads must have been converted + to use setlocale_null_r or setlocale_null as well, and the other threads + must not make other setlocale invocations (since changing the global locale + has side effects on all threads). */ +extern int setlocale_null_r (int category, char *buf, size_t bufsize) + _GL_ARG_NONNULL ((2)); + +/* setlocale_null (CATEGORY) is like setlocale (CATEGORY, NULL), except that + it is guaranteed to be multithread-safe. + The return value is NULL if CATEGORY is invalid. + For this call to be multithread-safe, *all* calls to + setlocale (CATEGORY, NULL) in all other threads must have been converted + to use setlocale_null_r or setlocale_null as well, and the other threads + must not make other setlocale invocations (since changing the global locale + has side effects on all threads). */ +extern const char *setlocale_null (int category); + + +#ifdef __cplusplus +} +#endif + +#endif /* _SETLOCALE_NULL_H */ diff --git a/contrib/tools/bison/lib/sig-handler.h b/contrib/tools/bison/lib/sig-handler.h index b289473dbd..17604eada3 100644 --- a/contrib/tools/bison/lib/sig-handler.h +++ b/contrib/tools/bison/lib/sig-handler.h @@ -1,6 +1,6 @@ /* Convenience declarations when working with <signal.h>. - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 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 diff --git a/contrib/tools/bison/lib/sigaction.c b/contrib/tools/bison/lib/sigaction.c index abedfdcdc4..792b3e8dac 100644 --- a/contrib/tools/bison/lib/sigaction.c +++ b/contrib/tools/bison/lib/sigaction.c @@ -1,5 +1,5 @@ /* POSIX compatible signal blocking. - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 Free Software Foundation, Inc. Written by Eric Blake <ebb9@byu.net>, 2008. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/sigprocmask.c b/contrib/tools/bison/lib/sigprocmask.c index d6cd3f82e5..d18610691e 100644 --- a/contrib/tools/bison/lib/sigprocmask.c +++ b/contrib/tools/bison/lib/sigprocmask.c @@ -1,5 +1,5 @@ /* POSIX compatible signal blocking. - Copyright (C) 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2006-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2006. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/spawn-pipe.c b/contrib/tools/bison/lib/spawn-pipe.c index 5fe50fc640..3e5afbef94 100644 --- a/contrib/tools/bison/lib/spawn-pipe.c +++ b/contrib/tools/bison/lib/spawn-pipe.c @@ -1,5 +1,5 @@ /* Creation of subprocesses, communicating via pipes. - Copyright (C) 2001-2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006-2020 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/spawn-pipe.h b/contrib/tools/bison/lib/spawn-pipe.h index 0d70968666..6a95650ee0 100644 --- a/contrib/tools/bison/lib/spawn-pipe.h +++ b/contrib/tools/bison/lib/spawn-pipe.h @@ -1,5 +1,5 @@ /* Creation of subprocesses, communicating via pipes. - Copyright (C) 2001-2003, 2006, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006, 2008-2020 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/stdio-impl.h b/contrib/tools/bison/lib/stdio-impl.h index 4260468b61..067b95ebd6 100644 --- a/contrib/tools/bison/lib/stdio-impl.h +++ b/contrib/tools/bison/lib/stdio-impl.h @@ -1,5 +1,5 @@ /* Implementation details of FILE streams. - Copyright (C) 2007-2008, 2010-2019 Free Software Foundation, Inc. + Copyright (C) 2007-2008, 2010-2020 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 @@ -18,11 +18,16 @@ the same implementation of stdio extension API, except that some fields have different naming conventions, or their access requires some casts. */ -/* Glibc 2.28 made _IO_IN_BACKUP private. For now, work around this - problem by defining it ourselves. FIXME: Do not rely on glibc +/* Glibc 2.28 made _IO_UNBUFFERED and _IO_IN_BACKUP private. For now, work + around this problem by defining them ourselves. FIXME: Do not rely on glibc internals. */ -#if !defined _IO_IN_BACKUP && defined _IO_EOF_SEEN -# define _IO_IN_BACKUP 0x100 +#if defined _IO_EOF_SEEN +# if !defined _IO_UNBUFFERED +# define _IO_UNBUFFERED 0x2 +# endif +# if !defined _IO_IN_BACKUP +# define _IO_IN_BACKUP 0x100 +# endif #endif /* BSD stdio derived implementations. */ diff --git a/contrib/tools/bison/lib/stdio-safer.h b/contrib/tools/bison/lib/stdio-safer.h index 790846c2e7..ce74a93ea3 100644 --- a/contrib/tools/bison/lib/stdio-safer.h +++ b/contrib/tools/bison/lib/stdio-safer.h @@ -1,6 +1,6 @@ /* Invoke stdio functions, but avoid some glitches. - Copyright (C) 2001, 2003, 2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2003, 2006, 2009-2020 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 diff --git a/contrib/tools/bison/lib/stpcpy.c b/contrib/tools/bison/lib/stpcpy.c index a1d32fdaf8..58265f0b79 100644 --- a/contrib/tools/bison/lib/stpcpy.c +++ b/contrib/tools/bison/lib/stpcpy.c @@ -1,5 +1,5 @@ /* stpcpy.c -- copy a string and return pointer to end of new string - Copyright (C) 1992, 1995, 1997-1998, 2006, 2009-2019 Free Software + Copyright (C) 1992, 1995, 1997-1998, 2006, 2009-2020 Free Software Foundation, Inc. NOTE: The canonical source of this file is maintained with the GNU C Library. diff --git a/contrib/tools/bison/lib/streq.h b/contrib/tools/bison/lib/streq.h index 326537b6d0..d06c27200c 100644 --- a/contrib/tools/bison/lib/streq.h +++ b/contrib/tools/bison/lib/streq.h @@ -1,5 +1,5 @@ /* Optimized string comparison. - Copyright (C) 2001-2002, 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/stripslash.c b/contrib/tools/bison/lib/stripslash.c index dfc15b43cc..6818b30614 100644 --- a/contrib/tools/bison/lib/stripslash.c +++ b/contrib/tools/bison/lib/stripslash.c @@ -1,6 +1,6 @@ /* stripslash.c -- remove redundant trailing slashes from a file name - Copyright (C) 1990, 2001, 2003-2006, 2009-2019 Free Software Foundation, + Copyright (C) 1990, 2001, 2003-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/strndup.c b/contrib/tools/bison/lib/strndup.c index 5b74828469..d5294b8852 100644 --- a/contrib/tools/bison/lib/strndup.c +++ b/contrib/tools/bison/lib/strndup.c @@ -1,6 +1,6 @@ /* A replacement function, for systems that lack strndup. - Copyright (C) 1996-1998, 2001-2003, 2005-2007, 2009-2019 Free Software + Copyright (C) 1996-1998, 2001-2003, 2005-2007, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it diff --git a/contrib/tools/bison/lib/strverscmp.c b/contrib/tools/bison/lib/strverscmp.c index bf5ce5086f..2e9284486d 100644 --- a/contrib/tools/bison/lib/strverscmp.c +++ b/contrib/tools/bison/lib/strverscmp.c @@ -1,5 +1,5 @@ /* Compare strings while treating digits characters numerically. - Copyright (C) 1997-2019 Free Software Foundation, Inc. + Copyright (C) 1997-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jean-François Bignolles <bignolle@ecoledoc.ibp.fr>, 1997. @@ -17,10 +17,8 @@ License along with the GNU C Library; if not, see <https://www.gnu.org/licenses/>. */ -#if !_LIBC -# include <config.h> -#endif +#include <stdint.h> #include <string.h> #include <ctype.h> @@ -35,27 +33,25 @@ #define CMP 2 #define LEN 3 -#ifndef weak_alias -# define __strverscmp strverscmp -#endif /* Compare S1 and S2 as strings holding indices/version numbers, returning less than, equal to or greater than zero if S1 is less than, equal to or greater than S2 (for more info, see the texinfo doc). */ +#ifndef weak_alias +#define __strverscmp strverscmp +#endif + int __strverscmp (const char *s1, const char *s2) { const unsigned char *p1 = (const unsigned char *) s1; const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - int state; - int diff; /* Symbol(s) 0 [1-9] others Transition (10) 0 (01) d (00) x */ - static const unsigned char next_state[] = + static const uint_least8_t next_state[] = { /* state x d 0 */ /* S_N */ S_N, S_I, S_Z, @@ -64,7 +60,7 @@ __strverscmp (const char *s1, const char *s2) /* S_Z */ S_N, S_F, S_Z }; - static const signed char result_type[] = + static const int_least8_t result_type[] = { /* state x/x x/d x/0 d/x d/d d/0 0/x 0/d 0/0 */ @@ -77,15 +73,16 @@ __strverscmp (const char *s1, const char *s2) if (p1 == p2) return 0; - c1 = *p1++; - c2 = *p2++; + unsigned char c1 = *p1++; + unsigned char c2 = *p2++; /* Hint: '0' is a digit too. */ - state = S_N + ((c1 == '0') + (isdigit (c1) != 0)); + int state = S_N + ((c1 == '0') + (isdigit (c1) != 0)); + int diff; while ((diff = c1 - c2) == 0) { if (c1 == '\0') - return diff; + return diff; state = next_state[state]; c1 = *p1++; @@ -96,20 +93,20 @@ __strverscmp (const char *s1, const char *s2) state = result_type[state * 3 + (((c2 == '0') + (isdigit (c2) != 0)))]; switch (state) - { + { case CMP: return diff; case LEN: while (isdigit (*p1++)) - if (!isdigit (*p2++)) - return 1; + if (!isdigit (*p2++)) + return 1; return isdigit (*p2) ? -1 : diff; default: return state; - } + } } #ifdef weak_alias libc_hidden_def (__strverscmp) diff --git a/contrib/tools/bison/lib/textstyle.h b/contrib/tools/bison/lib/textstyle.h new file mode 100644 index 0000000000..8cf63c7979 --- /dev/null +++ b/contrib/tools/bison/lib/textstyle.h @@ -0,0 +1,466 @@ +/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ +/* Dummy replacement for part of the public API of the libtextstyle library. + Copyright (C) 2006-2007, 2019-2020 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2019. */ + +/* This file is used as replacement when libtextstyle with its include file + <textstyle.h> is not found. + It supports the essential API and implements it in a way that does not + provide text styling. That is, it produces plain text output via <stdio.h> + FILE objects. + Thus, it allows a package to be build with or without a dependency to + libtextstyle, with very few occurrences of '#if HAVE_LIBTEXTSTYLE'. + + Restriction: + It assumes that freopen() is not being called on stdout and stderr. */ + +#ifndef _TEXTSTYLE_H +#define _TEXTSTYLE_H + +#include <errno.h> +#include <stdarg.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#if HAVE_TCDRAIN +# include <termios.h> +#endif + +/* ----------------------------- From ostream.h ----------------------------- */ + +/* Describes the scope of a flush operation. */ +typedef enum +{ + /* Flushes buffers in this ostream_t. + Use this value if you want to write to the underlying ostream_t. */ + FLUSH_THIS_STREAM = 0, + /* Flushes all buffers in the current process. + Use this value if you want to write to the same target through a + different file descriptor or a FILE stream. */ + FLUSH_THIS_PROCESS = 1, + /* Flushes buffers in the current process and attempts to flush the buffers + in the kernel. + Use this value so that some other process (or the kernel itself) + may write to the same target. */ + FLUSH_ALL = 2 +} ostream_flush_scope_t; + + +/* An output stream is an object to which one can feed a sequence of bytes. */ + +typedef FILE * ostream_t; + +static inline void +ostream_write_mem (ostream_t stream, const void *data, size_t len) +{ + if (len > 0) + fwrite (data, 1, len, stream); +} + +static inline void +ostream_flush (ostream_t stream, ostream_flush_scope_t scope) +{ + fflush (stream); + if (scope == FLUSH_ALL) + { + int fd = fileno (stream); + if (fd >= 0) + { + /* For streams connected to a disk file: */ + fsync (fd); + #if HAVE_TCDRAIN + /* For streams connected to a terminal: */ + { + int retval; + + do + retval = tcdrain (fd); + while (retval < 0 && errno == EINTR); + } + #endif + } + } +} + +static inline void +ostream_free (ostream_t stream) +{ + if (stream == stdin || stream == stderr) + fflush (stream); + else + fclose (stream); +} + +static inline void +ostream_write_str (ostream_t stream, const char *string) +{ + ostream_write_mem (stream, string, strlen (string)); +} + +static inline ptrdiff_t ostream_printf (ostream_t stream, + const char *format, ...) +#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3 + __attribute__ ((__format__ (__printf__, 2, 3))) +#endif + ; +static inline ptrdiff_t +ostream_printf (ostream_t stream, const char *format, ...) +{ + va_list args; + char *temp_string; + ptrdiff_t ret; + + va_start (args, format); + ret = vasprintf (&temp_string, format, args); + va_end (args); + if (ret >= 0) + { + if (ret > 0) + ostream_write_str (stream, temp_string); + free (temp_string); + } + return ret; +} + +static inline ptrdiff_t ostream_vprintf (ostream_t stream, + const char *format, va_list args) +#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3 + __attribute__ ((__format__ (__printf__, 2, 0))) +#endif + ; +static inline ptrdiff_t +ostream_vprintf (ostream_t stream, const char *format, va_list args) +{ + char *temp_string; + ptrdiff_t ret = vasprintf (&temp_string, format, args); + if (ret >= 0) + { + if (ret > 0) + ostream_write_str (stream, temp_string); + free (temp_string); + } + return ret; +} + +/* ------------------------- From styled-ostream.h ------------------------- */ + +typedef ostream_t styled_ostream_t; + +#define styled_ostream_write_mem ostream_write_mem +#define styled_ostream_flush ostream_flush +#define styled_ostream_free ostream_free + +static inline void +styled_ostream_begin_use_class (styled_ostream_t stream _GL_UNUSED, + const char *classname _GL_UNUSED) +{ +} + +static inline void +styled_ostream_end_use_class (styled_ostream_t stream _GL_UNUSED, + const char *classname _GL_UNUSED) +{ +} + +static inline const char * +styled_ostream_get_hyperlink_ref (styled_ostream_t stream _GL_UNUSED) +{ + return NULL; +} + +static inline const char * +styled_ostream_get_hyperlink_id (styled_ostream_t stream _GL_UNUSED) +{ + return NULL; +} + +static inline void +styled_ostream_set_hyperlink (styled_ostream_t stream _GL_UNUSED, + const char *ref _GL_UNUSED, + const char *id _GL_UNUSED) +{ +} + +static inline void +styled_ostream_flush_to_current_style (styled_ostream_t stream _GL_UNUSED) +{ +} + +/* -------------------------- From file-ostream.h -------------------------- */ + +typedef ostream_t file_ostream_t; + +#define file_ostream_write_mem ostream_write_mem +#define file_ostream_flush ostream_flush +#define file_ostream_free ostream_free + +static inline file_ostream_t +file_ostream_create (FILE *fp) +{ + return fp; +} + +/* --------------------------- From fd-ostream.h --------------------------- */ + +typedef ostream_t fd_ostream_t; + +#define fd_ostream_write_mem ostream_write_mem +#define fd_ostream_flush ostream_flush +#define fd_ostream_free ostream_free + +static inline fd_ostream_t +fd_ostream_create (int fd, const char *filename _GL_UNUSED, + bool buffered _GL_UNUSED) +{ + if (fd == 1) + return stdout; + else if (fd == 2) + return stderr; + else + return fdopen (fd, "w"); +} + +/* -------------------------- From term-ostream.h -------------------------- */ + +typedef int term_color_t; +enum +{ + COLOR_DEFAULT = -1 /* unknown */ +}; + +typedef enum +{ + WEIGHT_NORMAL = 0, + WEIGHT_BOLD, + WEIGHT_DEFAULT = WEIGHT_NORMAL +} term_weight_t; + +typedef enum +{ + POSTURE_NORMAL = 0, + POSTURE_ITALIC, /* same as oblique */ + POSTURE_DEFAULT = POSTURE_NORMAL +} term_posture_t; + +typedef enum +{ + UNDERLINE_OFF = 0, + UNDERLINE_ON, + UNDERLINE_DEFAULT = UNDERLINE_OFF +} term_underline_t; + +typedef ostream_t term_ostream_t; + +#define term_ostream_write_mem ostream_write_mem +#define term_ostream_flush ostream_flush +#define term_ostream_free ostream_free + +static inline term_color_t +term_ostream_get_color (term_ostream_t stream _GL_UNUSED) +{ + return COLOR_DEFAULT; +} + +static inline void +term_ostream_set_color (term_ostream_t stream _GL_UNUSED, + term_color_t color _GL_UNUSED) +{ +} + +static inline term_color_t +term_ostream_get_bgcolor (term_ostream_t stream _GL_UNUSED) +{ + return COLOR_DEFAULT; +} + +static inline void +term_ostream_set_bgcolor (term_ostream_t stream _GL_UNUSED, + term_color_t color _GL_UNUSED) +{ +} + +static inline term_weight_t +term_ostream_get_weight (term_ostream_t stream _GL_UNUSED) +{ + return WEIGHT_DEFAULT; +} + +static inline void +term_ostream_set_weight (term_ostream_t stream _GL_UNUSED, + term_weight_t weight _GL_UNUSED) +{ +} + +static inline term_posture_t +term_ostream_get_posture (term_ostream_t stream _GL_UNUSED) +{ + return POSTURE_DEFAULT; +} + +static inline void +term_ostream_set_posture (term_ostream_t stream _GL_UNUSED, + term_posture_t posture _GL_UNUSED) +{ +} + +static inline term_underline_t +term_ostream_get_underline (term_ostream_t stream _GL_UNUSED) +{ + return UNDERLINE_DEFAULT; +} + +static inline void +term_ostream_set_underline (term_ostream_t stream _GL_UNUSED, + term_underline_t underline _GL_UNUSED) +{ +} + +static inline const char * +term_ostream_get_hyperlink_ref (term_ostream_t stream _GL_UNUSED) +{ + return NULL; +} + +static inline const char * +term_ostream_get_hyperlink_id (term_ostream_t stream _GL_UNUSED) +{ + return NULL; +} + +static inline void +term_ostream_set_hyperlink (term_ostream_t stream _GL_UNUSED, + const char *ref _GL_UNUSED, + const char *id _GL_UNUSED) +{ +} + +static inline void +term_ostream_flush_to_current_style (term_ostream_t stream) +{ + fflush (stream); +} + +typedef enum +{ + TTYCTL_AUTO = 0, /* Automatic best-possible choice. */ + TTYCTL_NONE, /* No control. + Result: Garbled output can occur, and the terminal can + be left in any state when the program is interrupted. */ + TTYCTL_PARTIAL, /* Signal handling. + Result: Garbled output can occur, but the terminal will + be left in the default state when the program is + interrupted. */ + TTYCTL_FULL /* Signal handling and disabling echo and flush-upon-signal. + Result: No garbled output, and the the terminal will + be left in the default state when the program is + interrupted. */ +} ttyctl_t; + +static inline term_ostream_t +term_ostream_create (int fd, const char *filename, + ttyctl_t tty_control _GL_UNUSED) +{ + return fd_ostream_create (fd, filename, true); +} + +/* ----------------------- From term-styled-ostream.h ----------------------- */ + +typedef styled_ostream_t term_styled_ostream_t; + +#define term_styled_ostream_write_mem ostream_write_mem +#define term_styled_ostream_flush ostream_flush +#define term_styled_ostream_free ostream_free +#define term_styled_ostream_begin_use_class styled_ostream_begin_use_class +#define term_styled_ostream_end_use_class styled_ostream_end_use_class +#define term_styled_ostream_get_hyperlink_ref styled_ostream_get_hyperlink_ref +#define term_styled_ostream_get_hyperlink_id styled_ostream_get_hyperlink_id +#define term_styled_ostream_set_hyperlink styled_ostream_set_hyperlink +#define term_styled_ostream_flush_to_current_style styled_ostream_flush_to_current_style + +static inline term_styled_ostream_t +term_styled_ostream_create (int fd, const char *filename, + ttyctl_t tty_control _GL_UNUSED, + const char *css_filename _GL_UNUSED) +{ + return fd_ostream_create (fd, filename, true); +} + +/* ----------------------- From html-styled-ostream.h ----------------------- */ + +typedef styled_ostream_t html_styled_ostream_t; + +static inline html_styled_ostream_t +html_styled_ostream_create (ostream_t destination _GL_UNUSED, + const char *css_filename _GL_UNUSED) +{ + abort (); + return NULL; +} + +/* ------------------------------ From color.h ------------------------------ */ + +#define color_test_mode false + +enum color_option { color_no, color_tty, color_yes, color_html }; +#define color_mode color_no + +#define style_file_name NULL + +static inline bool +handle_color_option (const char *option _GL_UNUSED) +{ + return false; +} + +static inline void +handle_style_option (const char *option _GL_UNUSED) +{ +} + +static inline void +print_color_test (void) +{ + abort (); +} + +static inline void +style_file_prepare (const char *style_file_envvar _GL_UNUSED, + const char *stylesdir_envvar _GL_UNUSED, + const char *stylesdir_after_install _GL_UNUSED, + const char *default_style_file _GL_UNUSED) +{ +} + +/* ------------------------------ From misc.h ------------------------------ */ + +static inline styled_ostream_t +styled_ostream_create (int fd, const char *filename, + ttyctl_t tty_control _GL_UNUSED, + const char *css_filename _GL_UNUSED) +{ + return fd_ostream_create (fd, filename, true); +} + +static inline void +libtextstyle_set_failure_exit_code (int exit_code _GL_UNUSED) +{ +} + +#endif /* _TEXTSTYLE_H */ diff --git a/contrib/tools/bison/lib/timespec.h b/contrib/tools/bison/lib/timespec.h index 26f1bc1a4c..02684ce6ea 100644 --- a/contrib/tools/bison/lib/timespec.h +++ b/contrib/tools/bison/lib/timespec.h @@ -1,6 +1,6 @@ /* timespec -- System time interface - Copyright (C) 2000, 2002, 2004-2005, 2007, 2009-2019 Free Software + Copyright (C) 2000, 2002, 2004-2005, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/timevar.c b/contrib/tools/bison/lib/timevar.c index 0f6fb402e4..6657e97c25 100644 --- a/contrib/tools/bison/lib/timevar.c +++ b/contrib/tools/bison/lib/timevar.c @@ -1,6 +1,6 @@ /* Timing variables for measuring compiler performance. - Copyright (C) 2000, 2002, 2004, 2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2000, 2002, 2004, 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Alex Samuel <samuel@codesourcery.com> @@ -16,7 +16,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include <config.h> diff --git a/contrib/tools/bison/lib/timevar.def b/contrib/tools/bison/lib/timevar.def index 9de9b815a7..6e0d6ff054 100644 --- a/contrib/tools/bison/lib/timevar.def +++ b/contrib/tools/bison/lib/timevar.def @@ -1,7 +1,7 @@ /* This file contains the definitions for timing variables used to -*- C -*- measure run-time performance of the compiler. - Copyright (C) 2002, 2007, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002, 2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Akim Demaille <akim@freefriends.org>. diff --git a/contrib/tools/bison/lib/timevar.h b/contrib/tools/bison/lib/timevar.h index 5d5a279cc5..036be80893 100644 --- a/contrib/tools/bison/lib/timevar.h +++ b/contrib/tools/bison/lib/timevar.h @@ -1,6 +1,6 @@ /* Timing variables for measuring application performance. - Copyright (C) 2000, 2002, 2004, 2009-2015, 2018-2019 Free Software + Copyright (C) 2000, 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Alex Samuel <samuel@codesourcery.com> @@ -16,7 +16,7 @@ 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/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #ifndef _TIMEVAR_H # define _TIMEVAR_H 1 diff --git a/contrib/tools/bison/lib/unistd-safer.h b/contrib/tools/bison/lib/unistd-safer.h index 8eebffcae2..3e83509678 100644 --- a/contrib/tools/bison/lib/unistd-safer.h +++ b/contrib/tools/bison/lib/unistd-safer.h @@ -1,6 +1,6 @@ /* Invoke unistd-like functions, but avoid some glitches. - Copyright (C) 2001, 2003, 2005, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2003, 2005, 2009-2020 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 diff --git a/contrib/tools/bison/lib/unitypes.h b/contrib/tools/bison/lib/unitypes.h index 8ce466142b..b277a0858a 100644 --- a/contrib/tools/bison/lib/unitypes.h +++ b/contrib/tools/bison/lib/unitypes.h @@ -1,6 +1,6 @@ /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ /* Elementary types and macros for the GNU UniString library. - Copyright (C) 2002, 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2006, 2009-2020 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 @@ -44,4 +44,17 @@ typedef uint32_t ucs4_t; # endif #endif +/* Qualifier in a function declaration, that asserts that the caller must + pass a pointer to a different object in the specified pointer argument + than in the other pointer arguments. */ +#ifndef _UC_RESTRICT +# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) +# define _UC_RESTRICT __restrict +# elif 199901L <= __STDC_VERSION__ || defined restrict +# define _UC_RESTRICT restrict +# else +# define _UC_RESTRICT +# endif +#endif + #endif /* _UNITYPES_H */ diff --git a/contrib/tools/bison/lib/uniwidth.h b/contrib/tools/bison/lib/uniwidth.h index cb79a70481..b28898b54f 100644 --- a/contrib/tools/bison/lib/uniwidth.h +++ b/contrib/tools/bison/lib/uniwidth.h @@ -1,6 +1,6 @@ /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ /* Display width functions. - Copyright (C) 2001-2002, 2005, 2007, 2009-2019 Free Software Foundation, + Copyright (C) 2001-2002, 2005, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it diff --git a/contrib/tools/bison/lib/uniwidth/cjk.h b/contrib/tools/bison/lib/uniwidth/cjk.h index 9870422ca6..3dcc7cb856 100644 --- a/contrib/tools/bison/lib/uniwidth/cjk.h +++ b/contrib/tools/bison/lib/uniwidth/cjk.h @@ -1,5 +1,5 @@ /* Test for CJK encoding. - Copyright (C) 2001-2002, 2005-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2005-2007, 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This program is free software: you can redistribute it and/or modify it diff --git a/contrib/tools/bison/lib/uniwidth/width.c b/contrib/tools/bison/lib/uniwidth/width.c index a7f59b18eb..ad92323cce 100644 --- a/contrib/tools/bison/lib/uniwidth/width.c +++ b/contrib/tools/bison/lib/uniwidth/width.c @@ -1,5 +1,5 @@ /* Determine display width of Unicode character. - Copyright (C) 2001-2002, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This program is free software: you can redistribute it and/or modify it diff --git a/contrib/tools/bison/lib/unlocked-io.h b/contrib/tools/bison/lib/unlocked-io.h index ee1c06268f..e7f7199eda 100644 --- a/contrib/tools/bison/lib/unlocked-io.h +++ b/contrib/tools/bison/lib/unlocked-io.h @@ -1,6 +1,6 @@ /* Prefer faster, non-thread-safe stdio functions if available. - Copyright (C) 2001-2004, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2009-2020 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 diff --git a/contrib/tools/bison/lib/vasnprintf.c b/contrib/tools/bison/lib/vasnprintf.c index f1f47f0d21..e3a1e9fa75 100644 --- a/contrib/tools/bison/lib/vasnprintf.c +++ b/contrib/tools/bison/lib/vasnprintf.c @@ -1,5 +1,5 @@ /* vsprintf with automatic memory allocation. - Copyright (C) 1999, 2002-2019 Free Software Foundation, Inc. + Copyright (C) 1999, 2002-2020 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 @@ -1553,16 +1553,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion, switch (conversion) { case 'd': case 'i': case 'u': -# if HAVE_LONG_LONG_INT if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) tmp_length = (unsigned int) (sizeof (unsigned long long) * CHAR_BIT * 0.30103 /* binary -> decimal */ ) + 1; /* turn floor into ceil */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + else if (type == TYPE_LONGINT || type == TYPE_ULONGINT) tmp_length = (unsigned int) (sizeof (unsigned long) * CHAR_BIT * 0.30103 /* binary -> decimal */ @@ -1583,16 +1580,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion, break; case 'o': -# if HAVE_LONG_LONG_INT if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) tmp_length = (unsigned int) (sizeof (unsigned long long) * CHAR_BIT * 0.333334 /* binary -> octal */ ) + 1; /* turn floor into ceil */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + else if (type == TYPE_LONGINT || type == TYPE_ULONGINT) tmp_length = (unsigned int) (sizeof (unsigned long) * CHAR_BIT * 0.333334 /* binary -> octal */ @@ -1611,16 +1605,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion, break; case 'x': case 'X': -# if HAVE_LONG_LONG_INT if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) tmp_length = (unsigned int) (sizeof (unsigned long long) * CHAR_BIT * 0.25 /* binary -> hexadecimal */ ) + 1; /* turn floor into ceil */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + else if (type == TYPE_LONGINT || type == TYPE_ULONGINT) tmp_length = (unsigned int) (sizeof (unsigned long) * CHAR_BIT * 0.25 /* binary -> hexadecimal */ @@ -1939,11 +1930,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, case TYPE_COUNT_LONGINT_POINTER: *a.arg[dp->arg_index].a.a_count_longint_pointer = length; break; -#if HAVE_LONG_LONG_INT case TYPE_COUNT_LONGLONGINT_POINTER: *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; break; -#endif default: abort (); } @@ -4835,17 +4824,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, switch (type) { -#if HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: case TYPE_ULONGLONGINT: -# if defined _WIN32 && ! defined __CYGWIN__ +#if defined _WIN32 && ! defined __CYGWIN__ *fbp++ = 'I'; *fbp++ = '6'; *fbp++ = '4'; break; -# else +#else *fbp++ = 'l'; -# endif #endif FALLTHROUGH; case TYPE_LONGINT: @@ -4917,7 +4904,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, Windows Vista, the use of %n in format strings by default crashes the program. See <https://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and - <https://msdn.microsoft.com/en-us/library/ms175782.aspx> + <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-printf-count-output> So we should avoid %n in this situation. */ fbp[1] = '\0'; # endif @@ -5063,7 +5050,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, SNPRINTF_BUF (arg); } break; -#if HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: { long long int arg = a.arg[dp->arg_index].a.a_longlongint; @@ -5076,7 +5062,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, SNPRINTF_BUF (arg); } break; -#endif case TYPE_DOUBLE: { double arg = a.arg[dp->arg_index].a.a_double; diff --git a/contrib/tools/bison/lib/vasnprintf.h b/contrib/tools/bison/lib/vasnprintf.h index 5b192b21e9..f63399a5e6 100644 --- a/contrib/tools/bison/lib/vasnprintf.h +++ b/contrib/tools/bison/lib/vasnprintf.h @@ -1,5 +1,5 @@ /* vsprintf with automatic memory allocation. - Copyright (C) 2002-2004, 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2004, 2007-2020 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 @@ -67,9 +67,11 @@ extern "C" { # define asnprintf rpl_asnprintf # define vasnprintf rpl_vasnprintf #endif -extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) +extern char * asnprintf (char *restrict resultbuf, size_t *lengthp, + const char *format, ...) _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4)); -extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) +extern char * vasnprintf (char *restrict resultbuf, size_t *lengthp, + const char *format, va_list args) _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0)); #ifdef __cplusplus diff --git a/contrib/tools/bison/lib/vasprintf.c b/contrib/tools/bison/lib/vasprintf.c new file mode 100644 index 0000000000..7bb21dde3b --- /dev/null +++ b/contrib/tools/bison/lib/vasprintf.c @@ -0,0 +1,50 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#ifdef IN_LIBASPRINTF +# include "vasprintf.h" +#else +# include <stdio.h> +#endif + +#include <errno.h> +#include <limits.h> +#include <stdlib.h> + +#include "vasnprintf.h" + +int +vasprintf (char **resultp, const char *format, va_list args) +{ + size_t length; + char *result = vasnprintf (NULL, &length, format, args); + if (result == NULL) + return -1; + + if (length > INT_MAX) + { + free (result); + errno = EOVERFLOW; + return -1; + } + + *resultp = result; + /* Return the number of resulting bytes, excluding the trailing NUL. */ + return length; +} diff --git a/contrib/tools/bison/lib/verify.h b/contrib/tools/bison/lib/verify.h index 6930645a35..d9ab89a570 100644 --- a/contrib/tools/bison/lib/verify.h +++ b/contrib/tools/bison/lib/verify.h @@ -1,6 +1,6 @@ /* Compile-time assert-like macros. - Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2020 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 @@ -21,29 +21,37 @@ #define _GL_VERIFY_H -/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11. - This is supported by GCC 4.6.0 and later, in C mode, and its use - here generates easier-to-read diagnostics when verify (R) fails. +/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert (R, DIAGNOSTIC) + works as per C11. This is supported by GCC 4.6.0 and later, in C + mode. - Define _GL_HAVE_STATIC_ASSERT to 1 if static_assert works as per C++11. - This is supported by GCC 6.1.0 and later, in C++ mode. + Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as + per C2X, and define _GL_HAVE_STATIC_ASSERT1 if static_assert (R) + works as per C++17. This is supported by GCC 9.1 and later. - Use this only with GCC. If we were willing to slow 'configure' - down we could also use it with other compilers, but since this - affects only the quality of diagnostics, why bother? */ -#if (4 < __GNUC__ + (6 <= __GNUC_MINOR__) \ - && (201112L <= __STDC_VERSION__ || !defined __STRICT_ANSI__) \ - && !defined __cplusplus) -# define _GL_HAVE__STATIC_ASSERT 1 -#endif -#if (6 <= __GNUC__) && defined __cplusplus -# define _GL_HAVE_STATIC_ASSERT 1 + Support compilers claiming conformance to the relevant standard, + and also support GCC when not pedantic. If we were willing to slow + 'configure' down we could also use it with other compilers, but + since this affects only the quality of diagnostics, why bother? */ +#ifndef __cplusplus +# if (201112L <= __STDC_VERSION__ \ + || (!defined __STRICT_ANSI__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__))) +# define _GL_HAVE__STATIC_ASSERT 1 +# endif +# if (202000L <= __STDC_VERSION__ \ + || (!defined __STRICT_ANSI__ && 9 <= __GNUC__)) +# define _GL_HAVE__STATIC_ASSERT1 1 +# endif +#else +# if 201703L <= __cplusplus || 9 <= __GNUC__ +# define _GL_HAVE_STATIC_ASSERT1 1 +# endif #endif /* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other system headers, defines a conflicting _Static_assert that is no better than ours; override it. */ -#ifndef _GL_HAVE_STATIC_ASSERT +#ifndef _GL_HAVE__STATIC_ASSERT # include <stddef.h> # undef _Static_assert #endif @@ -141,9 +149,9 @@ which do not support _Static_assert, also do not warn about the last declaration mentioned above. - * GCC warns if -Wnested-externs is enabled and verify() is used + * GCC warns if -Wnested-externs is enabled and 'verify' is used within a function body; but inside a function, you can always - arrange to use verify_expr() instead. + arrange to use verify_expr instead. * In C++, any struct definition inside sizeof is invalid. Use a template type to work around the problem. */ @@ -195,48 +203,61 @@ template <int w> #endif /* Verify requirement R at compile-time, as a declaration without a - trailing ';'. If R is false, fail at compile-time, preferably - with a diagnostic that includes the string-literal DIAGNOSTIC. + trailing ';'. If R is false, fail at compile-time. + + This macro requires three or more arguments but uses at most the first + two, so that the _Static_assert macro optionally defined below supports + both the C11 two-argument syntax and the C2X one-argument syntax. Unfortunately, unlike C11, this implementation must appear as an ordinary declaration, and cannot appear inside struct { ... }. */ -#ifdef _GL_HAVE__STATIC_ASSERT -# define _GL_VERIFY _Static_assert +#if defined _GL_HAVE__STATIC_ASSERT +# define _GL_VERIFY(R, DIAGNOSTIC, ...) _Static_assert (R, DIAGNOSTIC) #else -# define _GL_VERIFY(R, DIAGNOSTIC) \ +# define _GL_VERIFY(R, DIAGNOSTIC, ...) \ extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ [_GL_VERIFY_TRUE (R, DIAGNOSTIC)] #endif /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ #ifdef _GL_STATIC_ASSERT_H -# if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert -# define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC) +# if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert +# define _Static_assert(...) \ + _GL_VERIFY (__VA_ARGS__, "static assertion failed", -) # endif -# if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert +# if !defined _GL_HAVE_STATIC_ASSERT1 && !defined static_assert # define static_assert _Static_assert /* C11 requires this #define. */ # endif #endif /* @assert.h omit start@ */ +#if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__)) +# define _GL_HAS_BUILTIN_TRAP 1 +#elif defined __has_builtin +# define _GL_HAS_BUILTIN_TRAP __has_builtin (__builtin_trap) +#else +# define _GL_HAS_BUILTIN_TRAP 0 +#endif + +#if 4 < __GNUC__ + (5 <= __GNUC_MINOR__) +# define _GL_HAS_BUILTIN_UNREACHABLE 1 +#elif defined __has_builtin +# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable) +#else +# define _GL_HAS_BUILTIN_UNREACHABLE 0 +#endif + /* Each of these macros verifies that its argument R is nonzero. To be portable, R should be an integer constant expression. Unlike assert (R), there is no run-time overhead. There are two macros, since no single macro can be used in all - contexts in C. verify_true (R) is for scalar contexts, including + contexts in C. verify_expr (R, E) is for scalar contexts, including integer constant expression contexts. verify (R) is for declaration contexts, e.g., the top level. */ -/* Verify requirement R at compile-time, as an integer constant expression. - Return 1. This is equivalent to verify_expr (R, 1). - - verify_true is obsolescent; please use verify_expr instead. */ - -#define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")") - /* Verify requirement R at compile-time. Return the value of the expression E. */ @@ -244,31 +265,28 @@ template <int w> (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E)) /* Verify requirement R at compile-time, as a declaration without a - trailing ';'. */ + trailing ';'. verify (R) acts like static_assert (R) except that + it is portable to C11/C++14 and earlier, it can issue better + diagnostics, and its name is shorter and may be more convenient. */ -#ifdef __GNUC__ -# define verify(R) _GL_VERIFY (R, "verify (" #R ")") +#ifdef __PGI +/* PGI barfs if R is long. */ +# define verify(R) _GL_VERIFY (R, "verify (...)", -) #else -/* PGI barfs if R is long. Play it safe. */ -# define verify(R) _GL_VERIFY (R, "verify (...)") -#endif - -#ifndef __has_builtin -# define __has_builtin(x) 0 +# define verify(R) _GL_VERIFY (R, "verify (" #R ")", -) #endif -/* Assume that R always holds. This lets the compiler optimize - accordingly. R should not have side-effects; it may or may not be - evaluated. Behavior is undefined if R is false. */ +/* Assume that R always holds. Behavior is undefined if R is false, + fails to evaluate, or has side effects. Although assuming R can + help a compiler generate better code or diagnostics, performance + can suffer if R uses hard-to-optimize features such as function + calls not inlined by the compiler. */ -#if (__has_builtin (__builtin_unreachable) \ - || 4 < __GNUC__ + (5 <= __GNUC_MINOR__)) +#if _GL_HAS_BUILTIN_UNREACHABLE # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ()) #elif 1200 <= _MSC_VER # define assume(R) __assume (R) -#elif ((defined GCC_LINT || defined lint) \ - && (__has_builtin (__builtin_trap) \ - || 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__)))) +#elif (defined GCC_LINT || defined lint) && _GL_HAS_BUILTIN_TRAP /* Doing it this way helps various packages when configured with --enable-gcc-warnings, which compiles with -Dlint. It's nicer when 'assume' silences warnings even with older GCCs. */ diff --git a/contrib/tools/bison/lib/w32spawn.h b/contrib/tools/bison/lib/w32spawn.h index 941ff1ab2d..a4b3b1e500 100644 --- a/contrib/tools/bison/lib/w32spawn.h +++ b/contrib/tools/bison/lib/w32spawn.h @@ -1,5 +1,5 @@ /* Auxiliary functions for the creation of subprocesses. Native Windows API. - Copyright (C) 2001, 2003-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2003-2020 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/wait-process.c b/contrib/tools/bison/lib/wait-process.c index 84c0e86b1f..58a1e1121d 100644 --- a/contrib/tools/bison/lib/wait-process.c +++ b/contrib/tools/bison/lib/wait-process.c @@ -1,5 +1,5 @@ /* Waiting for a subprocess to finish. - Copyright (C) 2001-2003, 2005-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2020 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software: you can redistribute it and/or modify @@ -80,7 +80,7 @@ static size_t slaves_allocated = SIZEOF (static_slaves); #endif /* The cleanup action. It gets called asynchronously. */ -static void +static _GL_ASYNC_SAFE void cleanup_slaves (void) { for (;;) @@ -102,6 +102,14 @@ cleanup_slaves (void) } } +/* The cleanup action, taking a signal argument. + It gets called asynchronously. */ +static _GL_ASYNC_SAFE void +cleanup_slaves_action (int sig _GL_UNUSED) +{ + cleanup_slaves (); +} + /* Register a subprocess as being a slave process. This means that the subprocess will be terminated when its creator receives a catchable fatal signal or exits normally. Registration ends when wait_subprocess() @@ -113,7 +121,7 @@ register_slave_subprocess (pid_t child) if (!cleanup_slaves_registered) { atexit (cleanup_slaves); - at_fatal_signal (cleanup_slaves); + at_fatal_signal (cleanup_slaves_action); cleanup_slaves_registered = true; } diff --git a/contrib/tools/bison/lib/wait-process.h b/contrib/tools/bison/lib/wait-process.h index 08470fb850..849d5156f9 100644 --- a/contrib/tools/bison/lib/wait-process.h +++ b/contrib/tools/bison/lib/wait-process.h @@ -1,5 +1,5 @@ /* Waiting for a subprocess to finish. - Copyright (C) 2001-2003, 2006, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006, 2008-2020 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/waitpid.c b/contrib/tools/bison/lib/waitpid.c index a9dace628c..2ef76615aa 100644 --- a/contrib/tools/bison/lib/waitpid.c +++ b/contrib/tools/bison/lib/waitpid.c @@ -1,5 +1,5 @@ /* Wait for process state change. - Copyright (C) 2001-2003, 2005-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2020 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 diff --git a/contrib/tools/bison/lib/wcwidth.c b/contrib/tools/bison/lib/wcwidth.c index 1f081ccaa1..6af212b2c2 100644 --- a/contrib/tools/bison/lib/wcwidth.c +++ b/contrib/tools/bison/lib/wcwidth.c @@ -1,5 +1,5 @@ /* Determine the number of screen columns needed for a character. - Copyright (C) 2006-2007, 2010-2019 Free Software Foundation, Inc. + Copyright (C) 2006-2007, 2010-2020 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 diff --git a/contrib/tools/bison/lib/windows-initguard.h b/contrib/tools/bison/lib/windows-initguard.h new file mode 100644 index 0000000000..c4be45a5f8 --- /dev/null +++ b/contrib/tools/bison/lib/windows-initguard.h @@ -0,0 +1,35 @@ +/* Init guards, somewhat like spinlocks (native Windows implementation). + Copyright (C) 2005-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. + Based on GCC's gthr-win32.h. */ + +#ifndef _WINDOWS_INITGUARD_H +#define _WINDOWS_INITGUARD_H + +#define WIN32_LEAN_AND_MEAN /* avoid including junk */ +#include <windows.h> + +typedef struct + { + volatile int done; + volatile LONG started; + } + glwthread_initguard_t; + +#define GLWTHREAD_INITGUARD_INIT { 0, -1 } + +#endif /* _WINDOWS_INITGUARD_H */ diff --git a/contrib/tools/bison/lib/windows-mutex.c b/contrib/tools/bison/lib/windows-mutex.c new file mode 100644 index 0000000000..7eb38a2b1e --- /dev/null +++ b/contrib/tools/bison/lib/windows-mutex.c @@ -0,0 +1,95 @@ +/* Plain mutexes (native Windows implementation). + Copyright (C) 2005-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. + Based on GCC's gthr-win32.h. */ + +#include <config.h> + +/* Specification. */ +#include "windows-mutex.h" + +#include <errno.h> + +void +glwthread_mutex_init (glwthread_mutex_t *mutex) +{ + InitializeCriticalSection (&mutex->lock); + mutex->guard.done = 1; +} + +int +glwthread_mutex_lock (glwthread_mutex_t *mutex) +{ + if (!mutex->guard.done) + { + if (InterlockedIncrement (&mutex->guard.started) == 0) + /* This thread is the first one to need this mutex. Initialize it. */ + glwthread_mutex_init (mutex); + else + { + /* Don't let mutex->guard.started grow and wrap around. */ + InterlockedDecrement (&mutex->guard.started); + /* Yield the CPU while waiting for another thread to finish + initializing this mutex. */ + while (!mutex->guard.done) + Sleep (0); + } + } + EnterCriticalSection (&mutex->lock); + return 0; +} + +int +glwthread_mutex_trylock (glwthread_mutex_t *mutex) +{ + if (!mutex->guard.done) + { + if (InterlockedIncrement (&mutex->guard.started) == 0) + /* This thread is the first one to need this mutex. Initialize it. */ + glwthread_mutex_init (mutex); + else + { + /* Don't let mutex->guard.started grow and wrap around. */ + InterlockedDecrement (&mutex->guard.started); + /* Let another thread finish initializing this mutex, and let it also + lock this mutex. */ + return EBUSY; + } + } + if (!TryEnterCriticalSection (&mutex->lock)) + return EBUSY; + return 0; +} + +int +glwthread_mutex_unlock (glwthread_mutex_t *mutex) +{ + if (!mutex->guard.done) + return EINVAL; + LeaveCriticalSection (&mutex->lock); + return 0; +} + +int +glwthread_mutex_destroy (glwthread_mutex_t *mutex) +{ + if (!mutex->guard.done) + return EINVAL; + DeleteCriticalSection (&mutex->lock); + mutex->guard.done = 0; + return 0; +} diff --git a/contrib/tools/bison/lib/windows-mutex.h b/contrib/tools/bison/lib/windows-mutex.h new file mode 100644 index 0000000000..748b9883db --- /dev/null +++ b/contrib/tools/bison/lib/windows-mutex.h @@ -0,0 +1,51 @@ +/* Plain mutexes (native Windows implementation). + Copyright (C) 2005-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. + Based on GCC's gthr-win32.h. */ + +#ifndef _WINDOWS_MUTEX_H +#define _WINDOWS_MUTEX_H + +#define WIN32_LEAN_AND_MEAN /* avoid including junk */ +#include <windows.h> + +#include "windows-initguard.h" + +typedef struct + { + glwthread_initguard_t guard; /* protects the initialization */ + CRITICAL_SECTION lock; + } + glwthread_mutex_t; + +#define GLWTHREAD_MUTEX_INIT { GLWTHREAD_INITGUARD_INIT } + +#ifdef __cplusplus +extern "C" { +#endif + +extern void glwthread_mutex_init (glwthread_mutex_t *mutex); +extern int glwthread_mutex_lock (glwthread_mutex_t *mutex); +extern int glwthread_mutex_trylock (glwthread_mutex_t *mutex); +extern int glwthread_mutex_unlock (glwthread_mutex_t *mutex); +extern int glwthread_mutex_destroy (glwthread_mutex_t *mutex); + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS_MUTEX_H */ diff --git a/contrib/tools/bison/lib/windows-once.c b/contrib/tools/bison/lib/windows-once.c new file mode 100644 index 0000000000..c431bd6707 --- /dev/null +++ b/contrib/tools/bison/lib/windows-once.c @@ -0,0 +1,62 @@ +/* Once-only control (native Windows implementation). + Copyright (C) 2005-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. + Based on GCC's gthr-win32.h. */ + +#include <config.h> + +/* Specification. */ +#include "windows-once.h" + +#include <stdlib.h> + +void +glwthread_once (glwthread_once_t *once_control, void (*initfunction) (void)) +{ + if (once_control->inited <= 0) + { + if (InterlockedIncrement (&once_control->started) == 0) + { + /* This thread is the first one to come to this once_control. */ + InitializeCriticalSection (&once_control->lock); + EnterCriticalSection (&once_control->lock); + once_control->inited = 0; + initfunction (); + once_control->inited = 1; + LeaveCriticalSection (&once_control->lock); + } + else + { + /* Don't let once_control->started grow and wrap around. */ + InterlockedDecrement (&once_control->started); + /* Some other thread has already started the initialization. + Yield the CPU while waiting for the other thread to finish + initializing and taking the lock. */ + while (once_control->inited < 0) + Sleep (0); + if (once_control->inited <= 0) + { + /* Take the lock. This blocks until the other thread has + finished calling the initfunction. */ + EnterCriticalSection (&once_control->lock); + LeaveCriticalSection (&once_control->lock); + if (!(once_control->inited > 0)) + abort (); + } + } + } +} diff --git a/contrib/tools/bison/lib/windows-once.h b/contrib/tools/bison/lib/windows-once.h new file mode 100644 index 0000000000..d31717e861 --- /dev/null +++ b/contrib/tools/bison/lib/windows-once.h @@ -0,0 +1,47 @@ +/* Once-only control (native Windows implementation). + Copyright (C) 2005-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. + Based on GCC's gthr-win32.h. */ + +#ifndef _WINDOWS_ONCE_H +#define _WINDOWS_ONCE_H + +#define WIN32_LEAN_AND_MEAN /* avoid including junk */ +#include <windows.h> + +typedef struct + { + volatile int inited; + volatile LONG started; + CRITICAL_SECTION lock; + } + glwthread_once_t; + +#define GLWTHREAD_ONCE_INIT { -1, -1 } + +#ifdef __cplusplus +extern "C" { +#endif + +extern void glwthread_once (glwthread_once_t *once_control, + void (*initfunction) (void)); + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS_ONCE_H */ diff --git a/contrib/tools/bison/lib/windows-recmutex.c b/contrib/tools/bison/lib/windows-recmutex.c new file mode 100644 index 0000000000..db3c40c442 --- /dev/null +++ b/contrib/tools/bison/lib/windows-recmutex.c @@ -0,0 +1,127 @@ +/* Plain recursive mutexes (native Windows implementation). + Copyright (C) 2005-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. + Based on GCC's gthr-win32.h. */ + +#include <config.h> + +/* Specification. */ +#include "windows-recmutex.h" + +#include <errno.h> + +void +glwthread_recmutex_init (glwthread_recmutex_t *mutex) +{ + mutex->owner = 0; + mutex->depth = 0; + InitializeCriticalSection (&mutex->lock); + mutex->guard.done = 1; +} + +int +glwthread_recmutex_lock (glwthread_recmutex_t *mutex) +{ + if (!mutex->guard.done) + { + if (InterlockedIncrement (&mutex->guard.started) == 0) + /* This thread is the first one to need this mutex. Initialize it. */ + glwthread_recmutex_init (mutex); + else + { + /* Don't let mutex->guard.started grow and wrap around. */ + InterlockedDecrement (&mutex->guard.started); + /* Yield the CPU while waiting for another thread to finish + initializing this mutex. */ + while (!mutex->guard.done) + Sleep (0); + } + } + { + DWORD self = GetCurrentThreadId (); + if (mutex->owner != self) + { + EnterCriticalSection (&mutex->lock); + mutex->owner = self; + } + if (++(mutex->depth) == 0) /* wraparound? */ + { + mutex->depth--; + return EAGAIN; + } + } + return 0; +} + +int +glwthread_recmutex_trylock (glwthread_recmutex_t *mutex) +{ + if (!mutex->guard.done) + { + if (InterlockedIncrement (&mutex->guard.started) == 0) + /* This thread is the first one to need this mutex. Initialize it. */ + glwthread_recmutex_init (mutex); + else + { + /* Don't let mutex->guard.started grow and wrap around. */ + InterlockedDecrement (&mutex->guard.started); + /* Let another thread finish initializing this mutex, and let it also + lock this mutex. */ + return EBUSY; + } + } + { + DWORD self = GetCurrentThreadId (); + if (mutex->owner != self) + { + if (!TryEnterCriticalSection (&mutex->lock)) + return EBUSY; + mutex->owner = self; + } + if (++(mutex->depth) == 0) /* wraparound? */ + { + mutex->depth--; + return EAGAIN; + } + } + return 0; +} + +int +glwthread_recmutex_unlock (glwthread_recmutex_t *mutex) +{ + if (mutex->owner != GetCurrentThreadId ()) + return EPERM; + if (mutex->depth == 0) + return EINVAL; + if (--(mutex->depth) == 0) + { + mutex->owner = 0; + LeaveCriticalSection (&mutex->lock); + } + return 0; +} + +int +glwthread_recmutex_destroy (glwthread_recmutex_t *mutex) +{ + if (mutex->owner != 0) + return EBUSY; + DeleteCriticalSection (&mutex->lock); + mutex->guard.done = 0; + return 0; +} diff --git a/contrib/tools/bison/lib/windows-recmutex.h b/contrib/tools/bison/lib/windows-recmutex.h new file mode 100644 index 0000000000..3b315e5ce9 --- /dev/null +++ b/contrib/tools/bison/lib/windows-recmutex.h @@ -0,0 +1,57 @@ +/* Plain recursive mutexes (native Windows implementation). + Copyright (C) 2005-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. + Based on GCC's gthr-win32.h. */ + +#ifndef _WINDOWS_RECMUTEX_H +#define _WINDOWS_RECMUTEX_H + +#define WIN32_LEAN_AND_MEAN /* avoid including junk */ +#include <windows.h> + +#include "windows-initguard.h" + +/* The native Windows documentation says that CRITICAL_SECTION already + implements a recursive lock. But we need not rely on it: It's easy to + implement a recursive lock without this assumption. */ + +typedef struct + { + glwthread_initguard_t guard; /* protects the initialization */ + DWORD owner; + unsigned long depth; + CRITICAL_SECTION lock; + } + glwthread_recmutex_t; + +#define GLWTHREAD_RECMUTEX_INIT { GLWTHREAD_INITGUARD_INIT, 0, 0 } + +#ifdef __cplusplus +extern "C" { +#endif + +extern void glwthread_recmutex_init (glwthread_recmutex_t *mutex); +extern int glwthread_recmutex_lock (glwthread_recmutex_t *mutex); +extern int glwthread_recmutex_trylock (glwthread_recmutex_t *mutex); +extern int glwthread_recmutex_unlock (glwthread_recmutex_t *mutex); +extern int glwthread_recmutex_destroy (glwthread_recmutex_t *mutex); + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS_RECMUTEX_H */ diff --git a/contrib/tools/bison/lib/windows-rwlock.c b/contrib/tools/bison/lib/windows-rwlock.c new file mode 100644 index 0000000000..aafc5ddda3 --- /dev/null +++ b/contrib/tools/bison/lib/windows-rwlock.c @@ -0,0 +1,373 @@ +/* Read-write locks (native Windows implementation). + Copyright (C) 2005-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. + Based on GCC's gthr-win32.h. */ + +#include <config.h> + +/* Specification. */ +#include "windows-rwlock.h" + +#include <errno.h> +#include <stdlib.h> + +/* In this file, the waitqueues are implemented as circular arrays. */ +#define glwthread_waitqueue_t glwthread_carray_waitqueue_t + +static void +glwthread_waitqueue_init (glwthread_waitqueue_t *wq) +{ + wq->array = NULL; + wq->count = 0; + wq->alloc = 0; + wq->offset = 0; +} + +/* Enqueues the current thread, represented by an event, in a wait queue. + Returns INVALID_HANDLE_VALUE if an allocation failure occurs. */ +static HANDLE +glwthread_waitqueue_add (glwthread_waitqueue_t *wq) +{ + HANDLE event; + unsigned int index; + + if (wq->count == wq->alloc) + { + unsigned int new_alloc = 2 * wq->alloc + 1; + HANDLE *new_array = + (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE)); + if (new_array == NULL) + /* No more memory. */ + return INVALID_HANDLE_VALUE; + /* Now is a good opportunity to rotate the array so that its contents + starts at offset 0. */ + if (wq->offset > 0) + { + unsigned int old_count = wq->count; + unsigned int old_alloc = wq->alloc; + unsigned int old_offset = wq->offset; + unsigned int i; + if (old_offset + old_count > old_alloc) + { + unsigned int limit = old_offset + old_count - old_alloc; + for (i = 0; i < limit; i++) + new_array[old_alloc + i] = new_array[i]; + } + for (i = 0; i < old_count; i++) + new_array[i] = new_array[old_offset + i]; + wq->offset = 0; + } + wq->array = new_array; + wq->alloc = new_alloc; + } + /* Whether the created event is a manual-reset one or an auto-reset one, + does not matter, since we will wait on it only once. */ + event = CreateEvent (NULL, TRUE, FALSE, NULL); + if (event == INVALID_HANDLE_VALUE) + /* No way to allocate an event. */ + return INVALID_HANDLE_VALUE; + index = wq->offset + wq->count; + if (index >= wq->alloc) + index -= wq->alloc; + wq->array[index] = event; + wq->count++; + return event; +} + +/* Notifies the first thread from a wait queue and dequeues it. */ +static void +glwthread_waitqueue_notify_first (glwthread_waitqueue_t *wq) +{ + SetEvent (wq->array[wq->offset + 0]); + wq->offset++; + wq->count--; + if (wq->count == 0 || wq->offset == wq->alloc) + wq->offset = 0; +} + +/* Notifies all threads from a wait queue and dequeues them all. */ +static void +glwthread_waitqueue_notify_all (glwthread_waitqueue_t *wq) +{ + unsigned int i; + + for (i = 0; i < wq->count; i++) + { + unsigned int index = wq->offset + i; + if (index >= wq->alloc) + index -= wq->alloc; + SetEvent (wq->array[index]); + } + wq->count = 0; + wq->offset = 0; +} + +void +glwthread_rwlock_init (glwthread_rwlock_t *lock) +{ + InitializeCriticalSection (&lock->lock); + glwthread_waitqueue_init (&lock->waiting_readers); + glwthread_waitqueue_init (&lock->waiting_writers); + lock->runcount = 0; + lock->guard.done = 1; +} + +int +glwthread_rwlock_rdlock (glwthread_rwlock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glwthread_rwlock_init (lock); + else + { + /* Don't let lock->guard.started grow and wrap around. */ + InterlockedDecrement (&lock->guard.started); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + } + EnterCriticalSection (&lock->lock); + /* Test whether only readers are currently running, and whether the runcount + field will not overflow, and whether no writer is waiting. The latter + condition is because POSIX recommends that "write locks shall take + precedence over read locks", to avoid "writer starvation". */ + if (!(lock->runcount + 1 > 0 && lock->waiting_writers.count == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_readers. */ + HANDLE event = glwthread_waitqueue_add (&lock->waiting_readers); + if (event != INVALID_HANDLE_VALUE) + { + DWORD result; + LeaveCriticalSection (&lock->lock); + /* Wait until another thread signals this event. */ + result = WaitForSingleObject (event, INFINITE); + if (result == WAIT_FAILED || result == WAIT_TIMEOUT) + abort (); + CloseHandle (event); + /* The thread which signalled the event already did the bookkeeping: + removed us from the waiting_readers, incremented lock->runcount. */ + if (!(lock->runcount > 0)) + abort (); + return 0; + } + else + { + /* Allocation failure. Weird. */ + do + { + LeaveCriticalSection (&lock->lock); + Sleep (1); + EnterCriticalSection (&lock->lock); + } + while (!(lock->runcount + 1 > 0)); + } + } + lock->runcount++; + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glwthread_rwlock_wrlock (glwthread_rwlock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glwthread_rwlock_init (lock); + else + { + /* Don't let lock->guard.started grow and wrap around. */ + InterlockedDecrement (&lock->guard.started); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + } + EnterCriticalSection (&lock->lock); + /* Test whether no readers or writers are currently running. */ + if (!(lock->runcount == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_writers. */ + HANDLE event = glwthread_waitqueue_add (&lock->waiting_writers); + if (event != INVALID_HANDLE_VALUE) + { + DWORD result; + LeaveCriticalSection (&lock->lock); + /* Wait until another thread signals this event. */ + result = WaitForSingleObject (event, INFINITE); + if (result == WAIT_FAILED || result == WAIT_TIMEOUT) + abort (); + CloseHandle (event); + /* The thread which signalled the event already did the bookkeeping: + removed us from the waiting_writers, set lock->runcount = -1. */ + if (!(lock->runcount == -1)) + abort (); + return 0; + } + else + { + /* Allocation failure. Weird. */ + do + { + LeaveCriticalSection (&lock->lock); + Sleep (1); + EnterCriticalSection (&lock->lock); + } + while (!(lock->runcount == 0)); + } + } + lock->runcount--; /* runcount becomes -1 */ + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glwthread_rwlock_tryrdlock (glwthread_rwlock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glwthread_rwlock_init (lock); + else + { + /* Don't let lock->guard.started grow and wrap around. */ + InterlockedDecrement (&lock->guard.started); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + } + /* It's OK to wait for this critical section, because it is never taken for a + long time. */ + EnterCriticalSection (&lock->lock); + /* Test whether only readers are currently running, and whether the runcount + field will not overflow, and whether no writer is waiting. The latter + condition is because POSIX recommends that "write locks shall take + precedence over read locks", to avoid "writer starvation". */ + if (!(lock->runcount + 1 > 0 && lock->waiting_writers.count == 0)) + { + /* This thread would have to wait for a while. Return instead. */ + LeaveCriticalSection (&lock->lock); + return EBUSY; + } + lock->runcount++; + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glwthread_rwlock_trywrlock (glwthread_rwlock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glwthread_rwlock_init (lock); + else + { + /* Don't let lock->guard.started grow and wrap around. */ + InterlockedDecrement (&lock->guard.started); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + } + /* It's OK to wait for this critical section, because it is never taken for a + long time. */ + EnterCriticalSection (&lock->lock); + /* Test whether no readers or writers are currently running. */ + if (!(lock->runcount == 0)) + { + /* This thread would have to wait for a while. Return instead. */ + LeaveCriticalSection (&lock->lock); + return EBUSY; + } + lock->runcount--; /* runcount becomes -1 */ + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glwthread_rwlock_unlock (glwthread_rwlock_t *lock) +{ + if (!lock->guard.done) + return EINVAL; + EnterCriticalSection (&lock->lock); + if (lock->runcount < 0) + { + /* Drop a writer lock. */ + if (!(lock->runcount == -1)) + abort (); + lock->runcount = 0; + } + else + { + /* Drop a reader lock. */ + if (!(lock->runcount > 0)) + { + LeaveCriticalSection (&lock->lock); + return EPERM; + } + lock->runcount--; + } + if (lock->runcount == 0) + { + /* POSIX recommends that "write locks shall take precedence over read + locks", to avoid "writer starvation". */ + if (lock->waiting_writers.count > 0) + { + /* Wake up one of the waiting writers. */ + lock->runcount--; + glwthread_waitqueue_notify_first (&lock->waiting_writers); + } + else + { + /* Wake up all waiting readers. */ + lock->runcount += lock->waiting_readers.count; + glwthread_waitqueue_notify_all (&lock->waiting_readers); + } + } + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glwthread_rwlock_destroy (glwthread_rwlock_t *lock) +{ + if (!lock->guard.done) + return EINVAL; + if (lock->runcount != 0) + return EBUSY; + DeleteCriticalSection (&lock->lock); + if (lock->waiting_readers.array != NULL) + free (lock->waiting_readers.array); + if (lock->waiting_writers.array != NULL) + free (lock->waiting_writers.array); + lock->guard.done = 0; + return 0; +} diff --git a/contrib/tools/bison/lib/windows-rwlock.h b/contrib/tools/bison/lib/windows-rwlock.h new file mode 100644 index 0000000000..ae5b82f527 --- /dev/null +++ b/contrib/tools/bison/lib/windows-rwlock.h @@ -0,0 +1,68 @@ +/* Read-write locks (native Windows implementation). + Copyright (C) 2005-2020 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, 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. + Based on GCC's gthr-win32.h. */ + +#ifndef _WINDOWS_RWLOCK_H +#define _WINDOWS_RWLOCK_H + +#define WIN32_LEAN_AND_MEAN /* avoid including junk */ +#include <windows.h> + +#include "windows-initguard.h" + +/* It is impossible to implement read-write locks using plain locks, without + introducing an extra thread dedicated to managing read-write locks. + Therefore here we need to use the low-level Event type. */ + +typedef struct + { + HANDLE *array; /* array of waiting threads, each represented by an event */ + unsigned int count; /* number of waiting threads */ + unsigned int alloc; /* length of allocated array */ + unsigned int offset; /* index of first waiting thread in array */ + } + glwthread_carray_waitqueue_t; +typedef struct + { + glwthread_initguard_t guard; /* protects the initialization */ + CRITICAL_SECTION lock; /* protects the remaining fields */ + glwthread_carray_waitqueue_t waiting_readers; /* waiting readers */ + glwthread_carray_waitqueue_t waiting_writers; /* waiting writers */ + int runcount; /* number of readers running, or -1 when a writer runs */ + } + glwthread_rwlock_t; + +#define GLWTHREAD_RWLOCK_INIT { GLWTHREAD_INITGUARD_INIT } + +#ifdef __cplusplus +extern "C" { +#endif + +extern void glwthread_rwlock_init (glwthread_rwlock_t *lock); +extern int glwthread_rwlock_rdlock (glwthread_rwlock_t *lock); +extern int glwthread_rwlock_wrlock (glwthread_rwlock_t *lock); +extern int glwthread_rwlock_tryrdlock (glwthread_rwlock_t *lock); +extern int glwthread_rwlock_trywrlock (glwthread_rwlock_t *lock); +extern int glwthread_rwlock_unlock (glwthread_rwlock_t *lock); +extern int glwthread_rwlock_destroy (glwthread_rwlock_t *lock); + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS_RWLOCK_H */ diff --git a/contrib/tools/bison/lib/windows-tls.c b/contrib/tools/bison/lib/windows-tls.c new file mode 100644 index 0000000000..d52515c958 --- /dev/null +++ b/contrib/tools/bison/lib/windows-tls.c @@ -0,0 +1,339 @@ +/* Thread-local storage (native Windows implementation). + Copyright (C) 2005-2020 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. */ + +#include <config.h> + +/* Specification. */ +#include "windows-tls.h" + +#include <errno.h> +#include <limits.h> +#include <stdlib.h> + +#include "windows-once.h" + +void * +glwthread_tls_get (glwthread_tls_key_t key) +{ + return TlsGetValue (key); +} + +int +glwthread_tls_set (glwthread_tls_key_t key, void *value) +{ + if (!TlsSetValue (key, value)) + return EINVAL; + return 0; +} + +/* The following variables keep track of TLS keys with non-NULL destructor. */ + +static glwthread_once_t dtor_table_init_once = GLWTHREAD_ONCE_INIT; + +static CRITICAL_SECTION dtor_table_lock; + +struct dtor { glwthread_tls_key_t key; void (*destructor) (void *); }; + +/* The table of dtors. */ +static struct dtor *dtor_table; +/* Number of active entries in the dtor_table. */ +static unsigned int dtors_count; +/* Valid indices into dtor_table are 0..dtors_used-1. */ +static unsigned int dtors_used; +/* Allocation size of dtor_table. */ +static unsigned int dtors_allocated; +/* Invariant: 0 <= dtors_count <= dtors_used <= dtors_allocated. */ + +/* Number of threads that are currently processing destructors. */ +static unsigned int dtor_processing_threads; + +static void +dtor_table_initialize (void) +{ + InitializeCriticalSection (&dtor_table_lock); + /* The other variables are already initialized to NULL or 0, respectively. */ +} + +static void +dtor_table_ensure_initialized (void) +{ + glwthread_once (&dtor_table_init_once, dtor_table_initialize); +} + +/* Shrinks dtors_used down to dtors_count, by replacing inactive entries + with active ones. */ +static void +dtor_table_shrink_used (void) +{ + unsigned int i = 0; + unsigned int j = dtors_used; + + for (;;) + { + BOOL i_found = FALSE; + BOOL j_found = FALSE; + /* Find the next inactive entry, from the left. */ + for (; i < dtors_count;) + { + if (dtor_table[i].destructor == NULL) + { + i_found = TRUE; + break; + } + i++; + } + + /* Find the next active entry, from the right. */ + for (; j > dtors_count;) + { + j--; + if (dtor_table[j].destructor != NULL) + { + j_found = TRUE; + break; + } + } + + if (i_found != j_found) + /* dtors_count was apparently wrong. */ + abort (); + + if (!i_found) + break; + + /* i_found and j_found are TRUE. Swap the two entries. */ + dtor_table[i] = dtor_table[j]; + + i++; + } + + dtors_used = dtors_count; +} + +void +glwthread_tls_process_destructors (void) +{ + unsigned int repeat; + + dtor_table_ensure_initialized (); + + EnterCriticalSection (&dtor_table_lock); + if (dtor_processing_threads == 0) + { + /* Now it's the appropriate time for shrinking dtors_used. */ + if (dtors_used > dtors_count) + dtor_table_shrink_used (); + } + dtor_processing_threads++; + + for (repeat = GLWTHREAD_DESTRUCTOR_ITERATIONS; repeat > 0; repeat--) + { + unsigned int destructors_run = 0; + + /* Iterate across dtor_table. We don't need to make a copy of dtor_table, + because + * When another thread calls glwthread_tls_key_create with a non-NULL + destructor argument, this will possibly reallocate the dtor_table + array and increase dtors_allocated as well as dtors_used and + dtors_count, but it will not change dtors_used nor the contents of + the first dtors_used entries of dtor_table. + * When another thread calls glwthread_tls_key_delete, this will + possibly set some 'destructor' member to NULL, thus marking an + entry as inactive, but it will not otherwise change dtors_used nor + the contents of the first dtors_used entries of dtor_table. */ + unsigned int i_limit = dtors_used; + unsigned int i; + + for (i = 0; i < i_limit; i++) + { + struct dtor current = dtor_table[i]; + if (current.destructor != NULL) + { + /* The current dtor has not been deleted yet. */ + void *current_value = glwthread_tls_get (current.key); + if (current_value != NULL) + { + /* The current value is non-NULL. Run the destructor. */ + glwthread_tls_set (current.key, NULL); + LeaveCriticalSection (&dtor_table_lock); + current.destructor (current_value); + EnterCriticalSection (&dtor_table_lock); + destructors_run++; + } + } + } + + /* When all TLS values were already NULL, no further iterations are + needed. */ + if (destructors_run == 0) + break; + } + + dtor_processing_threads--; + LeaveCriticalSection (&dtor_table_lock); +} + +int +glwthread_tls_key_create (glwthread_tls_key_t *keyp, void (*destructor) (void *)) +{ + if (destructor != NULL) + { + dtor_table_ensure_initialized (); + + EnterCriticalSection (&dtor_table_lock); + if (dtor_processing_threads == 0) + { + /* Now it's the appropriate time for shrinking dtors_used. */ + if (dtors_used > dtors_count) + dtor_table_shrink_used (); + } + + while (dtors_used == dtors_allocated) + { + /* Need to grow the dtor_table. */ + unsigned int new_allocated = 2 * dtors_allocated + 1; + if (new_allocated < 7) + new_allocated = 7; + if (new_allocated <= dtors_allocated) /* overflow? */ + new_allocated = UINT_MAX; + + LeaveCriticalSection (&dtor_table_lock); + { + struct dtor *new_table = + (struct dtor *) malloc (new_allocated * sizeof (struct dtor)); + if (new_table == NULL) + return ENOMEM; + EnterCriticalSection (&dtor_table_lock); + /* Attention! dtors_used, dtors_allocated may have changed! */ + if (dtors_used < new_allocated) + { + if (dtors_allocated < new_allocated) + { + /* The new_table is useful. */ + memcpy (new_table, dtor_table, + dtors_used * sizeof (struct dtor)); + dtor_table = new_table; + dtors_allocated = new_allocated; + } + else + { + /* The new_table is not useful, since another thread + meanwhile allocated a drop_table that is at least + as large. */ + free (new_table); + } + break; + } + /* The new_table is not useful, since other threads increased + dtors_used. Free it any retry. */ + free (new_table); + } + } + /* Here dtors_used < dtors_allocated. */ + { + /* Allocate a new key. */ + glwthread_tls_key_t key = TlsAlloc (); + if (key == (DWORD)-1) + { + LeaveCriticalSection (&dtor_table_lock); + return EAGAIN; + } + /* Store the new dtor in the dtor_table, after all used entries. + Do not overwrite inactive entries with indices < dtors_used, in order + not to disturb glwthread_tls_process_destructors invocations that may + be executing in other threads. */ + dtor_table[dtors_used].key = key; + dtor_table[dtors_used].destructor = destructor; + dtors_used++; + dtors_count++; + LeaveCriticalSection (&dtor_table_lock); + *keyp = key; + } + } + else + { + /* Allocate a new key. */ + glwthread_tls_key_t key = TlsAlloc (); + if (key == (DWORD)-1) + return EAGAIN; + *keyp = key; + } + return 0; +} + +int +glwthread_tls_key_delete (glwthread_tls_key_t key) +{ + /* Should the destructor be called for all threads that are currently running? + Probably not, because + - ISO C does not specify when the destructor is to be invoked at all. + - In POSIX, the destructor functions specified with pthread_key_create() + are invoked at thread exit. + - It would be hard to implement, because there are no primitives for + accessing thread-specific values from a different thread. */ + dtor_table_ensure_initialized (); + + EnterCriticalSection (&dtor_table_lock); + if (dtor_processing_threads == 0) + { + /* Now it's the appropriate time for shrinking dtors_used. */ + if (dtors_used > dtors_count) + dtor_table_shrink_used (); + /* Here dtors_used == dtors_count. */ + + /* Find the key in dtor_table. */ + { + unsigned int i_limit = dtors_used; + unsigned int i; + + for (i = 0; i < i_limit; i++) + if (dtor_table[i].key == key) + { + if (i < dtors_used - 1) + /* Swap the entries i and dtors_used - 1. */ + dtor_table[i] = dtor_table[dtors_used - 1]; + dtors_count = dtors_used = dtors_used - 1; + break; + } + } + } + else + { + /* Be careful not to disturb the glwthread_tls_process_destructors + invocations that are executing in other threads. */ + unsigned int i_limit = dtors_used; + unsigned int i; + + for (i = 0; i < i_limit; i++) + if (dtor_table[i].destructor != NULL /* skip inactive entries */ + && dtor_table[i].key == key) + { + /* Mark this entry as inactive. */ + dtor_table[i].destructor = NULL; + dtors_count = dtors_count - 1; + break; + } + } + LeaveCriticalSection (&dtor_table_lock); + /* Now we have ensured that glwthread_tls_process_destructors will no longer + use this key. */ + + if (!TlsFree (key)) + return EINVAL; + return 0; +} diff --git a/contrib/tools/bison/lib/windows-tls.h b/contrib/tools/bison/lib/windows-tls.h new file mode 100644 index 0000000000..2b39fabd5a --- /dev/null +++ b/contrib/tools/bison/lib/windows-tls.h @@ -0,0 +1,42 @@ +/* Thread-local storage (native Windows implementation). + Copyright (C) 2005-2020 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 <https://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2005. */ + +#ifndef _WINDOWS_TLS_H +#define _WINDOWS_TLS_H + +#define WIN32_LEAN_AND_MEAN /* avoid including junk */ +#include <windows.h> + +typedef DWORD glwthread_tls_key_t; + +#ifdef __cplusplus +extern "C" { +#endif + +extern int glwthread_tls_key_create (glwthread_tls_key_t *keyp, void (*destructor) (void *)); +extern void *glwthread_tls_get (glwthread_tls_key_t key); +extern int glwthread_tls_set (glwthread_tls_key_t key, void *value); +extern int glwthread_tls_key_delete (glwthread_tls_key_t key); +extern void glwthread_tls_process_destructors (void); +#define GLWTHREAD_DESTRUCTOR_ITERATIONS 4 + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS_TLS_H */ diff --git a/contrib/tools/bison/lib/xalloc-die.c b/contrib/tools/bison/lib/xalloc-die.c index 295f8d8e75..68559deebb 100644 --- a/contrib/tools/bison/lib/xalloc-die.c +++ b/contrib/tools/bison/lib/xalloc-die.c @@ -1,6 +1,6 @@ /* Report a memory allocation failure and exit. - Copyright (C) 1997-2000, 2002-2004, 2006, 2009-2019 Free Software + Copyright (C) 1997-2000, 2002-2004, 2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/xalloc-oversized.h b/contrib/tools/bison/lib/xalloc-oversized.h index e3068c83c4..13ee23031a 100644 --- a/contrib/tools/bison/lib/xalloc-oversized.h +++ b/contrib/tools/bison/lib/xalloc-oversized.h @@ -1,6 +1,6 @@ /* xalloc-oversized.h -- memory allocation size checking - Copyright (C) 1990-2000, 2003-2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 1990-2000, 2003-2004, 2006-2020 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 diff --git a/contrib/tools/bison/lib/xalloc.h b/contrib/tools/bison/lib/xalloc.h index fc7e86bd89..19c64acb41 100644 --- a/contrib/tools/bison/lib/xalloc.h +++ b/contrib/tools/bison/lib/xalloc.h @@ -1,6 +1,6 @@ /* xalloc.h -- malloc with out-of-memory checking - Copyright (C) 1990-2000, 2003-2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 1990-2000, 2003-2004, 2006-2020 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 @@ -48,7 +48,7 @@ extern "C" { or by using gnulib's xalloc-die module. This is the function to call when one wants the program to die because of a memory allocation failure. */ -extern _Noreturn void xalloc_die (void); +/*extern*/ _Noreturn void xalloc_die (void); void *xmalloc (size_t s) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1)); diff --git a/contrib/tools/bison/lib/xconcat-filename.c b/contrib/tools/bison/lib/xconcat-filename.c index ad2d5f66b4..e04d4337eb 100644 --- a/contrib/tools/bison/lib/xconcat-filename.c +++ b/contrib/tools/bison/lib/xconcat-filename.c @@ -1,5 +1,5 @@ /* Construct a full filename from a directory and a relative filename. - Copyright (C) 2001-2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006-2020 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 diff --git a/contrib/tools/bison/lib/xhash.c b/contrib/tools/bison/lib/xhash.c new file mode 100644 index 0000000000..1e998d2d15 --- /dev/null +++ b/contrib/tools/bison/lib/xhash.c @@ -0,0 +1,38 @@ +/* hash - hashing table processing. + + Copyright (C) 2019-2020 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 <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include "hash.h" + +#include "xalloc.h" + +/* Same as hash_initialize, but invokes xalloc_die on memory + exhaustion. */ + +Hash_table * +hash_xinitialize (size_t candidate, const Hash_tuning *tuning, + Hash_hasher hasher, Hash_comparator comparator, + Hash_data_freer data_freer) +{ + Hash_table *res = + hash_initialize (candidate, tuning, hasher, comparator, data_freer); + if (!res) + xalloc_die (); + return res; +} diff --git a/contrib/tools/bison/lib/xmalloc.c b/contrib/tools/bison/lib/xmalloc.c index cbe9a4f567..486873602e 100644 --- a/contrib/tools/bison/lib/xmalloc.c +++ b/contrib/tools/bison/lib/xmalloc.c @@ -1,6 +1,6 @@ /* xmalloc.c -- malloc with out of memory checking - Copyright (C) 1990-2000, 2002-2006, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 1990-2000, 2002-2006, 2008-2020 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 @@ -76,14 +76,14 @@ x2realloc (void *p, size_t *pn) return x2nrealloc (p, pn, 1); } -/* Allocate S bytes of zeroed memory dynamically, with error checking. +/* Allocate N bytes of zeroed memory dynamically, with error checking. There's no need for xnzalloc (N, S), since it would be equivalent to xcalloc (N, S). */ void * -xzalloc (size_t s) +xzalloc (size_t n) { - return memset (xmalloc (s), 0, s); + return xcalloc (n, 1); } /* Allocate zeroed memory for N elements of S bytes, with error diff --git a/contrib/tools/bison/lib/xmemdup0.c b/contrib/tools/bison/lib/xmemdup0.c index 4f491be1b8..c076b9affb 100644 --- a/contrib/tools/bison/lib/xmemdup0.c +++ b/contrib/tools/bison/lib/xmemdup0.c @@ -1,6 +1,6 @@ /* xmemdup0.c -- copy a block of arbitrary bytes, plus a trailing NUL - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 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 @@ -38,7 +38,8 @@ char * xmemdup0 (void const *p, size_t s) { char *result = xcharalloc (s + 1); - memcpy (result, p, s); + if (s > 0) + memcpy (result, p, s); result[s] = 0; return result; } diff --git a/contrib/tools/bison/lib/xmemdup0.h b/contrib/tools/bison/lib/xmemdup0.h index 768f0b274b..9a61ade9c0 100644 --- a/contrib/tools/bison/lib/xmemdup0.h +++ b/contrib/tools/bison/lib/xmemdup0.h @@ -1,6 +1,6 @@ /* xmemdup0.h -- copy a block of arbitrary bytes, plus a trailing NUL - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 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 diff --git a/contrib/tools/bison/lib/xreadlink.c b/contrib/tools/bison/lib/xreadlink.c index 59cfde91b9..31521b9895 100644 --- a/contrib/tools/bison/lib/xreadlink.c +++ b/contrib/tools/bison/lib/xreadlink.c @@ -1,6 +1,6 @@ /* xreadlink.c -- readlink wrapper to return the link name in malloc'd storage - Copyright (C) 2001, 2003-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2003-2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/xreadlink.h b/contrib/tools/bison/lib/xreadlink.h index 583205be54..be82e78d63 100644 --- a/contrib/tools/bison/lib/xreadlink.h +++ b/contrib/tools/bison/lib/xreadlink.h @@ -1,6 +1,6 @@ /* Reading symbolic links without size limitation. - Copyright (C) 2001, 2003-2004, 2007, 2009-2019 Free Software Foundation, + Copyright (C) 2001, 2003-2004, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/xsize.h b/contrib/tools/bison/lib/xsize.h index ecfd478dcd..45d4166179 100644 --- a/contrib/tools/bison/lib/xsize.h +++ b/contrib/tools/bison/lib/xsize.h @@ -1,6 +1,6 @@ /* xsize.h -- Checked size_t computations. - Copyright (C) 2003, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2003, 2008-2020 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 diff --git a/contrib/tools/bison/lib/xstrndup.c b/contrib/tools/bison/lib/xstrndup.c index a973829113..93dcfe50fd 100644 --- a/contrib/tools/bison/lib/xstrndup.c +++ b/contrib/tools/bison/lib/xstrndup.c @@ -1,6 +1,6 @@ /* Duplicate a bounded initial segment of a string, with out-of-memory checking. - Copyright (C) 2003, 2006-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2003, 2006-2007, 2009-2020 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 diff --git a/contrib/tools/bison/lib/xstrndup.h b/contrib/tools/bison/lib/xstrndup.h index 360ccfdbb1..4f1da97c3f 100644 --- a/contrib/tools/bison/lib/xstrndup.h +++ b/contrib/tools/bison/lib/xstrndup.h @@ -1,6 +1,6 @@ /* Duplicate a bounded initial segment of a string, with out-of-memory checking. - Copyright (C) 2003, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2003, 2009-2020 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 diff --git a/contrib/tools/bison/lib/xtime.h b/contrib/tools/bison/lib/xtime.h index 9edd12392d..7f2992c335 100644 --- a/contrib/tools/bison/lib/xtime.h +++ b/contrib/tools/bison/lib/xtime.h @@ -1,6 +1,6 @@ /* xtime -- extended-resolution integer timestamps - Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2020 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 @@ -29,40 +29,27 @@ _GL_INLINE_HEADER_BEGIN #endif /* xtime_t is a signed type used for timestamps. It is an integer - type that is a count of nanoseconds -- except for obsolescent hosts - without sufficiently-wide integers, where it is a count of - seconds. */ -#if HAVE_LONG_LONG_INT + type that is a count of nanoseconds. */ typedef long long int xtime_t; -# define XTIME_PRECISION 1000000000 -#else -# include <limits.h> -typedef long int xtime_t; -# if LONG_MAX >> 31 >> 31 == 0 -# define XTIME_PRECISION 1 -# else -# define XTIME_PRECISION 1000000000 -# endif -#endif +#define XTIME_PRECISION 1000000000 #ifdef __cplusplus extern "C" { #endif /* Return an extended time value that contains S seconds and NS - nanoseconds. */ + nanoseconds. S and NS should be nonnegative; otherwise, integer + overflow can occur even if the result is in range. */ XTIME_INLINE xtime_t xtime_make (xtime_t s, long int ns) { - const long int giga = 1000 * 1000 * 1000; - s += ns / giga; - ns %= giga; - if (XTIME_PRECISION == 1) - return s; - else - return XTIME_PRECISION * s + ns; + return XTIME_PRECISION * s + ns; } +/* The following functions split an extended time value: + T = XTIME_PRECISION * xtime_sec (T) + xtime_nsec (T) + with 0 <= xtime_nsec (T) < XTIME_PRECISION. */ + /* Return the number of seconds in T, which must be nonnegative. */ XTIME_INLINE xtime_t xtime_nonnegative_sec (xtime_t t) @@ -74,11 +61,7 @@ xtime_nonnegative_sec (xtime_t t) XTIME_INLINE xtime_t xtime_sec (xtime_t t) { - return (XTIME_PRECISION == 1 - ? t - : t < 0 - ? (t + XTIME_PRECISION - 1) / XTIME_PRECISION - 1 - : xtime_nonnegative_sec (t)); + return (t + (t < 0)) / XTIME_PRECISION - (t < 0); } /* Return the number of nanoseconds in T, which must be nonnegative. */ diff --git a/contrib/tools/bison/lib/ya.make b/contrib/tools/bison/lib/ya.make index 4d6afb692a..41aec50a87 100644 --- a/contrib/tools/bison/lib/ya.make +++ b/contrib/tools/bison/lib/ya.make @@ -16,6 +16,7 @@ NO_COMPILER_WARNINGS() NO_RUNTIME() CFLAGS( + -DDEFAULT_TEXT_DOMAIN=\"bison-gnulib\" -DEXEEXT=\"\" ) @@ -24,6 +25,7 @@ SRCS( areadlink.c argmatch.c asnprintf.c + asprintf.c basename-lgpl.c basename.c binary-io.c @@ -53,16 +55,22 @@ SRCS( fd-safer.c fopen-safer.c fseterr.c + fstrcmp.c get-errno.c gethrxtime.c getprogname.c gl_array_list.c gl_list.c gl_xlist.c + glthread/lock.c + glthread/threadlib.c + glthread/tls.c hard-locale.c hash.c localcharset.c math.c + mbchar.c + mbfile.c mbrtowc.c mbswidth.c path-join.c @@ -75,6 +83,7 @@ SRCS( printf-parse.c progname.c quotearg.c + setlocale_null.c sig-handler.c spawn-pipe.c stripslash.c @@ -83,10 +92,12 @@ SRCS( unistd.c uniwidth/width.c vasnprintf.c + vasprintf.c wait-process.c wctype-h.c xalloc-die.c xconcat-filename.c + xhash.c xmalloc.c xmemdup0.c xreadlink.c @@ -130,6 +141,11 @@ ELSEIF (OS_WINDOWS) strverscmp.c waitpid.c wcwidth.c + windows-mutex.c + windows-once.c + windows-recmutex.c + windows-rwlock.c + windows-tls.c ) ENDIF() |