| From: | Peter Eisentraut <peter(at)eisentraut(dot)org> |
|---|---|
| To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Cc: | Jelte Fennema-Nio <postgres(at)jeltef(dot)nl> |
| Subject: | Re: Change copyObject() to use typeof_unqual |
| Date: | 2026-03-06 19:17:44 |
| Message-ID: | b136156d-11d1-4db9-84db-28fd8c0aa756@eisentraut.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On 04.02.26 11:46, Peter Eisentraut wrote:
> On 20.01.26 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.
>>
>> 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 *.
>
> I committed this first part, but it ran into some trouble on the buildfarm:
>
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?
> nm=taipan&dt=2026-02-04%2008%3A39%3A34
>
> The problem is that configure detected that gcc supports typeof_unqual,
> but the clang used to produce the .bc files does not.
Here is a new version, after the previous one was reverted.
This is rebased over commit 1887d822f14 and now also provides a C++
implementation, corresponding to the C++ typeof implementation added by
that commit.
This revealed an insufficiency in that commit, which I fix in the first
patch.
I have addressed the above problem by swapping the order of the probes
(putting the underscore variant first), as discussed.
There was also an issue that newer MSVC versions claimed to support
typeof_unqual but it didn't work correctly. I have enhanced the
configure probes to detect this problem.
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Fixes-for-C-typeof-implementation.patch | text/plain | 1.5 KB |
| v2-0002-Change-copyObject-to-use-typeof_unqual.patch | text/plain | 13.0 KB |
| v2-0003-Add-some-const-qualifiers-enabled-by-typeof_unqua.patch | text/plain | 16.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andres Freund | 2026-03-06 19:22:27 | Re: Reduce timing overhead of EXPLAIN ANALYZE using rdtsc? |
| Previous Message | Robert Haas | 2026-03-06 18:55:42 | Re: pg_combinebackup: incorrect size of VM fork after combine |