plpgsql: pure parser and reentrant scanner
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 8 Jan 2025 08:20:01 +0000 (09:20 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 8 Jan 2025 08:22:57 +0000 (09:22 +0100)
commit7b27f5fd36cb3270e8ac25aefd73b552663d1392
tree26c73cd8657a90cb7b5af1a6884569dd9e3b8ba0
parentb18464fad4af6ab3e115fd0e377ac7dce706a81e
plpgsql: pure parser and reentrant scanner

The plpgsql scanner is a wrapper around the core scanner, which
already uses the flex %option reentrant.  This patch only pushes up a
few levels the place where the scanner handle is allocated.  Before,
it was allocated in pl_scanner.c in a global variable, so to the
outside the scanner was not reentrant.  Now, it is allocated in
pl_comp.c and is passed as an argument to yyparse(), similar to how it
is handled in other reentrant scanners.

Also use flex yyextra to handle context information, instead of global
variables.  Again, this uses the existing yyextra support in the core
scanner.  This complements the other changes to make the scanner
reentrant.

The bison option %pure-parser is used to make the generated parser
pure.  This happens in the usual way, since plpgsql has its own bison
parser definition.

Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
src/pl/plpgsql/src/nls.mk
src/pl/plpgsql/src/pl_comp.c
src/pl/plpgsql/src/pl_gram.y
src/pl/plpgsql/src/pl_scanner.c
src/pl/plpgsql/src/plpgsql.h