Commit a3f66eac authored by Magnus Hagander's avatar Magnus Hagander

Some cleanups of enum-guc code, per comments from Tom.

parent c9a1cc69
$PostgreSQL: pgsql/src/backend/utils/misc/README,v 1.8 2007/12/28 00:23:23 tgl Exp $ $PostgreSQL: pgsql/src/backend/utils/misc/README,v 1.9 2008/03/16 16:42:44 mha Exp $
GUC IMPLEMENTATION NOTES GUC IMPLEMENTATION NOTES
The GUC (Grand Unified Configuration) module implements configuration The GUC (Grand Unified Configuration) module implements configuration
variables of multiple types (currently boolean, int, float, and string). variables of multiple types (currently boolean, enum, int, float, and string).
Variable settings can come from various places, with a priority ordering Variable settings can come from various places, with a priority ordering
determining which setting is used. determining which setting is used.
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.437 2008/03/10 12:55:13 mha Exp $ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.438 2008/03/16 16:42:44 mha Exp $
* *
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
...@@ -168,6 +168,14 @@ static const char *show_tcp_keepalives_count(void); ...@@ -168,6 +168,14 @@ static const char *show_tcp_keepalives_count(void);
static bool assign_autovacuum_max_workers(int newval, bool doit, GucSource source); static bool assign_autovacuum_max_workers(int newval, bool doit, GucSource source);
static bool assign_maxconnections(int newval, bool doit, GucSource source); static bool assign_maxconnections(int newval, bool doit, GucSource source);
static const char *config_enum_lookup_value(struct config_enum *record, int val);
static bool config_enum_lookup_name(struct config_enum *record,
const char *value, int *retval);
static char *config_enum_get_options(struct config_enum *record,
const char *prefix, const char *suffix);
/* /*
* Options for enum values defined in this module. * Options for enum values defined in this module.
*/ */
...@@ -3134,8 +3142,9 @@ InitializeGUCOptions(void) ...@@ -3134,8 +3142,9 @@ InitializeGUCOptions(void)
if (conf->assign_hook) if (conf->assign_hook)
if (!(*conf->assign_hook) (conf->boot_val, true, if (!(*conf->assign_hook) (conf->boot_val, true,
PGC_S_DEFAULT)) PGC_S_DEFAULT))
elog(FATAL, "failed to initialize %s to %d", elog(FATAL, "failed to initialize %s to %s",
conf->gen.name, conf->boot_val); conf->gen.name,
config_enum_lookup_value(conf, conf->boot_val));
*conf->variable = conf->reset_val = conf->boot_val; *conf->variable = conf->reset_val = conf->boot_val;
break; break;
} }
...@@ -4230,7 +4239,7 @@ config_enum_lookup_value(struct config_enum *record, int val) ...@@ -4230,7 +4239,7 @@ config_enum_lookup_value(struct config_enum *record, int val)
* Lookup the value for an enum option with the selected name * Lookup the value for an enum option with the selected name
* (case-insensitive). * (case-insensitive).
* If the enum option is found, sets the retval value and returns * If the enum option is found, sets the retval value and returns
* true. If it's not found, return FALSE and don't touch retval. * true. If it's not found, return FALSE and retval is set to 0.
* *
*/ */
static bool static bool
...@@ -4243,7 +4252,7 @@ config_enum_lookup_name(struct config_enum *record, const char *value, int *retv ...@@ -4243,7 +4252,7 @@ config_enum_lookup_name(struct config_enum *record, const char *value, int *retv
while (entry && entry->name) while (entry && entry->name)
{ {
if (!pg_strcasecmp(value, entry->name)) if (pg_strcasecmp(value, entry->name) == 0)
{ {
*retval = entry->val; *retval = entry->val;
return TRUE; return TRUE;
...@@ -4255,10 +4264,10 @@ config_enum_lookup_name(struct config_enum *record, const char *value, int *retv ...@@ -4255,10 +4264,10 @@ config_enum_lookup_name(struct config_enum *record, const char *value, int *retv
/* /*
* Returna list of all available options for an enum, separated * Return a list of all available options for an enum, separated
* by ", " (comma-space). * by ", " (comma-space).
* If prefix is gievn, it is added before the first enum value. * If prefix is non-NULL, it is added before the first enum value.
* If suffix is given, it is added to the end of the string. * If suffix is non-NULL, it is added to the end of the string.
*/ */
static char * static char *
config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix) 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, ...@@ -4895,8 +4904,9 @@ set_config_option(const char *name, const char *value,
{ {
ereport(elevel, ereport(elevel,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid value for parameter \"%s\": \"%d\"", errmsg("invalid value for parameter \"%s\": \"%s\"",
name, newval))); name,
config_enum_lookup_value(conf, newval))));
return false; return false;
} }
...@@ -5592,6 +5602,30 @@ DefineCustomStringVariable(const char *name, ...@@ -5592,6 +5602,30 @@ DefineCustomStringVariable(const char *name,
define_custom_variable(&var->gen); define_custom_variable(&var->gen);
} }
void
DefineCustomEnumVariable(const char *name,
const char *short_desc,
const char *long_desc,
int *valueAddr,
const struct config_enum_entry *options,
GucContext context,
GucEnumAssignHook assign_hook,
GucShowHook show_hook)
{
struct config_enum *var;
var = (struct config_enum *)
init_custom_variable(name, short_desc, long_desc, context,
PGC_ENUM, sizeof(struct config_enum));
var->variable = valueAddr;
var->boot_val = *valueAddr;
var->reset_val = *valueAddr;
var->options = options;
var->assign_hook = assign_hook;
var->show_hook = show_hook;
define_custom_variable(&var->gen);
}
void void
EmitWarningsOnPlaceholders(const char *className) EmitWarningsOnPlaceholders(const char *className)
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 2000-2008, PostgreSQL Global Development Group * Copyright (c) 2000-2008, PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.91 2008/03/10 12:55:13 mha Exp $ * $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.92 2008/03/16 16:42:44 mha Exp $
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
#ifndef GUC_H #ifndef GUC_H
...@@ -93,6 +93,16 @@ typedef enum ...@@ -93,6 +93,16 @@ typedef enum
PGC_S_SESSION /* SET command */ PGC_S_SESSION /* SET command */
} GucSource; } GucSource;
/*
* Enum values are made up of an array of name-value pairs
*/
struct config_enum_entry
{
const char *name;
int val;
};
typedef const char *(*GucStringAssignHook) (const char *newval, bool doit, GucSource source); typedef const char *(*GucStringAssignHook) (const char *newval, bool doit, GucSource source);
typedef bool (*GucBoolAssignHook) (bool newval, bool doit, GucSource source); typedef bool (*GucBoolAssignHook) (bool newval, bool doit, GucSource source);
typedef bool (*GucIntAssignHook) (int newval, bool doit, GucSource source); typedef bool (*GucIntAssignHook) (int newval, bool doit, GucSource source);
...@@ -189,6 +199,16 @@ extern void DefineCustomStringVariable( ...@@ -189,6 +199,16 @@ extern void DefineCustomStringVariable(
GucStringAssignHook assign_hook, GucStringAssignHook assign_hook,
GucShowHook show_hook); GucShowHook show_hook);
extern void DefineCustomEnumVariable(
const char *name,
const char *short_desc,
const char *long_desc,
int *valueAddr,
const struct config_enum_entry *options,
GucContext context,
GucEnumAssignHook assign_hook,
GucShowHook show_hook);
extern void EmitWarningsOnPlaceholders(const char *className); extern void EmitWarningsOnPlaceholders(const char *className);
extern const char *GetConfigOption(const char *name); extern const char *GetConfigOption(const char *name);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.39 2008/03/10 12:55:13 mha Exp $ * $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.40 2008/03/16 16:42:44 mha Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -37,15 +37,6 @@ union config_var_value ...@@ -37,15 +37,6 @@ union config_var_value
int enumval; int enumval;
}; };
/*
* Enum values are made up of an array of name-value pairs
*/
struct config_enum_entry
{
const char *name;
int val;
};
/* /*
* Groupings to help organize all the run-time options for display * Groupings to help organize all the run-time options for display
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment