Re: Change copyObject() to use typeof_unqual
David Geier <geidav.pg@gmail.com>
From: David Geier <geidav.pg@gmail.com>
To: Peter Eisentraut <peter@eisentraut.org>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2026-01-20T10:48:00Z
Lists: pgsql-hackers
Hi Peter! On 20.01.2026 10:37, Peter Eisentraut wrote: > 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. Great change. I've ran into that multiple times and had to un-const-correct my code because of how copyObject() works. > 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 *. > > (Even MSVC supports it, if we use a slightly newer version than is on > CI. For example, the new buildfarm member unicorn would support it.) I'm not too familiar with the build system, so I let someone else review this part. > The second patch make some changes to take advantage of this improved > qualifier handling. EventTriggerCollectSimpleCommand() is a good > example: It takes a node tree and makes a copy that it keeps around for > its internal purposes, but it can't communicate via its function > signature that it promises not scribble on the passed node tree. That > is now fixed. The changes to EvenTriggerCollectSimpleCommand() look good to me. Are you planning to look at the rest of the code as well? At a quick glance there seem to be more places that can be changed in similar ways, e.g. see refresh_matview_datafill(). -- David Geier
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add some const qualifiers enabled by typeof_unqual change on copyObject
- 7724cb9935a9 19 (unreleased) landed
-
Hardcode typeof_unqual to __typeof_unqual__ for clang
- 2eb6cd327cae 19 (unreleased) landed
-
Clean up postgres_fdw/t/010_subscription.pl.
- f4af7849b3db 19 (unreleased) cited
-
Hardcode override of typeof_unqual for clang-for-bitcode
- 63275ce84d2f 19 (unreleased) landed
-
Make typeof and typeof_unqual fallback definitions work on C++11
- cd083b54bd67 19 (unreleased) landed
-
Change copyObject() to use typeof_unqual
- 59292f7aac72 19 (unreleased) landed
- 4cfce4e62c8f 19 (unreleased) landed
-
Fixes for C++ typeof implementation
- 9c05f152b5dd 19 (unreleased) landed
-
Support using copyObject in standard C++
- 1887d822f142 19 (unreleased) cited