From ab61c40bfa2ba1887fee304b2ef5306a14a7248c Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 25 Jul 2024 09:26:08 +0200 Subject: [PATCH] Add extern declarations for Bison global variables This adds extern declarations for some global variables produced by Bison that are not already declared in its generated header file. This is a workaround to be able to add -Wmissing-variable-declarations to the global set of warning options in the near future. Another longer-term solution would be to convert these grammars to "pure" parsers in Bison, to avoid global variables altogether. Note that the core grammar is already pure, so this patch did not need to touch it. Reviewed-by: Andres Freund Discussion: https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c95ce@eisentraut.org --- contrib/cube/cubeparse.y | 4 ++++ contrib/seg/segparse.y | 4 ++++ src/backend/bootstrap/bootparse.y | 5 +++++ src/backend/replication/repl_gram.y | 5 +++++ src/backend/replication/syncrep_gram.y | 4 ++++ src/interfaces/ecpg/preproc/ecpg.header | 4 ++++ src/pl/plpgsql/src/pl_gram.y | 4 ++++ src/test/isolation/specparse.y | 3 +++ 8 files changed, 33 insertions(+) diff --git a/contrib/cube/cubeparse.y b/contrib/cube/cubeparse.y index b39fbe63e6b..fd56d0e1628 100644 --- a/contrib/cube/cubeparse.y +++ b/contrib/cube/cubeparse.y @@ -11,6 +11,10 @@ #include "utils/float.h" #include "varatt.h" +/* silence -Wmissing-variable-declarations */ +extern int cube_yychar; +extern int cube_yynerrs; + /* All grammar constructs return strings */ #define YYSTYPE char * diff --git a/contrib/seg/segparse.y b/contrib/seg/segparse.y index bf759dbbd84..729d4b6390b 100644 --- a/contrib/seg/segparse.y +++ b/contrib/seg/segparse.y @@ -13,6 +13,10 @@ #include "segdata.h" +/* silence -Wmissing-variable-declarations */ +extern int seg_yychar; +extern int seg_yynerrs; + /* * Bison doesn't allocate anything that needs to live across parser calls, * so we can easily have it use palloc instead of malloc. This prevents diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y index 3c9c1da0216..58e0878dc8d 100644 --- a/src/backend/bootstrap/bootparse.y +++ b/src/backend/bootstrap/bootparse.y @@ -33,6 +33,11 @@ #include "utils/memutils.h" +/* silence -Wmissing-variable-declarations */ +extern int boot_yychar; +extern int boot_yynerrs; + + /* * Bison doesn't allocate anything that needs to live across parser calls, * so we can easily have it use palloc instead of malloc. This prevents diff --git a/src/backend/replication/repl_gram.y b/src/backend/replication/repl_gram.y index 53780bbf297..c46ca395263 100644 --- a/src/backend/replication/repl_gram.y +++ b/src/backend/replication/repl_gram.y @@ -23,6 +23,11 @@ #include "replication/walsender_private.h" +/* silence -Wmissing-variable-declarations */ +extern int replication_yychar; +extern int replication_yynerrs; + + /* Result of the parsing is returned here */ Node *replication_parse_result; diff --git a/src/backend/replication/syncrep_gram.y b/src/backend/replication/syncrep_gram.y index a14f63b6582..5ce4f1bfe73 100644 --- a/src/backend/replication/syncrep_gram.y +++ b/src/backend/replication/syncrep_gram.y @@ -24,6 +24,10 @@ char *syncrep_parse_error_msg; static SyncRepConfigData *create_syncrep_config(const char *num_sync, List *members, uint8 syncrep_method); +/* silence -Wmissing-variable-declarations */ +extern int syncrep_yychar; +extern int syncrep_yynerrs; + /* * Bison doesn't allocate anything that needs to live across parser calls, * so we can easily have it use palloc instead of malloc. This prevents diff --git a/src/interfaces/ecpg/preproc/ecpg.header b/src/interfaces/ecpg/preproc/ecpg.header index 59502894256..571b92f6434 100644 --- a/src/interfaces/ecpg/preproc/ecpg.header +++ b/src/interfaces/ecpg/preproc/ecpg.header @@ -8,6 +8,10 @@ #include "ecpg_config.h" #include +/* silence -Wmissing-variable-declarations */ +extern int base_yychar; +extern int base_yynerrs; + /* Location tracking support --- simpler than bison's default */ #define YYLLOC_DEFAULT(Current, Rhs, N) \ do { \ diff --git a/src/pl/plpgsql/src/pl_gram.y b/src/pl/plpgsql/src/pl_gram.y index 97be9239e37..0671ff78722 100644 --- a/src/pl/plpgsql/src/pl_gram.y +++ b/src/pl/plpgsql/src/pl_gram.y @@ -27,6 +27,10 @@ #include "plpgsql.h" +/* silence -Wmissing-variable-declarations */ +extern int plpgsql_yychar; +extern int plpgsql_yynerrs; + /* Location tracking support --- simpler than bison's default */ #define YYLLOC_DEFAULT(Current, Rhs, N) \ do { \ diff --git a/src/test/isolation/specparse.y b/src/test/isolation/specparse.y index 0e8b166a53e..282a7504556 100644 --- a/src/test/isolation/specparse.y +++ b/src/test/isolation/specparse.y @@ -14,6 +14,9 @@ #include "isolationtester.h" +/* silence -Wmissing-variable-declarations */ +extern int spec_yychar; +extern int spec_yynerrs; TestSpec parseresult; /* result of parsing is left here */