pgsql: replication parser: pure parser and reentrant scanner

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: replication parser: pure parser and reentrant scanner
Date: 2024-12-24 15:43:29
Message-ID: E1tQ74C-0017vm-Ub@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

replication parser: 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. 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.

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(at)iki(dot)fi>
Co-authored-by: Andreas Karlsson <andreas(at)proxel(dot)se>
Reviewed-by: Andreas Karlsson <andreas(at)proxel(dot)se>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b(at)eisentraut(dot)org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e4a8fb8fefb903fe601f7415098a4fe39a14069a

Modified Files
--------------
src/backend/nls.mk | 2 +-
src/backend/replication/repl_gram.y | 9 +-
src/backend/replication/repl_scanner.l | 157 ++++++++++++++++------------
src/backend/replication/walsender.c | 11 +-
src/include/replication/walsender_private.h | 17 +--
5 files changed, 116 insertions(+), 80 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2024-12-24 17:09:42 pgsql: syncrep parser: pure parser and reentrant scanner
Previous Message Peter Eisentraut 2024-12-24 13:05:59 pgsql: Remove pgrminclude and associated scripts