On 9/28/18 7:26 AM, Simon Sobisch wrote:
    As I was told that only "current" VC compilers are considered for being
    patched I've tried to compile Bison 3.1 with VC 2015.
    Two places needed a patch to allow all sources to be compiled.
    You find a patch file attached.


Thanks for the heads-up. I installed the attached patches, which attempt to fix the problems you mention in more-portable ways. Please give them a try.


    a) any use of verify() defined in verify.h raises the warning
    > warning C4116: unnamed type definition in parentheses


Perhaps you could teach verify.h to use 'static_assert'; see <https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/16507642-please-implement-static-assert>. But if it's too much trouble please don't bother; see <https://www.gnu.org/prep/standards/html_node/System-Portability.html> for why.

>From 701488bf60e9b51ffa5d9da5bb6d7869620da154 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Fri, 28 Sep 2018 16:05:51 -0700
Subject: [PATCH 1/2] uniqstr: avoid need for VLAs

C11 no longer requires support for variable-length arrays, and
VS2015 does not have them.  Redo UNIQSTR_CONCAT to use a method
that is simpler and better anyway.
* src/uniqstr.c (uniqstr_vsprintf): Remove; no longer needed.
* src/uniqstr.h (UNIQSTR_GEN_FORMAT, UNIQSTR_GEN_FORMAT_):
* src/uniqstr.c (uniqstr_concat): New function.
* src/uniqstr.h (UNIQSTR_CONCAT): Use it instead of using
uniqstr_vsprintf.
---
 src/uniqstr.c | 33 +++++++++++++++++++++++++--------
 src/uniqstr.h | 42 +++++-------------------------------------
 2 files changed, 30 insertions(+), 45 deletions(-)

diff --git a/src/uniqstr.c b/src/uniqstr.c
index bfe1d172..b4f6e946 100644
--- a/src/uniqstr.c
+++ b/src/uniqstr.c
@@ -56,19 +56,36 @@ uniqstr_new (char const *str)
 }
 
 uniqstr
-uniqstr_vsprintf (char const *format, ...)
+uniqstr_concat (int nargs, ...)
 {
   va_list args;
-  size_t length;
-  va_start (args, format);
-  length = vsnprintf (NULL, 0, format, args);
+
+  va_start (args, nargs);
+  size_t reslen = 0;
+  for (int i = 0; i < nargs; i++)
+    reslen += strlen (va_arg (args, char const *));
   va_end (args);
 
-  char res[length + 1];
-  va_start (args, format);
-  vsprintf (res, format, args);
+  char *str = xmalloc (reslen + 1);
+  char *p = str;
+
+  va_start (args, nargs);
+  for (int i = 0; i < nargs; i++)
+    {
+      char const *arg = va_arg (args, char const *);
+      size_t arglen = strlen (arg);
+      memcpy (p, arg, arglen);
+      p += arglen;
+    }
   va_end (args);
-  return uniqstr_new (res);
+
+  *p = '\0';
+  uniqstr res = hash_insert (uniqstrs_table, str);
+  if (!res)
+    xalloc_die ();
+  if (res != str)
+    free (str);
+  return res;
 }
 
 /*------------------------------.
diff --git a/src/uniqstr.h b/src/uniqstr.h
index fe04cb79..52472421 100644
--- a/src/uniqstr.h
+++ b/src/uniqstr.h
@@ -32,12 +32,6 @@ typedef char const *uniqstr;
 /* Return the uniqstr for STR.  */
 uniqstr uniqstr_new (char const *str);
 
-/* Return a uniqstr built by vsprintf.  In order to simply concatenate
-   strings, use UNIQSTR_CONCAT, which is a convenient wrapper around
-   this function.  */
-uniqstr uniqstr_vsprintf (char const *format, ...)
-  _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2);
-
 /* Two uniqstr values have the same value iff they are the same.  */
 # define UNIQSTR_EQ(Ustr1, Ustr2) (!!((Ustr1) == (Ustr2)))
 
