Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita3f66ea

Browse files
committed
Some cleanups of enum-guc code, per comments from Tom.
1 parentc9a1cc6 commita3f66ea

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
staticboolassign_autovacuum_max_workers(intnewval,booldoit,GucSourcesource);
169169
staticboolassign_maxconnections(intnewval,booldoit,GucSourcesource);
170170

171+
staticconstchar*config_enum_lookup_value(structconfig_enum*record,intval);
172+
staticboolconfig_enum_lookup_name(structconfig_enum*record,
173+
constchar*value,int*retval);
174+
staticchar*config_enum_get_options(structconfig_enum*record,
175+
constchar*prefix,constchar*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 anddon't touch retval.
4242+
* true. If it's not found, return FALSE andretval is set to 0.
42344243
*
42354244
*/
42364245
staticbool
@@ -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 isgievn, it is added before the first enum value.
4261-
* If suffix isgiven, it is added to the end of the string.
4269+
* If prefix isnon-NULL, it is added before the first enum value.
4270+
* If suffix isnon-NULL, it is added to the end of the string.
42624271
*/
42634272
staticchar*
42644273
config_enum_get_options(structconfig_enum*record,constchar*prefix,constchar*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(constchar*name,
5607+
constchar*short_desc,
5608+
constchar*long_desc,
5609+
int*valueAddr,
5610+
conststructconfig_enum_entry*options,
5611+
GucContextcontext,
5612+
GucEnumAssignHookassign_hook,
5613+
GucShowHookshow_hook)
5614+
{
5615+
structconfig_enum*var;
5616+
5617+
var= (structconfig_enum*)
5618+
init_custom_variable(name,short_desc,long_desc,context,
5619+
PGC_ENUM,sizeof(structconfig_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(constchar*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
#ifndefGUC_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+
structconfig_enum_entry
100+
{
101+
constchar*name;
102+
intval;
103+
};
104+
105+
96106
typedefconstchar*(*GucStringAssignHook) (constchar*newval,booldoit,GucSourcesource);
97107
typedefbool (*GucBoolAssignHook) (boolnewval,booldoit,GucSourcesource);
98108
typedefbool (*GucIntAssignHook) (intnewval,booldoit,GucSourcesource);
@@ -189,6 +199,16 @@ extern void DefineCustomStringVariable(
189199
GucStringAssignHookassign_hook,
190200
GucShowHookshow_hook);
191201

202+
externvoidDefineCustomEnumVariable(
203+
constchar*name,
204+
constchar*short_desc,
205+
constchar*long_desc,
206+
int*valueAddr,
207+
conststructconfig_enum_entry*options,
208+
GucContextcontext,
209+
GucEnumAssignHookassign_hook,
210+
GucShowHookshow_hook);
211+
192212
externvoidEmitWarningsOnPlaceholders(constchar*className);
193213

194214
externconstchar*GetConfigOption(constchar*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
intenumval;
3838
};
3939

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp