pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Change copyObject() to use typeof_unqual
2+ messages / 1 participants
[nested] [flat]

* pgsql: Change copyObject() to use typeof_unqual
@ 2026-02-04 08:24  Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Peter Eisentraut @ 2026-02-04 08:24 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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.pg@gmail.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(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Change copyObject() to use typeof_unqual
@ 2026-03-13 06:14  Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Peter Eisentraut @ 2026-03-13 06:14 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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 *.

This is the second attempt, after the first attempt in commit
4cfce4e62c8 was reverted.  The following two points address problems
with the earlier version:

We test the underscore variant first so that there is a higher chance
that clang used for bitcode also supports it, since we don't test that
separately.

Unlike the typeof test, the typeof_unqual test also tests with a void
pointer similar to how copyObject() would use it, because that is not
handled by MSVC, so we want the test to fail there.

Reviewed-by: David Geier <geidav.pg@gmail.com>
Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl>
Discussion: https://www.postgresql.org/message-id/flat/92f9750f-c7f6-42d8-9a4a-85a3cbe808f3%40eisentraut.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/59292f7aac72305f8e47f19155e6c7e0a070acb9

Modified Files
--------------
config/c-compiler.m4                               |  65 +++++++++++++
configure                                          | 108 +++++++++++++++++++++
configure.ac                                       |   2 +
meson.build                                        |  62 ++++++++++++
src/include/c.h                                    |  12 +++
src/include/nodes/nodes.h                          |   4 +-
src/include/pg_config.h.in                         |  14 +++
.../test_cplusplusext/test_cplusplusext.cpp        |   3 +-
8 files changed, 267 insertions(+), 3 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-03-13 06:14 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-02-04 08:24 pgsql: Change copyObject() to use typeof_unqual Peter Eisentraut <peter@eisentraut.org>
2026-03-13 06:14 pgsql: Change copyObject() to use typeof_unqual Peter Eisentraut <peter@eisentraut.org>

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