From 0b5c772dd5ce8bf9a32e5072adc64798ca63b0ae Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 2 Dec 2024 10:35:37 +0100 Subject: [PATCH v0 13/15] syncrep parser: Use flex yyextra Use flex yyextra to handle context information, instead of global variables. This complements the earlier patch to make the scanner reentrant. --- src/backend/replication/syncrep_scanner.l | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/backend/replication/syncrep_scanner.l b/src/backend/replication/syncrep_scanner.l index 9c0f4fc2c19..85ae4e60604 100644 --- a/src/backend/replication/syncrep_scanner.l +++ b/src/backend/replication/syncrep_scanner.l @@ -37,7 +37,11 @@ fprintf_to_ereport(const char *fmt, const char *msg) ereport(ERROR, (errmsg_internal("%s", msg))); } -static StringInfoData xdbuf; /* FIXME */ +struct syncrep_yy_extra_type +{ + StringInfoData xdbuf; +}; +#define YY_EXTRA_TYPE struct syncrep_yy_extra_type * /* LCOV_EXCL_START */ @@ -84,18 +88,18 @@ xdinside [^"]+ [Ff][Ii][Rr][Ss][Tt] { return FIRST; } {xdstart} { - initStringInfo(&xdbuf); + initStringInfo(&yyextra->xdbuf); BEGIN(xd); } {xddouble} { - appendStringInfoChar(&xdbuf, '"'); + appendStringInfoChar(&yyextra->xdbuf, '"'); } {xdinside} { - appendStringInfoString(&xdbuf, yytext); + appendStringInfoString(&yyextra->xdbuf, yytext); } {xdstop} { - yylval->str = xdbuf.data; - xdbuf.data = NULL; + yylval->str = yyextra->xdbuf.data; + yyextra->xdbuf.data = NULL; BEGIN(INITIAL); return NAME; } @@ -149,12 +153,15 @@ void syncrep_scanner_init(const char *str, yyscan_t *yyscannerp) { yyscan_t yyscanner; + struct syncrep_yy_extra_type yyext; if (yylex_init(yyscannerp) != 0) elog(ERROR, "yylex_init() failed: %m"); yyscanner = *yyscannerp; + yyset_extra(&yyext, yyscanner); + yy_scan_string(str, yyscanner); } -- 2.47.1