Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2a7425d

Browse files
committed
jsonpath scanner: reentrant scanner
Use the flex %option reentrant to make the generated scanner reentrant and thread-safe. Note: The parser was already pure. Simplify flex scan buffer management: Instead of constructing the buffer from pieces and then using yy_scan_buffer(), we can just use yy_scan_string(), which does the same thing internally. (Actually, we use yy_scan_bytes() here because we already have the length.) Use flex yyextra to handle context information, instead of global variables. This complements the other changes to make the scanner reentrant. Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Reviewed-by: Andreas Karlsson <andreas@proxel.se> Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
1 parent 9b25489 commit 2a7425d

File tree

4 files changed

+145
-154
lines changed

4 files changed

+145
-154
lines changed

src/backend/nls.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ GETTEXT_TRIGGERS = $(BACKEND_COMMON_GETTEXT_TRIGGERS) \
77
GUC_check_errhint \
88
write_stderr \
99
yyerror \
10-
jsonpath_yyerror:3 \
10+
jsonpath_yyerror:4 \
1111
parser_yyerror \
1212
replication_yyerror:2 \
1313
scanner_yyerror \

src/backend/utils/adt/jsonpath_gram.y

+2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ static bool makeItemLikeRegex(JsonPathParseItem *expr,
6060
%name-prefix="jsonpath_yy"
6161
%parse-param {JsonPathParseResult **result}
6262
%parse-param {struct Node *escontext}
63+
%parse-param {yyscan_t yyscanner}
6364
%lex-param {JsonPathParseResult **result}
6465
%lex-param {struct Node *escontext}
66+
%lex-param {yyscan_t yyscanner}
6567

6668
%union
6769
{

src/backend/utils/adt/jsonpath_internal.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,25 @@ typedef struct JsonPathString
2222
int total;
2323
} JsonPathString;
2424

25+
#ifndef YY_TYPEDEF_YY_SCANNER_T
26+
#define YY_TYPEDEF_YY_SCANNER_T
27+
typedef void *yyscan_t;
28+
#endif
29+
2530
#include "utils/jsonpath.h"
2631
#include "jsonpath_gram.h"
2732

2833
#define YY_DECL extern int jsonpath_yylex(YYSTYPE *yylval_param, \
2934
JsonPathParseResult **result, \
30-
struct Node *escontext)
35+
struct Node *escontext, \
36+
yyscan_t yyscanner)
3137
YY_DECL;
3238
extern int jsonpath_yyparse(JsonPathParseResult **result,
33-
struct Node *escontext);
39+
struct Node *escontext,
40+
yyscan_t yyscanner);
3441
extern void jsonpath_yyerror(JsonPathParseResult **result,
3542
struct Node *escontext,
43+
yyscan_t yyscanner,
3644
const char *message);
3745

3846
#endif /* JSONPATH_INTERNAL_H */

0 commit comments

Comments
 (0)