Skip to contentSkip to conversation

parser_bison: Fix for bison < 3.6

PATCH Superseded Phil Sutter 2 participants 3 messages Jun 10

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 parser_bison: Fix for bison < 3.6

Support for 'custom' parse.error value was added in bison-3.6. Fall back to previous value for earlier versions.

This is harder to get right than it seems: On one hand, preprocessor macros can't be used in parser_bison.y's declaration section and automake forbids conditional changes to AM_YFLAGS on the other.

Fixes 67b822f2b2624 ("parser_bison: on syntax errors, output expected tokens")
---
 Makefile.am        |  6 ++++++
 configure.ac       | 12 ++++++++++++
 src/parser_bison.y |  4 ++--
 3 files changed, 20 insertions(+), 2 deletions(-)
Makefile.am +6 -0
index fa71e06eefee5..ddf145a87c810 100644
@@ -164,6 +164,12 @@ AM_CFLAGS = \
 	$(NULL)
 
 AM_YFLAGS = -d -Wno-yacc
+if BISON_CUSTOM_ERROR
+YACC += -D parse.error=custom -D parse.lac=full
+AM_CFLAGS += -DBISON_CUSTOM_ERROR
+else
+YACC += -D parse.error=verbose
+endif
 
 if BUILD_PROFILING
 AM_CFLAGS += --coverage
configure.ac +12 -0
index 0d3ee2ac89f69..b6cad3117a51b 100644
@@ -45,6 +45,18 @@ then
         exit 1
 fi
 
+AC_ARG_ENABLE([extended_parser_errors],
+	      AS_HELP_STRING([--disable-extended-parser-errors],
+			     [Disable use of parse.error=custom and LAC in Bison]),
+	      [], [
+			enable_extended_parser_errors=no
+			AC_SUBST([BISON], [$ac_cv_prog_YACC])
+			AX_PROG_BISON_VERSION([3.6],
+					      [enable_extended_parser_errors=yes])
+	      ])
+AM_CONDITIONAL([BISON_CUSTOM_ERROR],
+	       [test "x$enable_extended_parser_errors" != xno])
+
 AM_PROG_AR
 LT_INIT([disable-static])
 AC_EXEEXT
src/parser_bison.y +2 -2
index 5a334bf0c4997..fc95597d898c0 100644
@@ -221,8 +221,6 @@ int nft_lex(void *, void *, void *);
 %parse-param		{ void *scanner }
 %parse-param		{ struct parser_state *state }
 %lex-param		{ scanner }
