Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb6afae7

Browse files
committed
Use %option bison-bridge in psql/pgbench lexers.
The point of this change is to use %pure-parser in pgbench's exprparse.y.The immediate reason is that it turns out very ancient versions of bisonhave a bug with the combination of a reentrant lexer and non-reentrantparser. We could consider dropping support for such ancient bisons; butconsidering that we might well need exprparse.y to be reentrant some day,it seems better to make it so right now than to move the portabilitygoalposts. (AFAICT there's no particular performance consequence to thischange, either, so there's no good reason not to do it.)Now, %pure-parser assumes that the called lexer is built with %optionbison-bridge. Because we're assuming bitwise compatibility of yyscan_t(yyguts_t) data structures among all the psql/pgbench lexers, thatrequirement propagates back to psql's lexers as well. But it's just afew lines of change on that side too; and if psqlscan.l is to set thebaseline for a possibly-large family of lexers, it should err on theside of including not omitting useful features.
1 parent6f1f34c commitb6afae7

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

‎src/bin/pgbench/exprparse.y

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static PgBenchExpr *make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *
2828

2929
%}
3030

31+
%pure-parser
3132
%expect0
3233
%name-prefix="expr_yy"
3334

@@ -263,5 +264,7 @@ make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args)
263264

264265
/* First, get rid of "#define yyscan_t" from pgbench.h*/
265266
#undef yyscan_t
267+
/* ... and the yylval macro, which flex will have its own definition for*/
268+
#undef yylval
266269

267270
#include"exprscan.c"

‎src/bin/pgbench/exprscan.l

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ extern void expr_yyset_column(int column_no, yyscan_t yyscanner);
4747

4848
/* Except for the prefix, these options should match psqlscan.l */
4949
%optionreentrant
50+
%optionbison-bridge
5051
%option8bit
5152
%optionnever-interactive
5253
%optionnodefault
@@ -117,15 +118,15 @@ newline[\n]
117118
","{return','; }
118119

119120
:{alnum}+{
120-
yylval.str =pg_strdup(yytext +1);
121+
yylval->str =pg_strdup(yytext +1);
121122
return VARIABLE;
122123
}
123124
{digit}+{
124-
yylval.ival =strtoint64(yytext);
125+
yylval->ival =strtoint64(yytext);
125126
return INTEGER;
126127
}
127128
{alpha}{alnum}*{
128-
yylval.str =pg_strdup(yytext);
129+
yylval->str =pg_strdup(yytext);
129130
return FUNCTION;
130131
}
131132

