Re: anonymous unions (C11)

Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>

From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
To: Chao Li <li.evan.chao@gmail.com>, Peter Eisentraut <peter@eisentraut.org>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-09-30T11:21:51Z
Lists: pgsql-hackers

Attachments

On Wed, Sep 24, 2025 at 4:49 AM Chao Li <li.evan.chao@gmail.com> wrote:
>
>
> On Tue, Sep 23, 2025 at 5:38 PM Peter Eisentraut <peter@eisentraut.org> wrote:
>>
>>
>>
>> That said, I did go overboard here and converted all the struct/union
>> combinations I could find, but I'm not necessarily proposing to apply
>> all of them.  I'm proposing patches 0001 through 0004, which are
>> relatively simple or in areas that have already changed a few times
>> recently (so backpatching would not be trivial anyway), and/or they
>> are somewhat close to my heart because they originally motivated this
>> work a long time ago.  But if someone finds among the other patches
>> one that they particularly like, we could add that one as well.
>
>
> I went through all commits and code changes are neat and clear.
>
> But when I tried to build on my Macbook M4, it got 18 errors against cryptohash.c:
> ```
> cryptohash.c:108:22: error: no member named 'data' in 'struct pg_cryptohash_ctx'
>   108 |                         pg_md5_init(&ctx->data.md5);
>       |                                      ~~~  ^
... snip ...
> cryptohash.c:225:26: error: no member named 'data' in 'struct pg_cryptohash_ctx'
>   225 |                         pg_sha512_final(&ctx->data.sha512, dest);
>       |                                          ~~~  ^
> 18 errors generated.

I am using meson and gcc with following versions

$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04.2) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ meson --version
0.61.2

I am getting opposite of those errors

../../coderoot/pg/src/common/cryptohash.c: In function ‘pg_cryptohash_init’:
../../coderoot/pg/src/common/cryptohash.c:108:41: error:
‘pg_cryptohash_ctx’ has no member named ‘md5’
  108 |                         pg_md5_init(&ctx->md5);
      |                                         ^~
... snip ...
../../coderoot/pg/src/common/cryptohash.c:225:45: error:
‘pg_cryptohash_ctx’ has no member named ‘sha512’
  225 |                         pg_sha512_final(&ctx->sha512, dest);

Attached patch fixes those errors for me.

-- 
Best Wishes,
Ashutosh Bapat

Commits

  1. Make some use of anonymous unions [reloptions]

  2. Make some use of anonymous unions [libpq-oauth]

  3. Make some use of anonymous unions [DSM registry].

  4. Make some use of anonymous unions [pg_locale_t]

  5. Make some use of anonymous unions [pgcrypto]

  6. Make some use of anonymous unions [plpython]

  7. Make some use of anonymous unions [reorderbuffer xact_time]