pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: cube: pure parser and reentrant scanner
Date: Wed, 18 Dec 2024 07:57:19 +0000
Message-ID: <E1tNovn-000A7O-04@gemulon.postgresql.org> (raw)

cube: 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.  (Actually, we
use yy_scan_bytes() here because we already have the length.)

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/802fe923e3cd4b2f51080ed1a9a0958024b00479

Modified Files
--------------
contrib/cube/cube.c      |  7 ++--
contrib/cube/cubedata.h  | 15 +++++---
contrib/cube/cubeparse.y | 15 ++++----
contrib/cube/cubescan.l  | 89 ++++++++++++++++++++++++++++--------------------
4 files changed, 74 insertions(+), 52 deletions(-)



Message-ID: <E1tNovn-000A7O-04@gemulon.postgresql.org>
Permalink:  ../E1tNovn-000A7O-04@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1tNovn-000A7O-04@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: peter@eisentraut.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: cube: pure parser and reentrant scanner
  In-Reply-To: <E1tNovn-000A7O-04@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox