pgsql: Change copyObject() to use typeof_unqual

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Change copyObject() to use typeof_unqual
Date: 2026-02-04 08:24:53
Message-ID: E1vnYBx-0013wO-0p@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Change copyObject() to use typeof_unqual

Currently, when the argument of copyObject() is const-qualified, the
return type is also, because the use of typeof carries over all the
qualifiers. This is incorrect, since the point of copyObject() is to
make a copy to mutate. But apparently no code ran into it.

The new implementation uses typeof_unqual, which drops the qualifiers,
making this work correctly.

typeof_unqual is standardized in C23, but all recent versions of all
the usual compilers support it even in non-C23 mode, at least as
__typeof_unqual__. We add a configure/meson test for typeof_unqual
and __typeof_unqual__ and use it if it's available, else we use the
existing fallback of just returning void *.

Reviewed-by: David Geier <geidav(dot)pg(at)gmail(dot)com>
Discussion: https://www.postgresql.org/message-id/flat/92f9750f-c7f6-42d8-9a4a-85a3cbe808f3%40eisentraut.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4cfce4e62c8f09f5b1f6a7f69760ca46a74406e2

Modified Files
--------------
config/c-compiler.m4 | 25 +++++++++++++++++++++++++
configure | 42 ++++++++++++++++++++++++++++++++++++++++++
configure.ac | 1 +
meson.build | 24 ++++++++++++++++++++++++
src/include/nodes/nodes.h | 4 ++--
src/include/pg_config.h.in | 7 +++++++
6 files changed, 101 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-02-04 11:08:18 pgsql: Add backendType to PGPROC, replacing isRegularBackend
Previous Message Michael Paquier 2026-02-04 07:38:52 pgsql: pg_resetwal: Fix incorrect error message related to pg_wal/summa