From af7827dc6292c9fac5476624658c7c499b023064 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 3 Oct 2025 08:27:18 +0200 Subject: [PATCH v1 2/8] Add some const qualifiers in guc-related source files, in anticipation of some further restructuring. --- src/backend/utils/misc/guc.c | 62 +++++++++++++++--------------- src/backend/utils/misc/guc_funcs.c | 16 ++++---- src/include/utils/guc_tables.h | 10 ++--- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index f22189471dc..dac09ae7853 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -260,15 +260,15 @@ static bool assignable_custom_variable_name(const char *name, bool skip_errors, int elevel); static void do_serialize(char **destptr, Size *maxbytes, const char *fmt,...) pg_attribute_printf(3, 4); -static bool call_bool_check_hook(struct config_bool *conf, bool *newval, +static bool call_bool_check_hook(const struct config_bool *conf, bool *newval, void **extra, GucSource source, int elevel); -static bool call_int_check_hook(struct config_int *conf, int *newval, +static bool call_int_check_hook(const struct config_int *conf, int *newval, void **extra, GucSource source, int elevel); -static bool call_real_check_hook(struct config_real *conf, double *newval, +static bool call_real_check_hook(const struct config_real *conf, double *newval, void **extra, GucSource source, int elevel); -static bool call_string_check_hook(struct config_string *conf, char **newval, +static bool call_string_check_hook(const struct config_string *conf, char **newval, void **extra, GucSource source, int elevel); -static bool call_enum_check_hook(struct config_enum *conf, int *newval, +static bool call_enum_check_hook(const struct config_enum *conf, int *newval, void **extra, GucSource source, int elevel); @@ -1424,14 +1424,14 @@ check_GUC_name_for_parameter_acl(const char *name) */ #ifdef USE_ASSERT_CHECKING static bool -check_GUC_init(struct config_generic *gconf) +check_GUC_init(const struct config_generic *gconf) { /* Checks on values */ switch (gconf->vartype) { case PGC_BOOL: { - struct config_bool *conf = (struct config_bool *) gconf; + const struct config_bool *conf = (const struct config_bool *) gconf; if (*conf->variable && !conf->boot_val) { @@ -1443,7 +1443,7 @@ check_GUC_init(struct config_generic *gconf) } case PGC_INT: { - struct config_int *conf = (struct config_int *) gconf; + const struct config_int *conf = (const struct config_int *) gconf; if (*conf->variable != 0 && *conf->variable != conf->boot_val) { @@ -1455,7 +1455,7 @@ check_GUC_init(struct config_generic *gconf) } case PGC_REAL: { - struct config_real *conf = (struct config_real *) gconf; + const struct config_real *conf = (const struct config_real *) gconf; if (*conf->variable != 0.0 && *conf->variable != conf->boot_val) { @@ -1467,7 +1467,7 @@ check_GUC_init(struct config_generic *gconf) } case PGC_STRING: { - struct config_string *conf = (struct config_string *) gconf; + const struct config_string *conf = (const struct config_string *) gconf; if (*conf->variable != NULL && (conf->boot_val == NULL || @@ -1481,7 +1481,7 @@ check_GUC_init(struct config_generic *gconf) } case PGC_ENUM: { - struct config_enum *conf = (struct config_enum *) gconf; + const struct config_enum *conf = (const struct config_enum *) gconf; if (*conf->variable != conf->boot_val) { @@ -3012,7 +3012,7 @@ parse_real(const char *value, double *result, int flags, const char **hintmsg) * allocated for modification. */ const char * -config_enum_lookup_by_value(struct config_enum *record, int val) +config_enum_lookup_by_value(const struct config_enum *record, int val) { for (const struct config_enum_entry *entry = record->options; entry && entry->name; entry++) { @@ -3033,7 +3033,7 @@ config_enum_lookup_by_value(struct config_enum *record, int val) * true. If it's not found, return false and retval is set to 0. */ bool -config_enum_lookup_by_name(struct config_enum *record, const char *value, +config_enum_lookup_by_name(const struct config_enum *record, const char *value, int *retval) { for (const struct config_enum_entry *entry = record->options; entry && entry->name; entry++) @@ -3057,7 +3057,7 @@ config_enum_lookup_by_name(struct config_enum *record, const char *value, * If suffix is non-NULL, it is added to the end of the string. */ char * -config_enum_get_options(struct config_enum *record, const char *prefix, +config_enum_get_options(const struct config_enum *record, const char *prefix, const char *suffix, const char *separator) { StringInfoData retstr; @@ -3113,7 +3113,7 @@ config_enum_get_options(struct config_enum *record, const char *prefix, * Returns true if OK, false if not (or throws error, if elevel >= ERROR) */ static bool -parse_and_validate_value(struct config_generic *record, +parse_and_validate_value(const struct config_generic *record, const char *value, GucSource source, int elevel, union config_var_val *newval, void **newextra) @@ -3122,7 +3122,7 @@ parse_and_validate_value(struct config_generic *record, { case PGC_BOOL: { - struct config_bool *conf = (struct config_bool *) record; + const struct config_bool *conf = (const struct config_bool *) record; if (!parse_bool(value, &newval->boolval)) { @@ -3140,7 +3140,7 @@ parse_and_validate_value(struct config_generic *record, break; case PGC_INT: { - struct config_int *conf = (struct config_int *) record; + const struct config_int *conf = (const struct config_int *) record; const char *hintmsg; if (!parse_int(value, &newval->intval, @@ -3181,7 +3181,7 @@ parse_and_validate_value(struct config_generic *record, break; case PGC_REAL: { - struct config_real *conf = (struct config_real *) record; + const struct config_real *conf = (const struct config_real *) record; const char *hintmsg; if (!parse_real(value, &newval->realval, @@ -3222,7 +3222,7 @@ parse_and_validate_value(struct config_generic *record, break; case PGC_STRING: { - struct config_string *conf = (struct config_string *) record; + const struct config_string *conf = (const struct config_string *) record; /* * The value passed by the caller could be transient, so we @@ -3252,7 +3252,7 @@ parse_and_validate_value(struct config_generic *record, break; case PGC_ENUM: { - struct config_enum *conf = (struct config_enum *) record; + const struct config_enum *conf = (const struct config_enum *) record; if (!config_enum_lookup_by_name(conf, value, &newval->enumval)) { @@ -5455,7 +5455,7 @@ GetConfigOptionByName(const char *name, const char **varname, bool missing_ok) * The result string is palloc'd. */ char * -ShowGUCOption(struct config_generic *record, bool use_units) +ShowGUCOption(const struct config_generic *record, bool use_units) { char buffer[256]; const char *val; @@ -5464,7 +5464,7 @@ ShowGUCOption(struct config_generic *record, bool use_units) { case PGC_BOOL: { - struct config_bool *conf = (struct config_bool *) record; + const struct config_bool *conf = (const struct config_bool *) record; if (conf->show_hook) val = conf->show_hook(); @@ -5475,7 +5475,7 @@ ShowGUCOption(struct config_generic *record, bool use_units) case PGC_INT: { - struct config_int *conf = (struct config_int *) record; + const struct config_int *conf = (const struct config_int *) record; if (conf->show_hook) val = conf->show_hook(); @@ -5504,7 +5504,7 @@ ShowGUCOption(struct config_generic *record, bool use_units) case PGC_REAL: { - struct config_real *conf = (struct config_real *) record; + const struct config_real *conf = (const struct config_real *) record; if (conf->show_hook) val = conf->show_hook(); @@ -5529,7 +5529,7 @@ ShowGUCOption(struct config_generic *record, bool use_units) case PGC_STRING: { - struct config_string *conf = (struct config_string *) record; + const struct config_string *conf = (const struct config_string *) record; if (conf->show_hook) val = conf->show_hook(); @@ -5542,7 +5542,7 @@ ShowGUCOption(struct config_generic *record, bool use_units) case PGC_ENUM: { - struct config_enum *conf = (struct config_enum *) record; + const struct config_enum *conf = (const struct config_enum *) record; if (conf->show_hook) val = conf->show_hook(); @@ -6788,7 +6788,7 @@ GUC_check_errcode(int sqlerrcode) */ static bool -call_bool_check_hook(struct config_bool *conf, bool *newval, void **extra, +call_bool_check_hook(const struct config_bool *conf, bool *newval, void **extra, GucSource source, int elevel) { /* Quick success if no hook */ @@ -6822,7 +6822,7 @@ call_bool_check_hook(struct config_bool *conf, bool *newval, void **extra, } static bool -call_int_check_hook(struct config_int *conf, int *newval, void **extra, +call_int_check_hook(const struct config_int *conf, int *newval, void **extra, GucSource source, int elevel) { /* Quick success if no hook */ @@ -6856,7 +6856,7 @@ call_int_check_hook(struct config_int *conf, int *newval, void **extra, } static bool -call_real_check_hook(struct config_real *conf, double *newval, void **extra, +call_real_check_hook(const struct config_real *conf, double *newval, void **extra, GucSource source, int elevel) { /* Quick success if no hook */ @@ -6890,7 +6890,7 @@ call_real_check_hook(struct config_real *conf, double *newval, void **extra, } static bool -call_string_check_hook(struct config_string *conf, char **newval, void **extra, +call_string_check_hook(const struct config_string *conf, char **newval, void **extra, GucSource source, int elevel) { volatile bool result = true; @@ -6940,7 +6940,7 @@ call_string_check_hook(struct config_string *conf, char **newval, void **extra, } static bool -call_enum_check_hook(struct config_enum *conf, int *newval, void **extra, +call_enum_check_hook(const struct config_enum *conf, int *newval, void **extra, GucSource source, int elevel) { /* Quick success if no hook */ diff --git a/src/backend/utils/misc/guc_funcs.c b/src/backend/utils/misc/guc_funcs.c index f712a5971cf..d7a822e1462 100644 --- a/src/backend/utils/misc/guc_funcs.c +++ b/src/backend/utils/misc/guc_funcs.c @@ -578,7 +578,7 @@ pg_settings_get_flags(PG_FUNCTION_ARGS) * Return whether or not the GUC variable is visible to the current user. */ bool -ConfigOptionIsVisible(struct config_generic *conf) +ConfigOptionIsVisible(const struct config_generic *conf) { if ((conf->flags & GUC_SUPERUSER_ONLY) && !has_privs_of_role(GetUserId(), ROLE_PG_READ_ALL_SETTINGS)) @@ -591,7 +591,7 @@ ConfigOptionIsVisible(struct config_generic *conf) * Extract fields to show in pg_settings for given variable. */ static void -GetConfigOptionValues(struct config_generic *conf, const char **values) +GetConfigOptionValues(const struct config_generic *conf, const char **values) { char buffer[256]; @@ -629,7 +629,7 @@ GetConfigOptionValues(struct config_generic *conf, const char **values) { case PGC_BOOL: { - struct config_bool *lconf = (struct config_bool *) conf; + const struct config_bool *lconf = (const struct config_bool *) conf; /* min_val */ values[9] = NULL; @@ -650,7 +650,7 @@ GetConfigOptionValues(struct config_generic *conf, const char **values) case PGC_INT: { - struct config_int *lconf = (struct config_int *) conf; + const struct config_int *lconf = (const struct config_int *) conf; /* min_val */ snprintf(buffer, sizeof(buffer), "%d", lconf->min); @@ -675,7 +675,7 @@ GetConfigOptionValues(struct config_generic *conf, const char **values) case PGC_REAL: { - struct config_real *lconf = (struct config_real *) conf; + const struct config_real *lconf = (const struct config_real *) conf; /* min_val */ snprintf(buffer, sizeof(buffer), "%g", lconf->min); @@ -700,7 +700,7 @@ GetConfigOptionValues(struct config_generic *conf, const char **values) case PGC_STRING: { - struct config_string *lconf = (struct config_string *) conf; + const struct config_string *lconf = (const struct config_string *) conf; /* min_val */ values[9] = NULL; @@ -727,7 +727,7 @@ GetConfigOptionValues(struct config_generic *conf, const char **values) case PGC_ENUM: { - struct config_enum *lconf = (struct config_enum *) conf; + const struct config_enum *lconf = (const struct config_enum *) conf; /* min_val */ values[9] = NULL; @@ -741,7 +741,7 @@ GetConfigOptionValues(struct config_generic *conf, const char **values) * NOTE! enumvals with double quotes in them are not * supported! */ - values[11] = config_enum_get_options((struct config_enum *) conf, + values[11] = config_enum_get_options(lconf, "{\"", "\"}", "\",\""); /* boot_val */ diff --git a/src/include/utils/guc_tables.h b/src/include/utils/guc_tables.h index f72ce944d7f..44514691ba6 100644 --- a/src/include/utils/guc_tables.h +++ b/src/include/utils/guc_tables.h @@ -319,10 +319,10 @@ extern struct config_generic *find_option(const char *name, extern struct config_generic **get_explain_guc_options(int *num); /* get string value of variable */ -extern char *ShowGUCOption(struct config_generic *record, bool use_units); +extern char *ShowGUCOption(const struct config_generic *record, bool use_units); /* get whether or not the GUC variable is visible to current user */ -extern bool ConfigOptionIsVisible(struct config_generic *conf); +extern bool ConfigOptionIsVisible(const struct config_generic *conf); /* get the current set of variables */ extern struct config_generic **get_guc_variables(int *num_vars); @@ -330,10 +330,10 @@ extern struct config_generic **get_guc_variables(int *num_vars); extern void build_guc_variables(void); /* search in enum options */ -extern const char *config_enum_lookup_by_value(struct config_enum *record, int val); -extern bool config_enum_lookup_by_name(struct config_enum *record, +extern const char *config_enum_lookup_by_value(const struct config_enum *record, int val); +extern bool config_enum_lookup_by_name(const struct config_enum *record, const char *value, int *retval); -extern char *config_enum_get_options(struct config_enum *record, +extern char *config_enum_get_options(const struct config_enum *record, const char *prefix, const char *suffix, const char *separator); -- 2.51.0