mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
seg: pure parser and reentrant scanner
Use the flex %option reentrant and the bison option %pure-parser to make the generated scanner and parser pure, reentrant, and thread-safe. Make the generated scanner use palloc() etc. instead of malloc() etc. Previously, we only used palloc() for the buffer, but flex would still use malloc() for its internal structures. As a result, there could be some small memory leaks in case of uncaught errors. (We do catch normal syntax errors as soft errors.) Now, all the memory is under palloc() control, so there are no more such issues. 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. The previous code was necessary because we allocated the buffer with palloc() and the rest of the state was handled by malloc(). But this is no longer the case; everything is under palloc() now. (We could even get rid of the yylex_destroy() call and just let the memory context cleanup handle everything. But for now, we preserve the existing behavior.) 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
This commit is contained in:
@ -14,10 +14,6 @@
|
||||
#include "segdata.h"
|
||||
#include "segparse.h"
|
||||
|
||||
/* silence -Wmissing-variable-declarations */
|
||||
extern int seg_yychar;
|
||||
extern int seg_yynerrs;
|
||||
|
||||
/*
|
||||
* Bison doesn't allocate anything that needs to live across parser calls,
|
||||
* so we can easily have it use palloc instead of malloc. This prevents
|
||||
@ -35,6 +31,9 @@ static int sig_digits(const char *value);
|
||||
/* BISON Declarations */
|
||||
%parse-param {SEG *result}
|
||||
%parse-param {struct Node *escontext}
|
||||
%parse-param {yyscan_t yyscanner}
|
||||
%lex-param {yyscan_t yyscanner}
|
||||
%pure-parser
|
||||
%expect 0
|
||||
%name-prefix="seg_yy"
|
||||
|
||||
@ -72,6 +71,8 @@ range: boundary PLUMIN deviation
|
||||
result->u_sigd = Max(sig_digits(strbuf), Max($1.sigd, $3.sigd));
|
||||
result->l_ext = '\0';
|
||||
result->u_ext = '\0';
|
||||
|
||||
(void) yynerrs; /* suppress compiler warning */
|
||||
}
|
||||
|
||||
| boundary RANGE boundary
|
||||
|
Reference in New Issue
Block a user