Re: Safer hash table initialization macro - Mailing list pgsql-hackers

From Jelte Fennema-Nio
Subject Re: Safer hash table initialization macro
Date
Msg-id DESS1U66SWHO.2JT1YL2Q20K0F@jeltef.nl
Whole thread Raw
In response to Re: Safer hash table initialization macro  (Thomas Munro <thomas.munro@gmail.com>)
List 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@jeltef.nl> wrote:
>> On Fri, 5 Dec 2025 at 02:30, Thomas Munro <thomas.munro@gmail.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

pgsql-hackers by date:

Previous
From: David Geier
Date:
Subject: Re: get rid of Pointer type, mostly
Next
From: Chao Li
Date:
Subject: Re: get rid of Pointer type, mostly