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

From Jelte Fennema-Nio
Subject Re: Safer hash table initialization macro
Date
Msg-id DFZKNSINQ9I1.1JOM73FKP88HC@jeltef.nl
Whole thread Raw
In response to Re: Safer hash table initialization macro  (Chao Li <li.evan.chao@gmail.com>)
List pgsql-hackers
On Tue Jan 27, 2026 at 8:26 AM CET, Chao Li wrote:
> This function has a lot of duplicate checks on opts!=NULL, I think it can be simplified as:

Good suggestion. Done.

> 2 - 0002
> Why this function returns a structure by value? Which looks quite uncommon. Usually, when a function is named with
“new”,it returns a pointer to a new object. 

I changed the name to foreach_hash_start and made it a static inline
function in the header instead. I updated the comment to explain why
it's needed (i.e. to initialize the local varaiable).


> 3 - 0002
> foreach_hash feels fragile. It requires to call foreach_hash_term before break, which is easy to forget. And the
documentation   doesn’t mention how to continue, how to return from a loop, and how to goto from inside a loop. 

I agree that it'd be better if foreach_hash_term was not needed. But
that would be a lot bigger change (see the "SEQ SCAN TRACKING" comment).

I've updated the comment on foreach_hash_term to be more specific about
when it's needed.

Attachment

pgsql-hackers by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Add SECURITY_INVOKER_VIEWS option to CREATE DATABASE
Next
From: Robert Haas
Date:
Subject: Re: pgsql: Prevent invalidation of newly synced replication slots.