From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: ecpg: refactor to eliminate cast-away-const in find_variable().
Date: Sun, 07 Dec 2025 19:32:56 +0000
Message-ID: <E1vSKV5-003JRX-2A@gemulon.postgresql.org> (raw)
ecpg: refactor to eliminate cast-away-const in find_variable().
find_variable() and its subroutines transiently scribble on the
passed-in "name" string, even though we've declared that "const".
The string is in fact temporary, so this is not very harmful,
but it's confusing and will produce compiler warnings with
late-model gcc. Rearrange the code so that instead of modifying
the given string, we make temporary copies of the parts that we
need separated out. (I used loc_alloc so that the copies are
short-lived and don't need to be freed explicitly.)
This code is poorly structured and confusing, to the point where
my first attempt to fix it was wrong. It is also under-tested,
allowing the broken v1 patch to nonetheless pass regression.
I'll restrain myself from rewriting it completely, and just add
some comments and more test cases.
We will probably want to back-patch this once gcc 15.2 becomes
more widespread, but for now just put it in master.
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/1324889.1764886170@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/4eda42e8bdf5bd3bf69576d54a45c10e7cbc3b35
Modified Files
--------------
src/interfaces/ecpg/preproc/variable.c | 133 +++++++++++++------
.../ecpg/test/expected/preproc-array_of_struct.c | 143 ++++++++++++--------
.../test/expected/preproc-array_of_struct.stderr | 88 +++++++------
.../ecpg/test/expected/preproc-pointer_to_struct.c | 144 +++++++++++++--------
.../test/expected/preproc-pointer_to_struct.stderr | 88 +++++++------
.../ecpg/test/preproc/array_of_struct.pgc | 29 ++++-
.../ecpg/test/preproc/pointer_to_struct.pgc | 30 ++++-
7 files changed, 423 insertions(+), 232 deletions(-)
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: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: ecpg: refactor to eliminate cast-away-const in find_variable().
In-Reply-To: <E1vSKV5-003JRX-2A@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