v3-0001-flex-code-modernization-Replace-YY_EXTRA_TYPE-def.patch

text/plain

Filename: v3-0001-flex-code-modernization-Replace-YY_EXTRA_TYPE-def.patch
Type: text/plain
Part: 0
Message: Re: pure parsers and reentrant scanners

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v3-0001
Subject: flex code modernization: Replace YY_EXTRA_TYPE define with flex option
File+
src/backend/parser/scan.l 1 6
src/backend/replication/repl_scanner.l 1 1
src/backend/replication/syncrep_scanner.l 1 1
src/backend/utils/adt/jsonpath_scan.l 1 1
src/bin/psql/psqlscanslash.l 6 6
src/fe_utils/psqlscan.l 6 6
From 8987797444ec2fc6c8f920b3e46d6f12d2cbf864 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 26 Dec 2024 11:41:21 +0100
Subject: [PATCH v3 1/4] flex code modernization: Replace YY_EXTRA_TYPE define
 with flex option

Replace #define YY_EXTRA_TYPE with %option extra-type.  The latter is
the way recommended by the flex manual (available since flex 2.5.34).
---
 src/backend/parser/scan.l                 |  7 +------
 src/backend/replication/repl_scanner.l    |  2 +-
 src/backend/replication/syncrep_scanner.l |  2 +-
 src/backend/utils/adt/jsonpath_scan.l     |  2 +-
 src/bin/psql/psqlscanslash.l              | 12 ++++++------
 src/fe_utils/psqlscan.l                   | 12 ++++++------
 6 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index a152cff4117..7808e1c1484 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -89,12 +89,6 @@ const uint16 ScanKeywordTokens[] = {
  */
 #define YYSTYPE core_YYSTYPE
 
-/*
- * Set the type of yyextra.  All state variables used by the scanner should
- * be in yyextra, *not* statically allocated.
- */
-#define YY_EXTRA_TYPE core_yy_extra_type *
-
 /*
  * Each call to yylex must set yylloc to the location of the found token
  * (expressed as a byte offset from the start of the input text).
@@ -161,6 +155,7 @@ extern void core_yyset_column(int column_no, yyscan_t yyscanner);
 %option noyyfree
 %option warn
 %option prefix="core_yy"
+%option extra-type="core_yy_extra_type *"
 
 /*
  * OK, here is a short description of lex/flex rules behavior.
diff --git a/src/backend/replication/repl_scanner.l b/src/backend/replication/repl_scanner.l
index 14684c6f61e..9fa2f191abb 100644
--- a/src/backend/replication/repl_scanner.l
+++ b/src/backend/replication/repl_scanner.l
@@ -46,7 +46,6 @@ struct replication_yy_extra_type
 	/* Work area for collecting literals */
 	StringInfoData litbuf;
 };
-#define YY_EXTRA_TYPE struct replication_yy_extra_type *
 
 static void startlit(yyscan_t yyscanner);
 static char *litbufdup(yyscan_t yyscanner);
@@ -70,6 +69,7 @@ static void addlitchar(unsigned char ychar, yyscan_t yyscanner);
 %option noyyfree
 %option warn
 %option prefix="replication_yy"
+%option extra-type="struct replication_yy_extra_type *"
 
 /*
  * Exclusive states:
diff --git a/src/backend/replication/syncrep_scanner.l b/src/backend/replication/syncrep_scanner.l
index fe4a41b3f20..170f8d5665f 100644
--- a/src/backend/replication/syncrep_scanner.l
+++ b/src/backend/replication/syncrep_scanner.l
@@ -41,7 +41,6 @@ struct syncrep_yy_extra_type
 {
 	StringInfoData xdbuf;
 };
-#define YY_EXTRA_TYPE struct syncrep_yy_extra_type *
 
 /* LCOV_EXCL_START */
 
@@ -60,6 +59,7 @@ struct syncrep_yy_extra_type
 %option noyyfree
 %option warn
 %option prefix="syncrep_yy"
+%option extra-type="struct syncrep_yy_extra_type *"
 
 /*
  * <xd> delimited identifiers (double-quoted identifiers)
diff --git a/src/backend/utils/adt/jsonpath_scan.l b/src/backend/utils/adt/jsonpath_scan.l
index 268c139f01b..3bd7e594117 100644
--- a/src/backend/utils/adt/jsonpath_scan.l
+++ b/src/backend/utils/adt/jsonpath_scan.l
@@ -34,7 +34,6 @@ struct jsonpath_yy_extra_type
 {
 	JsonPathString scanstring;
 };
-#define YY_EXTRA_TYPE struct jsonpath_yy_extra_type *
 
 static void addstring(bool init, char *s, int l, yyscan_t yyscanner);
 static void addchar(bool init, char c, yyscan_t yyscanner);
@@ -64,6 +63,7 @@ fprintf_to_ereport(const char *fmt, const char *msg)
 %option noyywrap
 %option warn
 %option prefix="jsonpath_yy"
+%option extra-type="struct jsonpath_yy_extra_type *"
 %option reentrant
 %option bison-bridge
 %option noyyalloc
diff --git a/src/bin/psql/psqlscanslash.l b/src/bin/psql/psqlscanslash.l
index cfce9038016..0cf12805788 100644
--- a/src/bin/psql/psqlscanslash.l
+++ b/src/bin/psql/psqlscanslash.l
@@ -38,12 +38,6 @@
  */
 typedef int YYSTYPE;
 
-/*
- * Set the type of yyextra; we use it as a pointer back to the containing
- * PsqlScanState.
- */
-#define YY_EXTRA_TYPE PsqlScanState
-
 /*
  * These variables do not need to be saved across calls.  Yeah, it's a bit
  * of a hack, but putting them into PsqlScanStateData would be klugy too.
@@ -88,6 +82,12 @@ extern void slash_yyset_column(int column_no, yyscan_t yyscanner);
 %option warn
 %option prefix="slash_yy"
 
+/*
+ * Set the type of yyextra; we use it as a pointer back to the containing
+ * PsqlScanState.
+ */
+%option extra-type="PsqlScanState"
+
 /*
  * OK, here is a short description of lex/flex rules behavior.
  * The longest pattern which matches an input string is always chosen.
diff --git a/src/fe_utils/psqlscan.l b/src/fe_utils/psqlscan.l
index 0e40be994a8..b1a60a99a94 100644
--- a/src/fe_utils/psqlscan.l
+++ b/src/fe_utils/psqlscan.l
@@ -52,12 +52,6 @@
  */
 typedef int YYSTYPE;
 
-/*
- * Set the type of yyextra; we use it as a pointer back to the containing
- * PsqlScanState.
- */
-#define YY_EXTRA_TYPE PsqlScanState
-
 
 /* Return values from yylex() */
 #define LEXRES_EOL			0	/* end of input */
@@ -89,6 +83,12 @@ extern void psql_yyset_column(int column_no, yyscan_t yyscanner);
 %option warn
 %option prefix="psql_yy"
 
+/*
+ * Set the type of yyextra; we use it as a pointer back to the containing
+ * PsqlScanState.
+ */
+%option extra-type="PsqlScanState"
+
 /*
  * All of the following definitions and rules should exactly match
  * src/backend/parser/scan.l so far as the flex patterns are concerned.

base-commit: 3f2d72b4934945da76f6bc60dfe3fc5ca42e7526
-- 
2.47.1