On 08/23/21 10:57, Chapman Flack wrote: > Maybe those cases aren't very numerous ... and maybe they're distinctive > enough to recognize when creating one ("hmm, I am creating a check or > assign hook that does significant work here, will it be worth exposing > a getter API for the product of the work?").
How about a generic GetTypedConfigValue(char const *name, void *into) ? By default the type of *into would correspond to the type of the GUC (int for an enum) and would be returned directly from *conf->variable by a getter hook installed by default when the GUC is defined. But the definition could also supply a getter hook that would store a value of a different type, or computed a different way, for a GUC where that's appropriate. The function return could be boolean, true if such a variable exists and isn't a placeholder. Pro: provides read access to the typed value of any GUC, without exposing it to overwriting. Con: has to bsearch the GUCs every time the value is wanted. What I'd really like: ObserveTypedConfigValue(char const *name, void *into, int *flags, int flag) This would register an observer of the named GUC: whenever its typed value changes, it is written at *into and flag is ORed into *flags. This is more restrictive than allowing arbitrary code to be hooked into GUC changes (as changes can happen at delicate times such as error recovery), but allows an extension to always have the current typed value available and to cheaply know when it has changed. Observers would be updated in the normal course of processing a GUC change, eliminating the bsearch-per-lookup cost of the first approach. Thinkable? Regards, -Chap