Skip to content

Commit a3f66ea

Browse files
committed
Some cleanups of enum-guc code, per comments from Tom.
1 parent c9a1cc6 commit a3f66ea

File tree

4 files changed

+68
-23
lines changed

4 files changed

+68
-23
lines changed

src/backend/utils/misc/README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
$PostgreSQL: pgsql/src/backend/utils/misc/README,v 1.8 2007/12/28 00:23:23 tgl Exp $
1+
$PostgreSQL: pgsql/src/backend/utils/misc/README,v 1.9 2008/03/16 16:42:44 mha Exp $
22

33

44
GUC IMPLEMENTATION NOTES
55

66
The GUC (Grand Unified Configuration) module implements configuration
7-
variables of multiple types (currently boolean, int, float, and string).
7+
variables of multiple types (currently boolean, enum, int, float, and string).
88
Variable settings can come from various places, with a priority ordering
99
determining which setting is used.
1010

src/backend/utils/misc/guc.c

Lines changed: 44 additions & 10 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.437 2008/03/10 12:55:13 mha Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.438 2008/03/16 16:42:44 mha Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -168,6 +168,14 @@ 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);
174+
static char *config_enum_get_options(struct config_enum *record,
175+
const char *prefix, const char *suffix);
176+
177+
178+
171179
/*
172180
* Options for enum values defined in this module.
173181
*/
@@ -3134,8 +3142,9 @@ InitializeGUCOptions(void)
31343142
if (conf->assign_hook)
31353143
if (!(*conf->assign_hook) (conf->boot_val, true,
31363144
PGC_S_DEFAULT))
3137-
elog(FATAL, "failed to initialize %s to %d",
3138-
conf->gen.name, conf->boot_val);
3145+
elog(FATAL, "failed to initialize %s to %s",
3146+
conf->gen.name,
3147+
config_enum_lookup_value(conf, conf->boot_val));
31393148
*conf->variable = conf->reset_val = conf->boot_val;
31403149
break;
31413150
}
@@ -4230,7 +4239,7 @@ config_enum_lookup_value(struct config_enum *record, int val)
42304239
* Lookup the value for an enum option with the selected name
42314240
* (case-insensitive).
42324241
* If the enum option is found, sets the retval value and returns
4233-
* true. If it's not found, return FALSE and don't touch retval.
4242+
* true. If it's not found, return FALSE and retval is set to 0.
42344243
*
42354244
*/
42364245
static bool
@@ -4243,7 +4252,7 @@ config_enum_lookup_name(struct config_enum *record, const char *value, int *retv
42434252

42444253
while (entry && entry->name)
42454254
{
4246-
if (!pg_strcasecmp(value, entry->name))
4255+
if (pg_strcasecmp(value, entry->name) == 0)
42474256
{
42484257
*retval = entry->val;
42494258
return TRUE;
@@ -4255,10 +4264,10 @@ config_enum_lookup_name(struct config_enum *record, const char *value, int *retv
42554264

42564265

42574266
/*
4258-
* Returna list of all available options for an enum, separated
4267+
* Return a list of all available options for an enum, separated
42594268
* by ", " (comma-space).
4260-
* If prefix is gievn, it is added before the first enum value.
4261-
* If suffix is given, it is added to the end of the string.
4269+
* If prefix is non-NULL, it is added before the first enum value.
4270+
* If suffix is non-NULL, it is added to the end of the string.
42624271
*/
42634272
static char *
42644273
config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix)
@@ -4895,8 +4904,9 @@ set_config_option(const char *name, const char *value,
48954904
{
48964905
ereport(elevel,
48974906
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4898-
errmsg("invalid value for parameter \"%s\": \"%d\"",
4899-
name, newval)));
4907+
errmsg("invalid value for parameter \"%s\": \"%s\"",
4908+
name,
4909+
config_enum_lookup_value(conf, newval))));
49004910
return false;
49014911
}
49024912

@@ -5592,6 +5602,30 @@ DefineCustomStringVariable(const char *name,
55925602
define_custom_variable(&var->gen);
55935603
}
55945604

5605+
void
5606+
DefineCustomEnumVariable(const char *name,
5607+
const char *short_desc,
5608+
const char *long_desc,
5609+
int *valueAddr,
5610+
const struct config_enum_entry *options,
5611+
GucContext context,
5612+
GucEnumAssignHook assign_hook,
5613+
GucShowHook show_hook)
5614+
{
5615+
struct config_enum *var;
5616+
5617+
var = (struct config_enum *)
5618+
init_custom_variable(name, short_desc, long_desc, context,
5619+
PGC_ENUM, sizeof(struct config_enum));
5620+
var->variable = valueAddr;
5621+
var->boot_val = *valueAddr;
5622+
var->reset_val = *valueAddr;
5623+
var->options = options;
5624+
var->assign_hook = assign_hook;
5625+
var->show_hook = show_hook;
5626+
define_custom_variable(&var->gen);
5627+
}
5628+
55955629
void
55965630
EmitWarningsOnPlaceholders(const char *className)
55975631
{

src/include/utils/guc.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
88
* Written by Peter Eisentraut <peter_e@gmx.net>.
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.91 2008/03/10 12:55:13 mha Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.92 2008/03/16 16:42:44 mha Exp $
1111
*--------------------------------------------------------------------
1212
*/
1313
#ifndef GUC_H
@@ -93,6 +93,16 @@ typedef enum
9393
PGC_S_SESSION /* SET command */
9494
} GucSource;
9595

96+
/*
97+
* Enum values are made up of an array of name-value pairs
98+
*/
99+
struct config_enum_entry
100+
{
101+
const char *name;
102+
int val;
103+
};
104+
105+
96106
typedef const char *(*GucStringAssignHook) (const char *newval, bool doit, GucSource source);
97107
typedef bool (*GucBoolAssignHook) (bool newval, bool doit, GucSource source);
98108
typedef bool (*GucIntAssignHook) (int newval, bool doit, GucSource source);
@@ -189,6 +199,16 @@ extern void DefineCustomStringVariable(
189199
GucStringAssignHook assign_hook,
190200
GucShowHook show_hook);
191201

202+
extern void DefineCustomEnumVariable(
203+
const char *name,
204+
const char *short_desc,
205+
const char *long_desc,
206+
int *valueAddr,
207+
const struct config_enum_entry *options,
208+
GucContext context,
209+
GucEnumAssignHook assign_hook,
210+
GucShowHook show_hook);
211+
192212
extern void EmitWarningsOnPlaceholders(const char *className);
193213

194214
extern const char *GetConfigOption(const char *name);

src/include/utils/guc_tables.h

Lines changed: 1 addition & 10 deletions
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.39 2008/03/10 12:55:13 mha Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.40 2008/03/16 16:42:44 mha Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -37,15 +37,6 @@ union config_var_value
3737
int enumval;
3838
};
3939

40-
/*
41-
* Enum values are made up of an array of name-value pairs
42-
*/
43-
struct config_enum_entry
44-
{
45-
const char *name;
46-
int val;
47-
};
48-
4940
/*
5041
* Groupings to help organize all the run-time options for display
5142
*/

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