From 2a7425d7eef9b4b848763fb920fefa23c3c43f31 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 24 Dec 2024 23:42:41 +0100 Subject: 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 Reviewed-by: Andreas Karlsson Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org --- src/backend/utils/adt/jsonpath_internal.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/backend/utils/adt/jsonpath_internal.h') diff --git a/src/backend/utils/adt/jsonpath_internal.h b/src/backend/utils/adt/jsonpath_internal.h index 6cd6d8b652d..dbb5e67fe2b 100644 --- a/src/backend/utils/adt/jsonpath_internal.h +++ b/src/backend/utils/adt/jsonpath_internal.h @@ -22,17 +22,25 @@ typedef struct JsonPathString int total; } JsonPathString; +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void *yyscan_t; +#endif + #include "utils/jsonpath.h" #include "jsonpath_gram.h" #define YY_DECL extern int jsonpath_yylex(YYSTYPE *yylval_param, \ JsonPathParseResult **result, \ - struct Node *escontext) + struct Node *escontext, \ + yyscan_t yyscanner) YY_DECL; extern int jsonpath_yyparse(JsonPathParseResult **result, - struct Node *escontext); + struct Node *escontext, + yyscan_t yyscanner); extern void jsonpath_yyerror(JsonPathParseResult **result, struct Node *escontext, + yyscan_t yyscanner, const char *message); #endif /* JSONPATH_INTERNAL_H */ -- cgit v1.2.3