Re: Safer hash table initialization macro

From: "Jelte Fennema-Nio" <postgres(at)jeltef(dot)nl>
To: "Thomas Munro" <thomas(dot)munro(at)gmail(dot)com>
Cc: "Bertrand Drouvot" <bertranddrouvot(dot)pg(at)gmail(dot)com>, <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Safer hash table initialization macro
Date: 2025-12-08 10:53:02
Message-ID: DESS1U66SWHO.2JT1YL2Q20K0F@jeltef.nl
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat Dec 6, 2025 at 1:56 AM CET, Thomas Munro wrote:
> On Sat, Dec 6, 2025 at 3:32 AM Jelte Fennema-Nio <postgres(at)jeltef(dot)nl> wrote:
>> On Fri, 5 Dec 2025 at 02:30, Thomas Munro <thomas(dot)munro(at)gmail(dot)com> wrote:
>> create a hashmap it's still possible to call the.
>
> ... C functions without the helper macros.

Oops, forgot to finish that sentence.
>
> Yeah. I don't think we want that sort of thing all over the place.
> We could eventually come up with a small set of tools in a central
> place though, so people can work with this stuff without also known
> C++ meta-programming voodoo. For example something like (untested, I
> didn't think about char[size], just spitballing here...):
>
> (pg_expr_has_type_p(ptr, char *) || pg_expr_has_type_p(ptr, NameData *))
>
> ... given the definition I posted recently[1].

Ugh... It would have saved me some time if I'd seen that email before. I
also had no clue that 'extern "C++"' was a thing. Attached is a new
patchset where your proposed macro is used. I also needed a
pg_nullptr_of macro, because the trick that worked in C didn't in C++.

Also, it's probably worth checking out this thread[2]. Especially
because it overlaps significantly with[1].

> Sure, I was just thinking about how such cross-language usage would be
> forced to unpick our macrology and call the underlying C functions
> without them. Doesn't seem like the end of the world anyway, I was
> just thinking out loud about the consequences of this phenomenon in
> headers.

It's not great, but yeah that's the situation. Stuff like PG_TRY and
PG_CATCH are especially painful to reimplement. Luckily those things
can usually be re-implemented similarly in the target language, so the
macros only need to be disected once.

> [1] https://www.postgresql.org/message-id/CA+hUKGL7trhWiJ4qxpksBztMMTWDyPnP1QN+Lq341V7QL775DA@mail.gmail.com
[2]: https://www.postgresql.org/message-id/flat/CAGECzQR21OnnKiZO_1rLWO0-16kg1JBxnVq-wymYW0-_1cUNtg%40mail.gmail.com

Attachment Content-Type Size
v3-0001-Add-hash_make-macros.patch text/x-patch 14.8 KB
v3-0002-Use-hash_make-macros-throughout-the-codebase.patch text/x-patch 95.6 KB
v3-0003-Inline-functions-that-have-now-become-trivial.patch text/x-patch 4.5 KB
v3-0004-Add-foreach_hash-macro.patch text/x-patch 3.6 KB
v3-0005-Use-foreach_hash-macro-throughout-the-codebase.patch text/x-patch 67.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2025-12-08 10:53:15 Re: get rid of Pointer type, mostly
Previous Message David Geier 2025-12-08 10:25:28 Re: get rid of Pointer type, mostly