bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Testsuite summary for GNU Bison 3.8.2 : FAIL 2


From: Akim Demaille
Subject: Re: Testsuite summary for GNU Bison 3.8.2 : FAIL 2
Date: Mon, 25 Oct 2021 07:51:02 +0200


> Le 24 oct. 2021 à 09:15, Akim Demaille <akim@lrde.epita.fr> a écrit :
> 
> commit ff9771d26e5e387cde51393d97d4f8d42837a25a
> Author: Akim Demaille <akim.demaille@gmail.com>
> Date:   Sat Oct 23 06:01:44 2021 +0200
> 
>    examples: address portability issues about strdup
> 
>    Reported by Dennis Clarke
>    <https://lists.gnu.org/r/bug-bison/2021-10/msg00005.html>.
>    In particular
>    <https://lists.gnu.org/r/bug-bison/2021-10/msg00023.html>.
> 
>    * doc/bison.texi, examples/c/glr/c++-types.y (_XOPEN_SOURCE): Define
>    to 600, to get a strdup that works on Solaris.

On top of this patch, I will also install these.

commit ab2d834429c2a15b5214079b7b7be68c60e35bd8
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Sat Oct 23 06:09:31 2021 +0200

    examples: fix coding style
    
    * examples/c/glr/c++-types.y: Use snake_case identifiers.
    Prefer strdup to malloc+strcpy.

diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y
index 8b1591e6..fbdeb7fc 100644
--- a/examples/c/bistromathic/parse.y
+++ b/examples/c/bistromathic/parse.y
@@ -244,7 +244,7 @@ init_table (void)
 symrec *
 putsym (char const *name, int sym_type)
 {
-  symrec *res = (symrec *) malloc (sizeof (symrec));
+  symrec *res = malloc (sizeof *res);
   res->name = strdup (name);
   res->type = sym_type;
   res->value.var = 0; // Set value to 0 even if fun.
diff --git a/examples/c/glr/c++-types.y b/examples/c/glr/c++-types.y
index 232d0112..ff1b62fb 100644
--- a/examples/c/glr/c++-types.y
+++ b/examples/c/glr/c++-types.y
@@ -29,24 +29,24 @@
 
 %code requires
 {
-  union Node {
+  union node {
     struct {
-      int isNterm;
+      int is_nterm;
       int parents;
-    } nodeInfo;
+    } node_info;
     struct {
-      int isNterm; /* 1 */
+      int is_nterm; /* 1 */
       int parents;
       char const *form;
-      union Node *children[3];
+      union node *children[3];
     } nterm;
     struct {
-      int isNterm; /* 0 */
+      int is_nterm; /* 0 */
       int parents;
       char *text;
     } term;
   };
-  typedef union Node Node;
+  typedef union node node_t;
 }
 
 %define api.value.type union
@@ -65,12 +65,12 @@
 #include <stdlib.h>
 #include <string.h>
 
-  static Node *new_nterm (char const *, Node *, Node *, Node *);
-  static Node *new_term (char *);
-  static void free_node (Node *);
-  static char *node_to_string (const Node *);
-  static void node_print (FILE *, const Node *);
-  static Node *stmt_merge (YYSTYPE x0, YYSTYPE x1);
+  static node_t *new_nterm (char const *, node_t *, node_t *, node_t *);
+  static node_t *new_term (char *);
+  static void free_node (node_t *);
+  static char *node_to_string (const node_t *);
+  static void node_print (FILE *, const node_t *);
+  static node_t *stmt_merge (YYSTYPE x0, YYSTYPE x1);
 
   static void yyerror (YYLTYPE const * const loc, const char *msg);
   static yytoken_kind_t yylex (YYSTYPE *lval, YYLTYPE *lloc);
@@ -87,9 +87,9 @@
 
 %glr-parser
 
-%type <Node *> stmt expr decl declarator TYPENAME ID
-%destructor { free_node ($$); } <Node *>
-%printer { node_print (yyo, $$); } <Node *>
+%type <node_t *> stmt expr decl declarator TYPENAME ID
+%destructor { free_node ($$); } <node_t *>
+%printer { node_print (yyo, $$); } <node_t *>
 
 %%
 
@@ -190,12 +190,12 @@ yylex (YYSTYPE *lval, YYLTYPE *lloc)
                 if (isupper ((unsigned char) buffer[0]))
                   {
                     tok = TYPENAME;
-                    lval->TYPENAME = new_term (strcpy (malloc (i), buffer));
+                    lval->TYPENAME = new_term (strdup (buffer));
                   }
                 else
                   {
                     tok = ID;
-                    lval->ID = new_term (strcpy (malloc (i), buffer));
+                    lval->ID = new_term (strdup (buffer));
                   }
               }
             else