@@ -52,38 +46,12 @@ void uniqstr_assert (char const *str);
 | Concatenation.  |
 `----------------*/
 
-/* Concatenate at most 20 strings and return a uniqstr.  The goal of
-   this macro is to make the caller's code a little more succinct
-   without a trivial uniqstr_vsprintf format string to maintain
-   (for example, "%s%s%s") while still benefitting from gcc's type
-   checking.  Unfortunately, because of the missing format string in the
-   macro invocation, the argument number reported by gcc for a bad
-   argument type is 1 too large.  */
+/* Concatenate strings and return a uniqstr.  The goal of
+   this macro is to make the caller's code a little more succinct.  */
 # define UNIQSTR_CONCAT(...)                                            \
-  uniqstr_vsprintf (UNIQSTR_GEN_FORMAT (__VA_ARGS__,                    \
-                                        "%s", "%s", "%s", "%s", "%s",   \
-                                        "%s", "%s", "%s", "%s", "%s",   \
-                                        "%s", "%s", "%s", "%s", "%s",   \
-                                        "%s", "%s", "%s", "%s", "%s"),  \
-                    __VA_ARGS__)
-
-# define UNIQSTR_GEN_FORMAT(F1,  F2,  F3,  F4,  F5,     \
-                           F6,  F7,  F8,  F9,  F10,     \
-                           F11, F12, F13, F14, F15,     \
-                           F16, F17, F18, F19, F20,     \
-                           ...)                         \
-  UNIQSTR_GEN_FORMAT_ (__VA_ARGS__,                     \
-                       "", "", "", "", "",              \
-                       "", "", "", "", "",              \
-                       "", "", "", "", "",              \
-                       "", "", "", "", "")
-
-# define UNIQSTR_GEN_FORMAT_(F1,  F2,  F3,  F4,  F5,            \
-                            F6,  F7,  F8,  F9,  F10,            \
-                            F11, F12, F13, F14, F15,            \
-                            F16, F17, F18, F19, F20, ...)       \
-  F1  F2  F3  F4  F5  F6  F7  F8  F9  F10                       \
-  F11 F12 F13 F14 F15 F16 F17 F18 F19 F20
+  uniqstr_concat (ARRAY_CARDINALITY (((char const *[]) {__VA_ARGS__})), \
+                  __VA_ARGS__)
+uniqstr uniqstr_concat (int nargs, ...);
 
 /*--------------------.
 | Table of uniqstrs.  |
-- 
2.17.1

>From cca7206a718f8602859175a77f47dffe2eabc860 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Fri, 28 Sep 2018 16:41:09 -0700
Subject: [PATCH 2/2] getargs: use LC_MESSAGES trick only on glibc

* src/getargs.c (usage): Rely on setlocale (LC_MESSAGES, NULL)
trick only on glibc, as POSIX does not specify the output
of setlocale in this case, and the Gnulib localename module
source code indicates that the trick works only on glibc.
---
 src/getargs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/getargs.c b/src/getargs.c
index 5696c35f..95c681b5 100644
--- a/src/getargs.c
+++ b/src/getargs.c
@@ -360,6 +360,8 @@ FEATURE is a list of comma separated words that can include:\n\
       fputs (_("General help using GNU software: "
                "<http://www.gnu.org/gethelp/>.\n"),
              stdout);
+
+#if (defined __GLIBC__ && __GLIBC__ >= 2) && !defined __UCLIBC__
       /* Don't output this redundant message for English locales.
          Note we still output for 'C' so that it gets included in the
          man page.  */
@@ -372,6 +374,7 @@ FEATURE is a list of comma separated words that can include:\n\
            email address.  */
         fputs (_("Report translation bugs to "
                  "<http://translationproject.org/team/>.\n"), stdout);
+#endif
       fputs (_("For complete documentation, run: info bison.\n"), stdout);
     }
 
-- 
2.17.1

Reply via email to