Re: fix more casting away of qualifiers

Поиск
Список
Период
Сортировка
Искать

Re: fix more casting away of qualifiers

От:
Heikki Linnakangas <hlinnaka@iki.fi>
Дата:
Вложения:
On 18/08/2026 12:04, Peter Eisentraut wrote:
> The attached patches fix more cases where qualifiers (const, volatile) 
> are cast away either accidentally, or unnecessarily, or where it can be 
> worked around easily.
> 
> I split these into tiny bits to simplify review and to show that they 
> are all independent.  But they could perhaps be committed all together.
> (See also similar commit 3f988629805.)
Thanks for the cleanups!

> diff --git a/src/backend/utils/misc/guc_funcs.c b/src/backend/utils/misc/guc_funcs.c
> index e2c2919484e..defaa796a0c 100644
> --- a/src/backend/utils/misc/guc_funcs.c
> +++ b/src/backend/utils/misc/guc_funcs.c
> @@ -971,6 +971,7 @@ show_all_settings(PG_FUNCTION_ARGS)
>  	while (call_cntr < max_calls)	/* do when there is more left to send */
>  	{
>  		struct config_generic *conf = guc_vars[call_cntr];
> +		const char *cvalues[NUM_PG_SETTINGS_ATTS];
>  		char	   *values[NUM_PG_SETTINGS_ATTS];
>  		HeapTuple	tuple;
>  		Datum		result;
> @@ -984,7 +985,14 @@ show_all_settings(PG_FUNCTION_ARGS)
>  		}
>  
>  		/* extract values for the current variable */
> -		GetConfigOptionValues(conf, (const char **) values);
> +		GetConfigOptionValues(conf, cvalues);
> +
> +		/*
> +		 * This is so that both GetConfigOptionValues() and
> +		 * BuildTupleFromCStrings() are satisfied about the const-ness without
> +		 * triggering warnings.
> +		 */
> +		memcpy(values, cvalues, sizeof(cvalues));
>  
>  		/* build a tuple */
>  		tuple = BuildTupleFromCStrings(attinmeta, values);

This seems hacky. Can we change BuildTupleFromCStrings() to take a const 
instead? Maybe that was part of your "difficult half" already?

I guess that requires changing all the callers: You get a warning if 
pass a "char **" to a "const char **". Is there a way with some macro 
magic or something that you could accept both?

All else look good to me at a quick glance.

- Heikki



Re: fix more casting away of qualifiers

От:
Peter Eisentraut <peter@eisentraut.org>
Дата:
On 25.08.26 10:52, Daniel Gustafsson wrote:
>> On 25 Aug 2026, at 10:42, Peter Eisentraut  wrote:
> 
>> I have committed these patches except the one above.
> 
> BF member sifaka complains due to (it seems like) macOS bundling readline 3.0
> in the base OS.  Maybe we need a configure/meson check for this?
> 
> tab-complete.in.c:1525:19: error: assigning to 'char *' from 'const char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> 1525 | rl_readline_name = pset.progname;
> | ^ ~~~~~~~~~~~~~
> 1 error generated.

Ok, thanks, I'm going to revert it.  I was anticipating something like 
this, but at least now we know for sure.



FAQ