-%define parse.error custom
-%define parse.lac full
 %locations
 
 %initial-action {
@@ -6537,6 +6535,7 @@ exthdr_key		:	HBH	close_scope_hbh	{ $$ = IPPROTO_HOPOPTS; }
 
 %%
 
+#ifdef BISON_CUSTOM_ERROR
 static int
 yyreport_syntax_error(const yypcontext_t *yyctx, struct nft_ctx *nft,
                       void *scanner, struct parser_state *state)
@@ -6592,3 +6591,4 @@ yyreport_syntax_error(const yypcontext_t *yyctx, struct nft_ctx *nft,
 	free(msg);
 	return 0;
 }
+#endif /* BISON_CUSTOM_ERROR */
Signature · 1 line
2.54.0
#1 lore raw

Hi Phil,

Quoted 42 lines · Phil Sutter

Support for 'custom' parse.error value was added in bison-3.6. Fall back to previous value for earlier versions.

This is harder to get right than it seems: On one hand, preprocessor macros can't be used in parser_bison.y's declaration section and automake forbids conditional changes to AM_YFLAGS on the other.

Fixes 67b822f2b2624 ("parser_bison: on syntax errors, output expected tokens")
---
 Makefile.am        |  6 ++++++
 configure.ac       | 12 ++++++++++++
 src/parser_bison.y |  4 ++--
 3 files changed, 20 insertions(+), 2 deletions(-)
Makefile.am +6 -0
index fa71e06eefee5..ddf145a87c810 100644
@@ -164,6 +164,12 @@ AM_CFLAGS = \
 	$(NULL)
 
 AM_YFLAGS = -d -Wno-yacc
+if BISON_CUSTOM_ERROR
+YACC += -D parse.error=custom -D parse.lac=full
+AM_CFLAGS += -DBISON_CUSTOM_ERROR
+else
+YACC += -D parse.error=verbose
+endif
 
 if BUILD_PROFILING
 AM_CFLAGS += --coverage
configure.ac +1 -0
index 0d3ee2ac89f69..b6cad3117a51b 100644
@@ -45,6 +45,18 @@ then
         exit 1
 fi
 
+AC_ARG_ENABLE([extended_parser_errors],

configure.ac then · line 58

Quoted 10 lines
configure.ac +10 -0
+	      AS_HELP_STRING([--disable-extended-parser-errors],
+			     [Disable use of parse.error=custom and LAC in Bison]),
+	      [], [
+			enable_extended_parser_errors=no
+			AC_SUBST([BISON], [$ac_cv_prog_YACC])
+			AX_PROG_BISON_VERSION([3.6],
+					      [enable_extended_parser_errors=yes])
+	      ])
+AM_CONDITIONAL([BISON_CUSTOM_ERROR],
+	       [test "x$enable_extended_parser_errors" != xno])

Can this be made transparent? ie. if bison >= 3.6, then enable it always. Otherwise, disable it.

Then, include this information here in configure.ac:

echo "
nft configuration:

  cli support:                  ${with_cli}
  enable debugging symbols:     ${enable_debug}
  use mini-gmp:                 ${with_mini_gmp}
  enable man page:              ${enable_man_doc}
  libxtables support:           ${with_xtables}
  json output support:          ${with_json}
  collect profiling data:       ${enable_profiling}"

and here with -V:

# nft -V
nftables v1.1.6 (Commodore Bullmoose #7)
  cli:          editline
  json:         yes
  minigmp:      no
  libxtables:   yes

Maybe add:

bison >= 3.6: yes

or similar?

Thanks

Quoted 32 lines
configure.ac +0 -0
 AM_PROG_AR
 LT_INIT([disable-static])
 AC_EXEEXT
src/parser_bison.y +2 -2
index 5a334bf0c4997..fc95597d898c0 100644
@@ -221,8 +221,6 @@ int nft_lex(void *, void *, void *);
 %parse-param		{ void *scanner }
 %parse-param		{ struct parser_state *state }
 %lex-param		{ scanner }
-%define parse.error custom
-%define parse.lac full
 %locations
 
 %initial-action {
@@ -6537,6 +6535,7 @@ exthdr_key		:	HBH	close_scope_hbh	{ $$ = IPPROTO_HOPOPTS; }
 
 %%
 
+#ifdef BISON_CUSTOM_ERROR
 static int
 yyreport_syntax_error(const yypcontext_t *yyctx, struct nft_ctx *nft,
                       void *scanner, struct parser_state *state)
@@ -6592,3 +6591,4 @@ yyreport_syntax_error(const yypcontext_t *yyctx, struct nft_ctx *nft,
 	free(msg);
 	return 0;
 }
+#endif /* BISON_CUSTOM_ERROR */
Signature · 1 line
2.54.0
author reviewer
#2 lore raw

Hi Pablo,

Quoted 42 lines · Pablo Neira Ayuso
Quoted 41 lines · Phil Sutter

Support for 'custom' parse.error value was added in bison-3.6. Fall back to previous value for earlier versions.

This is harder to get right than it seems: On one hand, preprocessor macros can't be used in parser_bison.y's declaration section and automake forbids conditional changes to AM_YFLAGS on the other.

Fixes 67b822f2b2624 ("parser_bison: on syntax errors, output expected tokens")
---
 Makefile.am        |  6 ++++++
 configure.ac       | 12 ++++++++++++
 src/parser_bison.y |  4 ++--
 3 files changed, 20 insertions(+), 2 deletions(-)
Makefile.am +6 -0
index fa71e06eefee5..ddf145a87c810 100644
@@ -164,6 +164,12 @@ AM_CFLAGS = \
 	$(NULL)
 
 AM_YFLAGS = -d -Wno-yacc
+if BISON_CUSTOM_ERROR
+YACC += -D parse.error=custom -D parse.lac=full
+AM_CFLAGS += -DBISON_CUSTOM_ERROR
+else
+YACC += -D parse.error=verbose
+endif
 
 if BUILD_PROFILING
 AM_CFLAGS += --coverage
configure.ac +0 -0
index 0d3ee2ac89f69..b6cad3117a51b 100644
@@ -45,6 +45,18 @@ then
         exit 1
 fi
 
Quoted 14 lines

configure.ac then · line 58

Quoted 11 lines
configure.ac +11 -0
+AC_ARG_ENABLE([extended_parser_errors],
+	      AS_HELP_STRING([--disable-extended-parser-errors],
+			     [Disable use of parse.error=custom and LAC in Bison]),
+	      [], [
+			enable_extended_parser_errors=no
+			AC_SUBST([BISON], [$ac_cv_prog_YACC])
+			AX_PROG_BISON_VERSION([3.6],
+					      [enable_extended_parser_errors=yes])
+	      ])
+AM_CONDITIONAL([BISON_CUSTOM_ERROR],
+	       [test "x$enable_extended_parser_errors" != xno])

Can this be made transparent? ie. if bison >= 3.6, then enable it always. Otherwise, disable it.

This is the default behaviour (which is the "else" case of that huge AC_ARG_ENABLE). Users may choose to override the version-based setting via --{en,dis}able-extended-parser-errors. Fine with you or am I missing your point?

Quoted 12 lines

Then, include this information here in configure.ac:

echo "
nft configuration:

  cli support:                  ${with_cli}
  enable debugging symbols:     ${enable_debug}
  use mini-gmp:                 ${with_mini_gmp}
  enable man page:              ${enable_man_doc}
  libxtables support:           ${with_xtables}
  json output support:          ${with_json}
  collect profiling data:       ${enable_profiling}"
Quoted 8 lines

and here with -V:

# nft -V
nftables v1.1.6 (Commodore Bullmoose #7)
  cli:          editline
  json:         yes
  minigmp:      no
  libxtables:   yes

Oh right, I keep forgetting about the summary (which is really useful as reading config.log needs training).

Quoted 5 lines

Maybe add:

bison >= 3.6: yes

or similar?

I'd go with "extended parser errors", to remain consistent with the config option and also because it calls out what actually changed.

There is one other oddity still which I should check: The configure script always checks bison version, but 'make dist' tarballs ship with parser_bison.c and thus don't need bison at all. So this patch might disable the extended error messages for tarball users which don't have bison installed.

Cheers, Phil