From 6fdd5d9563439285df200f7282f0ca68152ef72d Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 15 Jan 2025 15:35:08 +0100 Subject: [PATCH] Drop warning-free support for Flex 2.5.35 This removes all the various workarounds for avoiding compiler warnings with Flex 2.5.35. Several recent patches have added additional warnings that would either need to be fixed along the lines of the existing workarounds, or we decide to no longer care about this, which we do here. Flex 2.5.35 is extremely outdated, and you can't even download it anymore from any of the Flex project sites, so it's nearly impossible to support. After this, using Flex 2.5.35 will still work, but the generated code will produce numerous compiler warnings. Reviewed-by: Tom Lane Discussion: https://www.postgresql.org/message-id/1a204ccd-7ae6-478c-a431-407b5c48ccc6@eisentraut.org --- src/Makefile.global.in | 1 - src/backend/parser/Makefile | 1 - src/backend/parser/meson.build | 2 +- src/backend/parser/scan.l | 9 ----- src/bin/pgbench/exprscan.l | 9 ----- src/bin/psql/Makefile | 1 - src/bin/psql/meson.build | 2 +- src/bin/psql/psqlscanslash.l | 9 ----- src/fe_utils/Makefile | 1 - src/fe_utils/meson.build | 2 +- src/fe_utils/psqlscan.l | 9 ----- src/tools/fix-old-flex-code.pl | 66 ---------------------------------- src/tools/pgflex | 13 ------- 13 files changed, 3 insertions(+), 122 deletions(-) delete mode 100644 src/tools/fix-old-flex-code.pl diff --git a/src/Makefile.global.in b/src/Makefile.global.in index eac3d00121..1278b7744f 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -788,7 +788,6 @@ TAS = @TAS@ %.c: %.l $(FLEX) $(if $(FLEX_NO_BACKUP),-b) $(FLEXFLAGS) -o'$@' $< @$(if $(FLEX_NO_BACKUP),if [ `wc -l &2; exit 1; fi) - $(if $(FLEX_FIX_WARNING),$(PERL) $(top_srcdir)/src/tools/fix-old-flex-code.pl '$@') %.c: %.y $(if $(BISON_CHECK_CMD),$(BISON_CHECK_CMD)) diff --git a/src/backend/parser/Makefile b/src/backend/parser/Makefile index 3162a01f30..8c0fe28d63 100644 --- a/src/backend/parser/Makefile +++ b/src/backend/parser/Makefile @@ -59,7 +59,6 @@ gram.c: BISON_CHECK_CMD = $(PERL) $(srcdir)/check_keywords.pl $< $(top_srcdir)/s scan.c: FLEXFLAGS = -CF -p -p scan.c: FLEX_NO_BACKUP=yes -scan.c: FLEX_FIX_WARNING=yes # Force these dependencies to be known even without dependency info built: diff --git a/src/backend/parser/meson.build b/src/backend/parser/meson.build index 4c3ca25dd4..874aa749aa 100644 --- a/src/backend/parser/meson.build +++ b/src/backend/parser/meson.build @@ -30,7 +30,7 @@ parser_sources = files('parser.c') backend_scanner = custom_target('scan', input: 'scan.l', output: 'scan.c', - command: [flex_cmd, '--no-backup', '--fix-warnings', '--', '-CF', '-p', '-p'], + command: [flex_cmd, '--no-backup', '--', '-CF', '-p', '-p'], ) generated_sources += backend_scanner parser_sources += backend_scanner diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l index 8031a78b90..08990831fe 100644 --- a/src/backend/parser/scan.l +++ b/src/backend/parser/scan.l @@ -130,15 +130,6 @@ static void addunicode(pg_wchar c, yyscan_t yyscanner); static void check_string_escape_warning(unsigned char ychar, core_yyscan_t yyscanner); static void check_escape_warning(core_yyscan_t yyscanner); -/* - * Work around a bug in flex 2.5.35: it emits a couple of functions that - * it forgets to emit declarations for. Since we use -Wmissing-prototypes, - * this would cause warnings. Providing our own declarations should be - * harmless even when the bug gets fixed. - */ -extern int core_yyget_column(yyscan_t yyscanner); -extern void core_yyset_column(int column_no, yyscan_t yyscanner); - %} %option reentrant diff --git a/src/bin/pgbench/exprscan.l b/src/bin/pgbench/exprscan.l index a1cd232248..46f6ea0512 100644 --- a/src/bin/pgbench/exprscan.l +++ b/src/bin/pgbench/exprscan.l @@ -44,15 +44,6 @@ static const char *expr_command = NULL; /* indicates whether last yylex() call read a newline */ static bool last_was_newline = false; -/* - * Work around a bug in flex 2.5.35: it emits a couple of functions that - * it forgets to emit declarations for. Since we use -Wmissing-prototypes, - * this would cause warnings. Providing our own declarations should be - * harmless even when the bug gets fixed. - */ -extern int expr_yyget_column(yyscan_t yyscanner); -extern void expr_yyset_column(int column_no, yyscan_t yyscanner); - /* LCOV_EXCL_START */ %} diff --git a/src/bin/psql/Makefile b/src/bin/psql/Makefile index e9e4ade1d2..5b1545d994 100644 --- a/src/bin/psql/Makefile +++ b/src/bin/psql/Makefile @@ -60,7 +60,6 @@ sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml) psqlscanslash.c: FLEXFLAGS = -Cfe -p -p psqlscanslash.c: FLEX_NO_BACKUP=yes -psqlscanslash.c: FLEX_FIX_WARNING=yes tab-complete.c: gen_tabcomplete.pl tab-complete.in.c $(PERL) $^ --outfile $@ diff --git a/src/bin/psql/meson.build b/src/bin/psql/meson.build index c2ef14ccea..f795ff2827 100644 --- a/src/bin/psql/meson.build +++ b/src/bin/psql/meson.build @@ -19,7 +19,7 @@ psql_sources = files( psqlscanslash = custom_target('psqlscanslash', input: 'psqlscanslash.l', output: 'psqlscanslash.c', - command: [flex_cmd, '--no-backup', '--fix-warnings', '--', '-Cfe', '-p', '-p']) + command: [flex_cmd, '--no-backup', '--', '-Cfe', '-p', '-p']) generated_sources += psqlscanslash psql_sources += psqlscanslash diff --git a/src/bin/psql/psqlscanslash.l b/src/bin/psql/psqlscanslash.l index f76b7722ac..ae7602a61d 100644 --- a/src/bin/psql/psqlscanslash.l +++ b/src/bin/psql/psqlscanslash.l @@ -57,15 +57,6 @@ static void evaluate_backtick(PsqlScanState state); #define ECHO psqlscan_emit(cur_state, yytext, yyleng) -/* - * Work around a bug in flex 2.5.35: it emits a couple of functions that - * it forgets to emit declarations for. Since we use -Wmissing-prototypes, - * this would cause warnings. Providing our own declarations should be - * harmless even when the bug gets fixed. - */ -extern int slash_yyget_column(yyscan_t yyscanner); -extern void slash_yyset_column(int column_no, yyscan_t yyscanner); - /* LCOV_EXCL_START */ %} diff --git a/src/fe_utils/Makefile b/src/fe_utils/Makefile index f9ca5de280..28196ce0f6 100644 --- a/src/fe_utils/Makefile +++ b/src/fe_utils/Makefile @@ -51,7 +51,6 @@ libpgfeutils.a: $(OBJS) psqlscan.c: FLEXFLAGS = -Cfe -p -p psqlscan.c: FLEX_NO_BACKUP=yes -psqlscan.c: FLEX_FIX_WARNING=yes # libpgfeutils could be useful to contrib, so install it install: all installdirs diff --git a/src/fe_utils/meson.build b/src/fe_utils/meson.build index 171268d65e..a18cbc939e 100644 --- a/src/fe_utils/meson.build +++ b/src/fe_utils/meson.build @@ -23,7 +23,7 @@ fe_utils_sources = files( psqlscan = custom_target('psqlscan', input: 'psqlscan.l', output: 'psqlscan.c', - command: [flex_cmd, '--no-backup', '--fix-warnings', '--', '-Cfe', '-p', '-p'], + command: [flex_cmd, '--no-backup', '--', '-Cfe', '-p', '-p'], ) generated_sources += psqlscan fe_utils_sources += psqlscan diff --git a/src/fe_utils/psqlscan.l b/src/fe_utils/psqlscan.l index e1cb726f32..b3c6b88e9c 100644 --- a/src/fe_utils/psqlscan.l +++ b/src/fe_utils/psqlscan.l @@ -61,15 +61,6 @@ typedef int YYSTYPE; #define ECHO psqlscan_emit(cur_state, yytext, yyleng) -/* - * Work around a bug in flex 2.5.35: it emits a couple of functions that - * it forgets to emit declarations for. Since we use -Wmissing-prototypes, - * this would cause warnings. Providing our own declarations should be - * harmless even when the bug gets fixed. - */ -extern int psql_yyget_column(yyscan_t yyscanner); -extern void psql_yyset_column(int column_no, yyscan_t yyscanner); - %} %option reentrant diff --git a/src/tools/fix-old-flex-code.pl b/src/tools/fix-old-flex-code.pl deleted file mode 100644 index c1c91db114..0000000000 --- a/src/tools/fix-old-flex-code.pl +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/perl -#---------------------------------------------------------------------- -# -# fix-old-flex-code.pl -# -# flex versions before 2.5.36, with certain option combinations, produce -# code that causes an "unused variable" warning. That's annoying, so -# let's suppress it by inserting a dummy reference to the variable. -# (That's exactly what 2.5.36 and later do ...) -# -# Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group -# Portions Copyright (c) 1994, Regents of the University of California -# -# src/tools/fix-old-flex-code.pl -# -#---------------------------------------------------------------------- - -use strict; -use warnings FATAL => 'all'; - -# Get command line argument. -usage() if $#ARGV != 0; -my $filename = shift; - -# Suck in the whole file. -local $/ = undef; -my $cfile; -open($cfile, '<', $filename) || die "opening $filename for reading: $!"; -my $ccode = <$cfile>; -close($cfile); - -# No need to do anything if it's not flex 2.5.x for x < 36. -exit 0 if $ccode !~ m/^#define YY_FLEX_MAJOR_VERSION 2$/m; -exit 0 if $ccode !~ m/^#define YY_FLEX_MINOR_VERSION 5$/m; -exit 0 if $ccode !~ m/^#define YY_FLEX_SUBMINOR_VERSION (\d+)$/m; -exit 0 if $1 >= 36; - -# Apply the desired patch. -$ccode =~ - s|(struct yyguts_t \* yyg = \(struct yyguts_t\*\)yyscanner; /\* This var may be unused depending upon options. \*/ -.*?) - return yy_is_jam \? 0 : yy_current_state; -|$1 - (void) yyg; - return yy_is_jam ? 0 : yy_current_state; -|s; - -# Write the modified file back out. -open($cfile, '>', $filename) || die "opening $filename for writing: $!"; -print $cfile $ccode; -close($cfile); - -exit 0; - - -sub usage -{ - die <. -EOM -} diff --git a/src/tools/pgflex b/src/tools/pgflex index baabe2df1c..3986b06874 100755 --- a/src/tools/pgflex +++ b/src/tools/pgflex @@ -4,7 +4,6 @@ # Wrapper around flex that: # - ensures lex.backup is created in a private directory # - can error out if lex.backup is created (--no-backup) -# - can fix warnings (--fix-warnings) # - works around concurrency issues with win_flex.exe: # https://github.com/lexxmark/winflexbison/issues/86 @@ -28,8 +27,6 @@ parser.add_argument('-o', dest='output_file', type=abspath, required=True, parser.add_argument('-i', dest='input_file', type=abspath, help='input file') -parser.add_argument('--fix-warnings', action='store_true', - help='whether to fix warnings in generated file') parser.add_argument('--no-backup', action='store_true', help='whether no_backup is enabled or not') @@ -72,14 +69,4 @@ if args.no_backup: sys.exit('Scanner requires backup; see lex.backup.') os.remove('lex.backup') -# fix warnings -if args.fix_warnings: - fix_warning_script = os.path.join(args.srcdir, - 'src/tools/fix-old-flex-code.pl') - - command = [args.perl, fix_warning_script, args.output_file] - sp = subprocess.run(command) - if sp.returncode != 0: - sys.exit(sp.returncode) - sys.exit(0) -- 2.39.5