From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: ecpg: re-implement preprocessor's string management. |
Date: | 2024-10-14 17:55:19 |
Message-ID: | E1t0PHs-000p5O-3c@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
ecpg: re-implement preprocessor's string management.
Most productions in the preprocessor grammar construct strings
representing SQL or C statements or fragments thereof. Instead
of returning these as <str> results of the productions, return
them as "location" values, taking advantage of Bison's flexibility
about what a location is. We aren't really giving up anything
thereby, since ecpg's error reports have always just given line
numbers, and that's tracked separately. The advantage of this
is that a single instance of the YYLLOC_DEFAULT macro can
perform all the work needed by the vast majority of productions,
including all the ones made automatically by parse.pl. This
avoids having large numbers of effectively-identical productions,
which tickles an optimization inefficiency in recent versions of
clang. (This patch reduces the compilation time for preproc.o
by more than 100-fold with clang 16, and is visibly helpful with
gcc too.) The compiled parser is noticeably smaller as well.
A disadvantage of this approach is that YYLLOC_DEFAULT is applied
before running the production's semantic action (if any). This
means it cannot use the method favored by cat_str() of free'ing
all the input strings; if the action needs to look at the input
strings, it'd be looking at dangling storage. As this stands,
therefore, it leaks memory like a sieve. This is already a big
patch though, and fixing the memory management seems like a
separable problem, so let's leave that for the next step.
(This does remove some free() calls that I'd have had to touch
anyway, in the expectation that the next step will manage
memory reclamation quite differently.)
Most of the changes here are mindless substitution of "@N" for
"$N" in grammar rules; see the changes to README.parser for
an explanation.
Discussion: https://postgr.es/m/2011420.1713493114@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/a542d5614bdb6430094556162b9ca2f01d35f9dc
Modified Files
--------------
src/interfaces/ecpg/preproc/README.parser | 32 +-
src/interfaces/ecpg/preproc/ecpg.addons | 294 +++----
src/interfaces/ecpg/preproc/ecpg.header | 63 +-
src/interfaces/ecpg/preproc/ecpg.trailer | 1148 ++++++++++----------------
src/interfaces/ecpg/preproc/ecpg.type | 127 ---
src/interfaces/ecpg/preproc/output.c | 16 +-
src/interfaces/ecpg/preproc/parse.pl | 215 +----
src/interfaces/ecpg/preproc/parser.c | 58 +-
src/interfaces/ecpg/preproc/preproc_extern.h | 15 +-
9 files changed, 752 insertions(+), 1216 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Davis | 2024-10-14 19:15:09 | pgsql: Move ICU-specific code from pg_locale.c into pg_locale_icu.c. |
Previous Message | Masahiko Sawada | 2024-10-14 16:53:44 | pgsql: Remove obsolete comment in reorderbuffer.h. |