@@ -210,45 +210,45 @@ yylex (YYSTYPE *lval, YYLTYPE *lloc)
     }
 }
 
-static Node *
-new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
+static node_t *
+new_nterm (char const *form, node_t *child0, node_t *child1, node_t *child2)
 {
-  Node *res = malloc (sizeof *res);
-  res->nterm.isNterm = 1;
+  node_t *res = malloc (sizeof *res);
+  res->nterm.is_nterm = 1;
   res->nterm.parents = 0;
   res->nterm.form = form;
   res->nterm.children[0] = child0;
   if (child0)
-    child0->nodeInfo.parents += 1;
+    child0->node_info.parents += 1;
   res->nterm.children[1] = child1;
   if (child1)
-    child1->nodeInfo.parents += 1;
+    child1->node_info.parents += 1;
   res->nterm.children[2] = child2;
   if (child2)
-    child2->nodeInfo.parents += 1;
+    child2->node_info.parents += 1;
   return res;
 }
 
-static Node *
+static node_t *
 new_term (char *text)
 {
-  Node *res = malloc (sizeof *res);
-  res->term.isNterm = 0;
+  node_t *res = malloc (sizeof *res);
+  res->term.is_nterm = 0;
   res->term.parents = 0;
   res->term.text = text;
   return res;
 }
 
 static void
-free_node (Node *node)
+free_node (node_t *node)
 {
   if (!node)
     return;
-  node->nodeInfo.parents -= 1;
+  node->node_info.parents -= 1;
   /* Free only if 0 (last parent) or -1 (no parents).  */
-  if (node->nodeInfo.parents > 0)
+  if (node->node_info.parents > 0)
     return;
-  if (node->nodeInfo.isNterm == 1)
+  if (node->node_info.is_nterm == 1)
     {
       free_node (node->nterm.children[0]);
       free_node (node->nterm.children[1]);
@@ -260,15 +260,12 @@ free_node (Node *node)
 }
 
 static char *
-node_to_string (const Node *node)
+node_to_string (const node_t *node)
 {
   char *res;
   if (!node)
-    {
-      res = malloc (1);
-      res[0] = 0;
-    }
-  else if (node->nodeInfo.isNterm == 1)
+    res = strdup ("");
+  else if (node->node_info.is_nterm)
     {
       char *child0 = node_to_string (node->nterm.children[0]);
       char *child1 = node_to_string (node->nterm.children[1]);
@@ -286,7 +283,7 @@ node_to_string (const Node *node)
 }
 
 static void
-node_print (FILE *out, const Node *n)
+node_print (FILE *out, const node_t *n)
 {
   char *str = node_to_string (n);
   fputs (str, out);
@@ -294,7 +291,7 @@ node_print (FILE *out, const Node *n)
 }
 
 
-static Node *
+static node_t *
 stmt_merge (YYSTYPE x0, YYSTYPE x1)
 {
   return new_nterm ("<OR>(%s, %s)", x0.stmt, x1.stmt, NULL);









commit 59bb05cc51b33fd73878731d2eb648e42fe88dc3
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Sat Oct 23 06:20:10 2021 +0200

    tests: fix coding style
    
    * tests/cxx-type.at, tests/glr-regression.at:
    Prefer strdup to malloc+strcpy.
    Use snake_case.

diff --git a/tests/cxx-type.at b/tests/cxx-type.at
index 2537d525..fcf5e53c 100644
--- a/tests/cxx-type.at
+++ b/tests/cxx-type.at
@@ -34,33 +34,33 @@ m4_define([_AT_TEST_GLR_CXXTYPES],
 %code requires
 {
   #include <stdio.h>
-  union Node {
+  union node_t {
     struct {
-      int isNterm;
+      int is_nterm;
       int parents;
-    } nodeInfo;
+    } node_info;
     struct {
-      int isNterm; /* 1 */
+      int is_nterm; /* 1 */
       int parents;
       char const *form;
-      union Node *children[3];
+      union node_t *children[3];
     } nterm;
     struct {
-      int isNterm; /* 0 */
+      int is_nterm; /* 0 */
       int parents;
       char *text;
     } term;
   };
-  typedef union Node Node;
-  #define YYSTYPE Node *
+  typedef union node_t node_t;
+  #define YYSTYPE node_t *
 }
 
 %code
 {
-  static Node *new_nterm (char const *, Node *, Node *, Node *);
-  static Node *new_term (char *);
-  static void free_node (Node *);
-  static char *node_to_string (Node *);
+  static node_t *new_nterm (char const *, node_t *, node_t *, node_t *);
+  static node_t *new_term (char *);
+  static void free_node (node_t *);
+  static char *node_to_string (node_t *);
 ]m4_bmatch([$2], [stmt_merge],
 [ static YYSTYPE stmt_merge (YYSTYPE x0, YYSTYPE x1);])[
   #define YYINITDEPTH 10
@@ -200,7 +200,7 @@ m4_define([_AT_TEST_GLR_CXXTYPES],
                 ungetc (c, stdin);
                 buffer[i++] = 0;
                 tok = isupper (YY_CAST (unsigned char, buffer[0])) ? TYPENAME 
: ID;
-                yylval = new_term (strcpy (YY_CAST (char *, malloc (i)), 
buffer));
+                yylval = new_term (strdup (buffer));
               }
             else
               {
@@ -215,45 +215,45 @@ m4_define([_AT_TEST_GLR_CXXTYPES],
     }
 }
 
-static Node *
-new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
+static node_t *
+new_nterm (char const *form, node_t *child0, node_t *child1, node_t *child2)
 {
-  Node *node = YY_CAST (Node *, malloc (sizeof (Node)));
-  node->nterm.isNterm = 1;
-  node->nterm.parents = 0;
-  node->nterm.form = form;
-  node->nterm.children[0] = child0;
+  node_t *res = YY_CAST (node_t *, malloc (sizeof *res));
+  res->nterm.is_nterm = 1;
+  res->nterm.parents = 0;
+  res->nterm.form = form;
+  res->nterm.children[0] = child0;
   if (child0)
-    child0->nodeInfo.parents += 1;
-  node->nterm.children[1] = child1;
+    child0->node_info.parents += 1;
+  res->nterm.children[1] = child1;
   if (child1)
-    child1->nodeInfo.parents += 1;
-  node->nterm.children[2] = child2;
+    child1->node_info.parents += 1;
+  res->nterm.children[2] = child2;
   if (child2)
-    child2->nodeInfo.parents += 1;
-  return node;
+    child2->node_info.parents += 1;
+  return res;
 }
 
-static Node *
+static node_t *
 new_term (char *text)
 {
-  Node *node = YY_CAST (Node *, malloc (sizeof (Node)));
-  node->term.isNterm = 0;
-  node->term.parents = 0;
-  node->term.text = text;
-  return node;
+  node_t *res = YY_CAST (node_t *, malloc (sizeof *res));
+  res->term.is_nterm = 0;
+  res->term.parents = 0;
+  res->term.text = text;
+  return res;
 }
 
 static void
-free_node (Node *node)
+free_node (node_t *node)
 {
   if (!node)
     return;
-  node->nodeInfo.parents -= 1;
+  node->node_info.parents -= 1;
   /* Free only if 0 (last parent) or -1 (no parents).  */
-  if (node->nodeInfo.parents > 0)
+  if (node->node_info.parents > 0)
     return;
-  if (node->nodeInfo.isNterm == 1)
+  if (node->node_info.is_nterm == 1)
     {
       free_node (node->nterm.children[0]);
       free_node (node->nterm.children[1]);
@@ -265,15 +265,12 @@ m4_define([_AT_TEST_GLR_CXXTYPES],
 }
 
 static char *
-node_to_string (Node *node)
+node_to_string (node_t *node)
 {
   char *res;
   if (!node)
-    {
-      res = YY_CAST (char *, malloc (1));
-      res[0] = 0;
-    }
-  else if (node->nodeInfo.isNterm == 1)
+    res = strdup ("");
+  else if (node->node_info.is_nterm)
     {
       char *child0 = node_to_string (node->nterm.children[0]);
       char *child1 = node_to_string (node->nterm.children[1]);
diff --git a/tests/glr-regression.at b/tests/glr-regression.at
index 2cd09468..a10f69ba 100644
--- a/tests/glr-regression.at
+++ b/tests/glr-regression.at
@@ -294,9 +294,8 @@ m4_pushdef([AT_TEST],
       return 0;
     else
       {
-        char *s;
         assert (strlen (buf) < sizeof buf - 1);
-        s = YY_CAST (char *, malloc (strlen (buf) + 1));
+        char *s = YY_CAST (char *, malloc (strlen (buf) + 1));
         strcpy (s, buf);
         ]AT_VAL[ = s;
         return 'V';












reply via email to

[Prev in Thread] Current Thread [Next in Thread]