pgsql: ecpg: refactor to eliminate cast-away-const in find_variable().

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: ecpg: refactor to eliminate cast-away-const in find_variable().
Date: 2025-12-07 19:32:56
Message-ID: E1vSKV5-003JRX-2A@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)sss(dot)pgh(dot)pa(dot)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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2025-12-08 01:24:19 pgsql: Improve error messages of input functions for pg_dependencies an
Previous Message Tom Lane 2025-12-07 16:57:04 pgsql: Micro-optimize datatype conversions in datum_to_jsonb_internal.