@@ -169,6 +170,7 @@ expr_yyerror_more(yyscan_t yyscanner, const char *message, const char *more)
169170
{
170171
PsqlScanState state =yyget_extra(yyscanner);
171172
interror_detection_offset =expr_scanner_offset(state) -1;
173+
YYSTYPElval;
172174
char *full_line;
173175
size_tl;
174176

@@ -179,7 +181,7 @@ expr_yyerror_more(yyscan_t yyscanner, const char *message, const char *more)
179181
*/
180182
if (!last_was_newline)
181183
{
182-
while (yylex(yyscanner))
184+
while (yylex(&lval,yyscanner))
183185
/* skip */ ;
184186
}
185187

@@ -210,6 +212,7 @@ bool
210212
expr_lex_one_word(PsqlScanState state, PQExpBuffer word_buf,int *offset)
211213
{
212214
intlexresult;
215+
YYSTYPElval;
213216

214217
/* Must be scanning already */
215218
Assert(state->scanbufhandle !=NULL);
@@ -228,7 +231,7 @@ expr_lex_one_word(PsqlScanState state, PQExpBuffer word_buf, int *offset)
228231
state->start_state = INITIAL;
229232

230233
/* And lex. */
231-
lexresult =yylex(state->scanner);
234+
lexresult =yylex(&lval,state->scanner);
232235

233236
/*
234237
* Save start offset of word, if any. We could do this more efficiently,

‎src/bin/pgbench/pgbench.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@
1717
* This file is included outside exprscan.l, in places where we can't see
1818
* flex's definition of typedef yyscan_t. Fortunately, it's documented as
1919
* being "void *", so we can use a macro to keep the function declarations
20-
* here looking like the definitions in exprscan.l. exprparse.yalso
21-
*uses this to be able to declare things as "yyscan_t".
20+
* here looking like the definitions in exprscan.l. exprparse.yand
21+
*pgbench.c also use this to be able to declare things as "yyscan_t".
2222
*/
2323
#defineyyscan_t void *
2424

25+
/*
26+
* Likewise, we can't see exprparse.y's definition of union YYSTYPE here,
27+
* but for now there's no need to know what the union contents are.
28+
*/
29+
unionYYSTYPE;
30+
2531
/* Types of expression nodes */
2632
typedefenumPgBenchExprType
2733
{
@@ -85,7 +91,7 @@ struct PgBenchExprList
8591
externPgBenchExpr*expr_parse_result;
8692

8793
externintexpr_yyparse(yyscan_tyyscanner);
88-
externintexpr_yylex(yyscan_tyyscanner);
94+
externintexpr_yylex(unionYYSTYPE*lvalp,yyscan_tyyscanner);
8995
externvoidexpr_yyerror(yyscan_tyyscanner,constchar*str)pg_attribute_noreturn();
9096
externvoidexpr_yyerror_more(yyscan_tyyscanner,constchar*str,
9197
constchar*more)pg_attribute_noreturn();

‎src/bin/psql/psqlscan.l

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
%{
3636
#include"psqlscan_int.h"
3737

38+
/*
39+
* We must have a typedef YYSTYPE for yylex's first argument, but this lexer
40+
* doesn't presently make use of that argument, so just declare it as int.
41+
*/
42+
typedefint YYSTYPE;
43+
3844
/*
3945
* Set the type of yyextra; we use it as a pointer back to the containing
4046
* PsqlScanState.
@@ -64,6 +70,7 @@ extern void psql_yyset_column(int column_no, yyscan_t yyscanner);
6470
%}
6571

6672
%optionreentrant
73+
%optionbison-bridge
6774
%option8bit
6875
%optionnever-interactive
6976
%optionnodefault
@@ -1002,7 +1009,7 @@ psql_scan(PsqlScanState state,
10021009
yy_switch_to_buffer(state->scanbufhandle, state->scanner);
10031010

10041011
/* And lex. */
1005-
lexresult =yylex(state->scanner);
1012+
lexresult =yylex(NULL,state->scanner);
10061013

10071014
/*
10081015
* Check termination state and return appropriate result info.

‎src/bin/psql/psqlscanslash.l

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
%{
2727
#include"psqlscan_int.h"
2828

29+
/*
30+
* We must have a typedef YYSTYPE for yylex's first argument, but this lexer
31+
* doesn't presently make use of that argument, so just declare it as int.
32+
*/
33+
typedefint YYSTYPE;
34+
2935
/*
3036
* Set the type of yyextra; we use it as a pointer back to the containing
3137
* PsqlScanState.
@@ -62,7 +68,9 @@ extern void slash_yyset_column(int column_no, yyscan_t yyscanner);
6268

6369
%}
6470

71+
/* Except for the prefix, these options should match psqlscan.l */
6572
%optionreentrant
73+
%optionbison-bridge
6674
%option8bit
6775
%optionnever-interactive
6876
%optionnodefault
@@ -447,7 +455,7 @@ psql_scan_slash_command(PsqlScanState state)
447455
state->start_state = xslashcmd;
448456

449457
/* And lex. */
450-
yylex(state->scanner);
458+
yylex(NULL,state->scanner);
451459

452460
/* There are no possible errors in this lex state... */
453461

@@ -521,7 +529,7 @@ psql_scan_slash_option(PsqlScanState state,
521529
state->start_state = xslashargstart;
522530

523531
/* And lex. */
524-
lexresult =yylex(state->scanner);
532+
lexresult =yylex(NULL,state->scanner);
525533

526534
/* Save final state for a moment... */
527535
final_state = state->start_state;
@@ -648,7 +656,7 @@ psql_scan_slash_command_end(PsqlScanState state)
648656
state->start_state = xslashend;
649657

650658
/* And lex. */
651-
yylex(state->scanner);
659+
yylex(NULL,state->scanner);
652660

653661
/* There are no possible errors in this lex state... */
654662

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp