Skip to content

Commit 7cbfa75

Browse files
committed
Fix postgres --describe-config for guc enums, breakage noted by Alvaro.
While at it, rename option lookup functions to make names clearer, per discussion with Tom.
1 parent 164899d commit 7cbfa75

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

src/backend/utils/misc/guc.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.438 2008/03/16 16:42:44 mha Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.439 2008/03/17 17:45:09 mha Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -168,9 +168,6 @@ static const char *show_tcp_keepalives_count(void);
168168
static bool assign_autovacuum_max_workers(int newval, bool doit, GucSource source);
169169
static bool assign_maxconnections(int newval, bool doit, GucSource source);
170170

171-
static const char *config_enum_lookup_value(struct config_enum *record, int val);
172-
static bool config_enum_lookup_name(struct config_enum *record,
173-
const char *value, int *retval);
174171
static char *config_enum_get_options(struct config_enum *record,
175172
const char *prefix, const char *suffix);
176173

@@ -3144,7 +3141,7 @@ InitializeGUCOptions(void)
31443141
PGC_S_DEFAULT))
31453142
elog(FATAL, "failed to initialize %s to %s",
31463143
conf->gen.name,
3147-
config_enum_lookup_value(conf, conf->boot_val));
3144+
config_enum_lookup_by_value(conf, conf->boot_val));
31483145
*conf->variable = conf->reset_val = conf->boot_val;
31493146
break;
31503147
}
@@ -4219,8 +4216,8 @@ parse_real(const char *value, double *result)
42194216
* The returned string is a pointer to static data and not
42204217
* allocated for modification.
42214218
*/
4222-
static const char *
4223-
config_enum_lookup_value(struct config_enum *record, int val)
4219+
const char *
4220+
config_enum_lookup_by_value(struct config_enum *record, int val)
42244221
{
42254222
const struct config_enum_entry *entry = record->options;
42264223
while (entry && entry->name)
@@ -4242,8 +4239,8 @@ config_enum_lookup_value(struct config_enum *record, int val)
42424239
* true. If it's not found, return FALSE and retval is set to 0.
42434240
*
42444241
*/
4245-
static bool
4246-
config_enum_lookup_name(struct config_enum *record, const char *value, int *retval)
4242+
bool
4243+
config_enum_lookup_by_name(struct config_enum *record, const char *value, int *retval)
42474244
{
42484245
const struct config_enum_entry *entry = record->options;
42494246

@@ -4876,7 +4873,7 @@ set_config_option(const char *name, const char *value,
48764873

48774874
if (value)
48784875
{
4879-
if (!config_enum_lookup_name(conf, value, &newval))
4876+
if (!config_enum_lookup_by_name(conf, value, &newval))
48804877
{
48814878
char *hintmsg = config_enum_get_options(conf, "Available values: ", ".");
48824879

@@ -4906,7 +4903,7 @@ set_config_option(const char *name, const char *value,
49064903
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
49074904
errmsg("invalid value for parameter \"%s\": \"%s\"",
49084905
name,
4909-
config_enum_lookup_value(conf, newval))));
4906+
config_enum_lookup_by_value(conf, newval))));
49104907
return false;
49114908
}
49124909

@@ -5007,7 +5004,7 @@ GetConfigOption(const char *name)
50075004
return *((struct config_string *) record)->variable;
50085005

50095006
case PGC_ENUM:
5010-
return config_enum_lookup_value((struct config_enum *) record,
5007+
return config_enum_lookup_by_value((struct config_enum *) record,
50115008
*((struct config_enum *) record)->variable);
50125009
}
50135010
return NULL;
@@ -5055,7 +5052,7 @@ GetConfigOptionResetString(const char *name)
50555052
return ((struct config_string *) record)->reset_val;
50565053

50575054
case PGC_ENUM:
5058-
return config_enum_lookup_value((struct config_enum *) record,
5055+
return config_enum_lookup_by_value((struct config_enum *) record,
50595056
((struct config_enum *) record)->reset_val);
50605057
}
50615058
return NULL;
@@ -6265,7 +6262,7 @@ _ShowOption(struct config_generic * record, bool use_units)
62656262
if(conf->show_hook)
62666263
val = (*conf->show_hook) ();
62676264
else
6268-
val = config_enum_lookup_value(conf, *conf->variable);
6265+
val = config_enum_lookup_by_value(conf, *conf->variable);
62696266
}
62706267
break;
62716268

@@ -6331,7 +6328,7 @@ is_newvalue_equal(struct config_generic * record, const char *newvalue)
63316328
struct config_enum *conf = (struct config_enum *) record;
63326329
int newval;
63336330

6334-
return config_enum_lookup_name(conf, newvalue, &newval)
6331+
return config_enum_lookup_by_name(conf, newvalue, &newval)
63356332
&& *conf->variable == newval;
63366333
}
63376334
}
@@ -6425,7 +6422,7 @@ write_nondefault_variables(GucContext context)
64256422
{
64266423
struct config_enum *conf = (struct config_enum *) gconf;
64276424

6428-
fprintf(fp, "%s", config_enum_lookup_value(conf, *conf->variable));
6425+
fprintf(fp, "%s", config_enum_lookup_by_value(conf, *conf->variable));
64296426
}
64306427
break;
64316428
}

src/backend/utils/misc/help_config.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/help_config.c,v 1.20 2008/02/23 19:23:33 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/help_config.c,v 1.21 2008/03/17 17:45:09 mha Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -35,6 +35,7 @@ typedef union
3535
struct config_real real;
3636
struct config_int integer;
3737
struct config_string string;
38+
struct config_enum _enum;
3839
} mixedStruct;
3940

4041

@@ -120,6 +121,12 @@ printMixedStruct(mixedStruct *structToPrint)
120121
structToPrint->string.boot_val ? structToPrint->string.boot_val : "");
121122
break;
122123

124+
case PGC_ENUM:
125+
printf("ENUM\t%s\t\t\t",
126+
config_enum_lookup_by_value(&structToPrint->_enum,
127+
structToPrint->_enum.boot_val));
128+
break;
129+
123130
default:
124131
write_stderr("internal error: unrecognized run-time parameter type\n");
125132
break;

src/include/utils/guc_tables.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.40 2008/03/16 16:42:44 mha Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.41 2008/03/17 17:45:09 mha Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -236,4 +236,10 @@ extern struct config_generic **get_guc_variables(void);
236236

237237
extern void build_guc_variables(void);
238238

239+
/* search in enum options */
240+
extern const char *config_enum_lookup_by_value(struct config_enum *record, int val);
241+
extern bool config_enum_lookup_by_name(struct config_enum *record,
242+
const char *value, int *retval);
243+
244+
239245
#endif /* GUC_TABLES_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy