static void set_config_sourcefile(const char *name, char *sourcefile,
int sourceline);
static void reapply_stacked_values(struct config_generic *variable,
- struct config_string *pHolder,
+ struct config_generic *pHolder,
GucStack *stack,
const char *curvalue,
GucContext curscontext, GucSource cursource,
Oid cursrole);
-static void free_placeholder(struct config_string *pHolder);
+static void free_placeholder(struct config_generic *pHolder);
static bool validate_option_array_item(const char *name, const char *value,
bool skipIfNoPermissions);
static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head);
int elevel);
static void do_serialize(char **destptr, Size *maxbytes,
const char *fmt,...) pg_attribute_printf(3, 4);
-static bool call_bool_check_hook(const struct config_bool *conf, bool *newval,
+static bool call_bool_check_hook(const struct config_generic *conf, bool *newval,
void **extra, GucSource source, int elevel);
-static bool call_int_check_hook(const struct config_int *conf, int *newval,
+static bool call_int_check_hook(const struct config_generic *conf, int *newval,
void **extra, GucSource source, int elevel);
-static bool call_real_check_hook(const struct config_real *conf, double *newval,
+static bool call_real_check_hook(const struct config_generic *conf, double *newval,
void **extra, GucSource source, int elevel);
-static bool call_string_check_hook(const struct config_string *conf, char **newval,
+static bool call_string_check_hook(const struct config_generic *conf, char **newval,
void **extra, GucSource source, int elevel);
-static bool call_enum_check_hook(const struct config_enum *conf, int *newval,
+static bool call_enum_check_hook(const struct config_generic *conf, int *newval,
void **extra, GucSource source, int elevel);
* Detect whether strval is referenced anywhere in a GUC string item
*/
static bool
-string_field_used(struct config_string *conf, char *strval)
+string_field_used(struct config_generic *conf, char *strval)
{
- if (strval == *(conf->variable) ||
- strval == conf->reset_val ||
- strval == conf->boot_val)
+ if (strval == *(conf->_string.variable) ||
+ strval == conf->_string.reset_val ||
+ strval == conf->_string.boot_val)
return true;
- for (GucStack *stack = conf->gen.stack; stack; stack = stack->prev)
+ for (GucStack *stack = conf->stack; stack; stack = stack->prev)
{
if (strval == stack->prior.val.stringval ||
strval == stack->masked.val.stringval)
* states).
*/
static void
-set_string_field(struct config_string *conf, char **field, char *newval)
+set_string_field(struct config_generic *conf, char **field, char *newval)
{
char *oldval = *field;
switch (gconf->vartype)
{
case PGC_BOOL:
- val->val.boolval =
- *((struct config_bool *) gconf)->variable;
+ val->val.boolval = *gconf->_bool.variable;
break;
case PGC_INT:
- val->val.intval =
- *((struct config_int *) gconf)->variable;
+ val->val.intval = *gconf->_int.variable;
break;
case PGC_REAL:
- val->val.realval =
- *((struct config_real *) gconf)->variable;
+ val->val.realval = *gconf->_real.variable;
break;
case PGC_STRING:
- set_string_field((struct config_string *) gconf,
- &(val->val.stringval),
- *((struct config_string *) gconf)->variable);
+ set_string_field(gconf, &(val->val.stringval), *gconf->_string.variable);
break;
case PGC_ENUM:
- val->val.enumval =
- *((struct config_enum *) gconf)->variable;
+ val->val.enumval = *gconf->_enum.variable;
break;
}
set_extra_field(gconf, &(val->extra), gconf->extra);
/* no need to do anything */
break;
case PGC_STRING:
- set_string_field((struct config_string *) gconf,
+ set_string_field(gconf,
&(val->val.stringval),
NULL);
break;
/*
* Count all the built-in variables.
*/
- for (int i = 0; ConfigureNamesBool[i].gen.name; i++)
- num_vars++;
-
- for (int i = 0; ConfigureNamesInt[i].gen.name; i++)
- num_vars++;
-
- for (int i = 0; ConfigureNamesReal[i].gen.name; i++)
- num_vars++;
-
- for (int i = 0; ConfigureNamesString[i].gen.name; i++)
- num_vars++;
-
- for (int i = 0; ConfigureNamesEnum[i].gen.name; i++)
+ for (int i = 0; ConfigureNames[i].name; i++)
num_vars++;
/*
&hash_ctl,
HASH_ELEM | HASH_FUNCTION | HASH_COMPARE | HASH_CONTEXT);
- for (int i = 0; ConfigureNamesBool[i].gen.name; i++)
- {
- struct config_generic *gucvar = &ConfigureNamesBool[i].gen;
-
- hentry = (GUCHashEntry *) hash_search(guc_hashtab,
- &gucvar->name,
- HASH_ENTER,
- &found);
- Assert(!found);
- hentry->gucvar = gucvar;
- }
-
- for (int i = 0; ConfigureNamesInt[i].gen.name; i++)
- {
- struct config_generic *gucvar = &ConfigureNamesInt[i].gen;
-
- hentry = (GUCHashEntry *) hash_search(guc_hashtab,
- &gucvar->name,
- HASH_ENTER,
- &found);
- Assert(!found);
- hentry->gucvar = gucvar;
- }
-
- for (int i = 0; ConfigureNamesReal[i].gen.name; i++)
- {
- struct config_generic *gucvar = &ConfigureNamesReal[i].gen;
-
- hentry = (GUCHashEntry *) hash_search(guc_hashtab,
- &gucvar->name,
- HASH_ENTER,
- &found);
- Assert(!found);
- hentry->gucvar = gucvar;
- }
-
- for (int i = 0; ConfigureNamesString[i].gen.name; i++)
- {
- struct config_generic *gucvar = &ConfigureNamesString[i].gen;
-
- hentry = (GUCHashEntry *) hash_search(guc_hashtab,
- &gucvar->name,
- HASH_ENTER,
- &found);
- Assert(!found);
- hentry->gucvar = gucvar;
- }
-
- for (int i = 0; ConfigureNamesEnum[i].gen.name; i++)
+ for (int i = 0; ConfigureNames[i].name; i++)
{
- struct config_generic *gucvar = &ConfigureNamesEnum[i].gen;
+ struct config_generic *gucvar = &ConfigureNames[i];
hentry = (GUCHashEntry *) hash_search(guc_hashtab,
&gucvar->name,
static struct config_generic *
add_placeholder_variable(const char *name, int elevel)
{
- size_t sz = sizeof(struct config_string) + sizeof(char *);
- struct config_string *var;
- struct config_generic *gen;
+ size_t sz = sizeof(struct config_generic) + sizeof(char *);
+ struct config_generic *var;
- var = (struct config_string *) guc_malloc(elevel, sz);
+ var = (struct config_generic *) guc_malloc(elevel, sz);
if (var == NULL)
return NULL;
memset(var, 0, sz);
- gen = &var->gen;
- gen->name = guc_strdup(elevel, name);
- if (gen->name == NULL)
+ var->name = guc_strdup(elevel, name);
+ if (var->name == NULL)
{
guc_free(var);
return NULL;
}
- gen->context = PGC_USERSET;
- gen->group = CUSTOM_OPTIONS;
- gen->short_desc = "GUC placeholder variable";
- gen->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
- gen->vartype = PGC_STRING;
+ var->context = PGC_USERSET;
+ var->group = CUSTOM_OPTIONS;
+ var->short_desc = "GUC placeholder variable";
+ var->flags = GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE | GUC_CUSTOM_PLACEHOLDER;
+ var->vartype = PGC_STRING;
/*
* The char* is allocated at the end of the struct since we have no
* 'static' place to point to. Note that the current value, as well as
* the boot and reset values, start out NULL.
*/
- var->variable = (char **) (var + 1);
+ var->_string.variable = (char **) (var + 1);
- if (!add_guc_variable((struct config_generic *) var, elevel))
+ if (!add_guc_variable(var, elevel))
{
- guc_free(unconstify(char *, gen->name));
+ guc_free(unconstify(char *, var->name));
guc_free(var);
return NULL;
}
- return gen;
+ return var;
}
/*
{
case PGC_BOOL:
{
- const struct config_bool *conf = (const struct config_bool *) gconf;
+ const struct config_bool *conf = &gconf->_bool;
if (*conf->variable && !conf->boot_val)
{
elog(LOG, "GUC (PGC_BOOL) %s, boot_val=%d, C-var=%d",
- conf->gen.name, conf->boot_val, *conf->variable);
+ gconf->name, conf->boot_val, *conf->variable);
return false;
}
break;
}
case PGC_INT:
{
- const struct config_int *conf = (const struct config_int *) gconf;
+ const struct config_int *conf = &gconf->_int;
if (*conf->variable != 0 && *conf->variable != conf->boot_val)
{
elog(LOG, "GUC (PGC_INT) %s, boot_val=%d, C-var=%d",
- conf->gen.name, conf->boot_val, *conf->variable);
+ gconf->name, conf->boot_val, *conf->variable);
return false;
}
break;
}
case PGC_REAL:
{
- const struct config_real *conf = (const struct config_real *) gconf;
+ const struct config_real *conf = &gconf->_real;
if (*conf->variable != 0.0 && *conf->variable != conf->boot_val)
{
elog(LOG, "GUC (PGC_REAL) %s, boot_val=%g, C-var=%g",
- conf->gen.name, conf->boot_val, *conf->variable);
+ gconf->name, conf->boot_val, *conf->variable);
return false;
}
break;
}
case PGC_STRING:
{
- const struct config_string *conf = (const struct config_string *) gconf;
+ const struct config_string *conf = &gconf->_string;
if (*conf->variable != NULL &&
(conf->boot_val == NULL ||
strcmp(*conf->variable, conf->boot_val) != 0))
{
elog(LOG, "GUC (PGC_STRING) %s, boot_val=%s, C-var=%s",
- conf->gen.name, conf->boot_val ? conf->boot_val : "<null>", *conf->variable);
+ gconf->name, conf->boot_val ? conf->boot_val : "<null>", *conf->variable);
return false;
}
break;
}
case PGC_ENUM:
{
- const struct config_enum *conf = (const struct config_enum *) gconf;
+ const struct config_enum *conf = &gconf->_enum;
if (*conf->variable != conf->boot_val)
{
elog(LOG, "GUC (PGC_ENUM) %s, boot_val=%d, C-var=%d",
- conf->gen.name, conf->boot_val, *conf->variable);
+ gconf->name, conf->boot_val, *conf->variable);
return false;
}
break;
{
case PGC_BOOL:
{
- struct config_bool *conf = (struct config_bool *) gconf;
+ struct config_bool *conf = &gconf->_bool;
bool newval = conf->boot_val;
- if (!call_bool_check_hook(conf, &newval, &extra,
+ if (!call_bool_check_hook(gconf, &newval, &extra,
PGC_S_DEFAULT, LOG))
elog(FATAL, "failed to initialize %s to %d",
- conf->gen.name, (int) newval);
+ gconf->name, (int) newval);
if (conf->assign_hook)
conf->assign_hook(newval, extra);
*conf->variable = conf->reset_val = newval;
}
case PGC_INT:
{
- struct config_int *conf = (struct config_int *) gconf;
+ struct config_int *conf = &gconf->_int;
int newval = conf->boot_val;
Assert(newval >= conf->min);
Assert(newval <= conf->max);
- if (!call_int_check_hook(conf, &newval, &extra,
+ if (!call_int_check_hook(gconf, &newval, &extra,
PGC_S_DEFAULT, LOG))
elog(FATAL, "failed to initialize %s to %d",
- conf->gen.name, newval);
+ gconf->name, newval);
if (conf->assign_hook)
conf->assign_hook(newval, extra);
*conf->variable = conf->reset_val = newval;
}
case PGC_REAL:
{
- struct config_real *conf = (struct config_real *) gconf;
+ struct config_real *conf = &gconf->_real;
double newval = conf->boot_val;
Assert(newval >= conf->min);
Assert(newval <= conf->max);
- if (!call_real_check_hook(conf, &newval, &extra,
+ if (!call_real_check_hook(gconf, &newval, &extra,
PGC_S_DEFAULT, LOG))
elog(FATAL, "failed to initialize %s to %g",
- conf->gen.name, newval);
+ gconf->name, newval);
if (conf->assign_hook)
conf->assign_hook(newval, extra);
*conf->variable = conf->reset_val = newval;
}
case PGC_STRING:
{
- struct config_string *conf = (struct config_string *) gconf;
+ struct config_string *conf = &gconf->_string;
char *newval;
/* non-NULL boot_val must always get strdup'd */
else
newval = NULL;
- if (!call_string_check_hook(conf, &newval, &extra,
+ if (!call_string_check_hook(gconf, &newval, &extra,
PGC_S_DEFAULT, LOG))
elog(FATAL, "failed to initialize %s to \"%s\"",
- conf->gen.name, newval ? newval : "");
+ gconf->name, newval ? newval : "");
if (conf->assign_hook)
conf->assign_hook(newval, extra);
*conf->variable = conf->reset_val = newval;
}
case PGC_ENUM:
{
- struct config_enum *conf = (struct config_enum *) gconf;
+ struct config_enum *conf = &gconf->_enum;
int newval = conf->boot_val;
- if (!call_enum_check_hook(conf, &newval, &extra,
+ if (!call_enum_check_hook(gconf, &newval, &extra,
PGC_S_DEFAULT, LOG))
elog(FATAL, "failed to initialize %s to %d",
- conf->gen.name, newval);
+ gconf->name, newval);
if (conf->assign_hook)
conf->assign_hook(newval, extra);
*conf->variable = conf->reset_val = newval;
char *fname;
bool fname_is_malloced;
struct stat stat_buf;
- struct config_string *data_directory_rec;
+ struct config_generic *data_directory_rec;
/* configdir is -D option, or $PGDATA if no -D */
if (userDoption)
* Note: SetDataDir will copy and absolute-ize its argument, so we don't
* have to.
*/
- data_directory_rec = (struct config_string *)
+ data_directory_rec =
find_option("data_directory", false, false, PANIC);
- if (*data_directory_rec->variable)
- SetDataDir(*data_directory_rec->variable);
+ if (*data_directory_rec->_string.variable)
+ SetDataDir(*data_directory_rec->_string.variable);
else if (configdir)
SetDataDir(configdir);
else
{
case PGC_BOOL:
{
- struct config_bool *conf = (struct config_bool *) gconf;
+ struct config_bool *conf = &gconf->_bool;
if (conf->assign_hook)
conf->assign_hook(conf->reset_val,
- conf->gen.reset_extra);
+ gconf->reset_extra);
*conf->variable = conf->reset_val;
- set_extra_field(&conf->gen, &conf->gen.extra,
- conf->gen.reset_extra);
+ set_extra_field(gconf, &gconf->extra,
+ gconf->reset_extra);
break;
}
case PGC_INT:
{
- struct config_int *conf = (struct config_int *) gconf;
+ struct config_int *conf = &gconf->_int;
if (conf->assign_hook)
conf->assign_hook(conf->reset_val,
- conf->gen.reset_extra);
+ gconf->reset_extra);
*conf->variable = conf->reset_val;
- set_extra_field(&conf->gen, &conf->gen.extra,
- conf->gen.reset_extra);
+ set_extra_field(gconf, &gconf->extra,
+ gconf->reset_extra);
break;
}
case PGC_REAL:
{
- struct config_real *conf = (struct config_real *) gconf;
+ struct config_real *conf = &gconf->_real;
if (conf->assign_hook)
conf->assign_hook(conf->reset_val,
- conf->gen.reset_extra);
+ gconf->reset_extra);
*conf->variable = conf->reset_val;
- set_extra_field(&conf->gen, &conf->gen.extra,
- conf->gen.reset_extra);
+ set_extra_field(gconf, &gconf->extra,
+ gconf->reset_extra);
break;
}
case PGC_STRING:
{
- struct config_string *conf = (struct config_string *) gconf;
+ struct config_string *conf = &gconf->_string;
if (conf->assign_hook)
conf->assign_hook(conf->reset_val,
- conf->gen.reset_extra);
- set_string_field(conf, conf->variable, conf->reset_val);
- set_extra_field(&conf->gen, &conf->gen.extra,
- conf->gen.reset_extra);
+ gconf->reset_extra);
+ set_string_field(gconf, conf->variable, conf->reset_val);
+ set_extra_field(gconf, &gconf->extra,
+ gconf->reset_extra);
break;
}
case PGC_ENUM:
{
- struct config_enum *conf = (struct config_enum *) gconf;
+ struct config_enum *conf = &gconf->_enum;
if (conf->assign_hook)
conf->assign_hook(conf->reset_val,
- conf->gen.reset_extra);
+ gconf->reset_extra);
*conf->variable = conf->reset_val;
- set_extra_field(&conf->gen, &conf->gen.extra,
- conf->gen.reset_extra);
+ set_extra_field(gconf, &gconf->extra,
+ gconf->reset_extra);
break;
}
}
{
case PGC_BOOL:
{
- struct config_bool *conf = (struct config_bool *) gconf;
+ struct config_bool *conf = &gconf->_bool;
bool newval = newvalue.val.boolval;
void *newextra = newvalue.extra;
if (*conf->variable != newval ||
- conf->gen.extra != newextra)
+ gconf->extra != newextra)
{
if (conf->assign_hook)
conf->assign_hook(newval, newextra);
*conf->variable = newval;
- set_extra_field(&conf->gen, &conf->gen.extra,
+ set_extra_field(gconf, &gconf->extra,
newextra);
changed = true;
}
}
case PGC_INT:
{
- struct config_int *conf = (struct config_int *) gconf;
+ struct config_int *conf = &gconf->_int;
int newval = newvalue.val.intval;
void *newextra = newvalue.extra;
if (*conf->variable != newval ||
- conf->gen.extra != newextra)
+ gconf->extra != newextra)
{
if (conf->assign_hook)
conf->assign_hook(newval, newextra);
*conf->variable = newval;
- set_extra_field(&conf->gen, &conf->gen.extra,
+ set_extra_field(gconf, &gconf->extra,
newextra);
changed = true;
}
}
case PGC_REAL:
{
- struct config_real *conf = (struct config_real *) gconf;
+ struct config_real *conf = &gconf->_real;
double newval = newvalue.val.realval;
void *newextra = newvalue.extra;
if (*conf->variable != newval ||
- conf->gen.extra != newextra)
+ gconf->extra != newextra)
{
if (conf->assign_hook)
conf->assign_hook(newval, newextra);
*conf->variable = newval;
- set_extra_field(&conf->gen, &conf->gen.extra,
+ set_extra_field(gconf, &gconf->extra,
newextra);
changed = true;
}
}
case PGC_STRING:
{
- struct config_string *conf = (struct config_string *) gconf;
+ struct config_string *conf = &gconf->_string;
char *newval = newvalue.val.stringval;
void *newextra = newvalue.extra;
if (*conf->variable != newval ||
- conf->gen.extra != newextra)
+ gconf->extra != newextra)
{
if (conf->assign_hook)
conf->assign_hook(newval, newextra);
- set_string_field(conf, conf->variable, newval);
- set_extra_field(&conf->gen, &conf->gen.extra,
+ set_string_field(gconf, conf->variable, newval);
+ set_extra_field(gconf, &gconf->extra,
newextra);
changed = true;
}
* we have type-specific code anyway, might as
* well inline it.
*/
- set_string_field(conf, &stack->prior.val.stringval, NULL);
- set_string_field(conf, &stack->masked.val.stringval, NULL);
+ set_string_field(gconf, &stack->prior.val.stringval, NULL);
+ set_string_field(gconf, &stack->masked.val.stringval, NULL);
break;
}
case PGC_ENUM:
{
- struct config_enum *conf = (struct config_enum *) gconf;
+ struct config_enum *conf = &gconf->_enum;
int newval = newvalue.val.enumval;
void *newextra = newvalue.extra;
if (*conf->variable != newval ||
- conf->gen.extra != newextra)
+ gconf->extra != newextra)
{
if (conf->assign_hook)
conf->assign_hook(newval, newextra);
*conf->variable = newval;
- set_extra_field(&conf->gen, &conf->gen.extra,
+ set_extra_field(gconf, &gconf->extra,
newextra);
changed = true;
}
* allocated for modification.
*/
const char *
-config_enum_lookup_by_value(const struct config_enum *record, int val)
+config_enum_lookup_by_value(const struct config_generic *record, int val)
{
- for (const struct config_enum_entry *entry = record->options; entry && entry->name; entry++)
+ for (const struct config_enum_entry *entry = record->_enum.options; entry && entry->name; entry++)
{
if (entry->val == val)
return entry->name;
}
elog(ERROR, "could not find enum option %d for %s",
- val, record->gen.name);
+ val, record->name);
return NULL; /* silence compiler */
}
{
case PGC_BOOL:
{
- const struct config_bool *conf = (const struct config_bool *) record;
-
if (!parse_bool(value, &newval->boolval))
{
ereport(elevel,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("parameter \"%s\" requires a Boolean value",
- conf->gen.name)));
+ record->name)));
return false;
}
- if (!call_bool_check_hook(conf, &newval->boolval, newextra,
+ if (!call_bool_check_hook(record, &newval->boolval, newextra,
source, elevel))
return false;
}
break;
case PGC_INT:
{
- const struct config_int *conf = (const struct config_int *) record;
+ const struct config_int *conf = &record->_int;
const char *hintmsg;
if (!parse_int(value, &newval->intval,
- conf->gen.flags, &hintmsg))
+ record->flags, &hintmsg))
{
ereport(elevel,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid value for parameter \"%s\": \"%s\"",
- conf->gen.name, value),
+ record->name, value),
hintmsg ? errhint("%s", _(hintmsg)) : 0));
return false;
}
if (newval->intval < conf->min || newval->intval > conf->max)
{
- const char *unit = get_config_unit_name(conf->gen.flags);
+ const char *unit = get_config_unit_name(record->flags);
const char *unitspace;
if (unit)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("%d%s%s is outside the valid range for parameter \"%s\" (%d%s%s .. %d%s%s)",
newval->intval, unitspace, unit,
- conf->gen.name,
+ record->name,
conf->min, unitspace, unit,
conf->max, unitspace, unit)));
return false;
}
- if (!call_int_check_hook(conf, &newval->intval, newextra,
+ if (!call_int_check_hook(record, &newval->intval, newextra,
source, elevel))
return false;
}
break;
case PGC_REAL:
{
- const struct config_real *conf = (const struct config_real *) record;
+ const struct config_real *conf = &record->_real;
const char *hintmsg;
if (!parse_real(value, &newval->realval,
- conf->gen.flags, &hintmsg))
+ record->flags, &hintmsg))
{
ereport(elevel,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid value for parameter \"%s\": \"%s\"",
- conf->gen.name, value),
+ record->name, value),
hintmsg ? errhint("%s", _(hintmsg)) : 0));
return false;
}
if (newval->realval < conf->min || newval->realval > conf->max)
{
- const char *unit = get_config_unit_name(conf->gen.flags);
+ const char *unit = get_config_unit_name(record->flags);
const char *unitspace;
if (unit)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("%g%s%s is outside the valid range for parameter \"%s\" (%g%s%s .. %g%s%s)",
newval->realval, unitspace, unit,
- conf->gen.name,
+ record->name,
conf->min, unitspace, unit,
conf->max, unitspace, unit)));
return false;
}
- if (!call_real_check_hook(conf, &newval->realval, newextra,
+ if (!call_real_check_hook(record, &newval->realval, newextra,
source, elevel))
return false;
}
break;
case PGC_STRING:
{
- const struct config_string *conf = (const struct config_string *) record;
-
/*
* The value passed by the caller could be transient, so we
* always strdup it.
* The only built-in "parsing" check we have is to apply
* truncation if GUC_IS_NAME.
*/
- if (conf->gen.flags & GUC_IS_NAME)
+ if (record->flags & GUC_IS_NAME)
truncate_identifier(newval->stringval,
strlen(newval->stringval),
true);
- if (!call_string_check_hook(conf, &newval->stringval, newextra,
+ if (!call_string_check_hook(record, &newval->stringval, newextra,
source, elevel))
{
guc_free(newval->stringval);
break;
case PGC_ENUM:
{
- const struct config_enum *conf = (const struct config_enum *) record;
+ const struct config_enum *conf = &record->_enum;
if (!config_enum_lookup_by_name(conf, value, &newval->enumval))
{
ereport(elevel,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid value for parameter \"%s\": \"%s\"",
- conf->gen.name, value),
+ record->name, value),
hintmsg ? errhint("%s", _(hintmsg)) : 0));
if (hintmsg)
return false;
}
- if (!call_enum_check_hook(conf, &newval->enumval, newextra,
+ if (!call_enum_check_hook(record, &newval->enumval, newextra,
source, elevel))
return false;
}
{
case PGC_BOOL:
{
- struct config_bool *conf = (struct config_bool *) record;
+ struct config_bool *conf = &record->_bool;
#define newval (newval_union.boolval)
else if (source == PGC_S_DEFAULT)
{
newval = conf->boot_val;
- if (!call_bool_check_hook(conf, &newval, &newextra,
+ if (!call_bool_check_hook(record, &newval, &newextra,
source, elevel))
return 0;
}
else
{
newval = conf->reset_val;
- newextra = conf->gen.reset_extra;
- source = conf->gen.reset_source;
- context = conf->gen.reset_scontext;
- srole = conf->gen.reset_srole;
+ newextra = record->reset_extra;
+ source = record->reset_source;
+ context = record->reset_scontext;
+ srole = record->reset_srole;
}
if (prohibitValueChange)
{
/* Release newextra, unless it's reset_extra */
- if (newextra && !extra_field_used(&conf->gen, newextra))
+ if (newextra && !extra_field_used(record, newextra))
guc_free(newextra);
if (*conf->variable != newval)
ereport(elevel,
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
errmsg("parameter \"%s\" cannot be changed without restarting the server",
- conf->gen.name)));
+ record->name)));
return 0;
}
record->status &= ~GUC_PENDING_RESTART;
{
/* Save old value to support transaction abort */
if (!makeDefault)
- push_old_value(&conf->gen, action);
+ push_old_value(record, action);
if (conf->assign_hook)
conf->assign_hook(newval, newextra);
*conf->variable = newval;
- set_extra_field(&conf->gen, &conf->gen.extra,
+ set_extra_field(record, &record->extra,
newextra);
- set_guc_source(&conf->gen, source);
- conf->gen.scontext = context;
- conf->gen.srole = srole;
+ set_guc_source(record, source);
+ record->scontext = context;
+ record->srole = srole;
}
if (makeDefault)
{
- if (conf->gen.reset_source <= source)
+ if (record->reset_source <= source)
{
conf->reset_val = newval;
- set_extra_field(&conf->gen, &conf->gen.reset_extra,
+ set_extra_field(record, &record->reset_extra,
newextra);
- conf->gen.reset_source = source;
- conf->gen.reset_scontext = context;
- conf->gen.reset_srole = srole;
+ record->reset_source = source;
+ record->reset_scontext = context;
+ record->reset_srole = srole;
}
- for (GucStack *stack = conf->gen.stack; stack; stack = stack->prev)
+ for (GucStack *stack = record->stack; stack; stack = stack->prev)
{
if (stack->source <= source)
{
stack->prior.val.boolval = newval;
- set_extra_field(&conf->gen, &stack->prior.extra,
+ set_extra_field(record, &stack->prior.extra,
newextra);
stack->source = source;
stack->scontext = context;
}
/* Perhaps we didn't install newextra anywhere */
- if (newextra && !extra_field_used(&conf->gen, newextra))
+ if (newextra && !extra_field_used(record, newextra))
guc_free(newextra);
break;
case PGC_INT:
{
- struct config_int *conf = (struct config_int *) record;
+ struct config_int *conf = &record->_int;
#define newval (newval_union.intval)
else if (source == PGC_S_DEFAULT)
{
newval = conf->boot_val;
- if (!call_int_check_hook(conf, &newval, &newextra,
+ if (!call_int_check_hook(record, &newval, &newextra,
source, elevel))
return 0;
}
else
{
newval = conf->reset_val;
- newextra = conf->gen.reset_extra;
- source = conf->gen.reset_source;
- context = conf->gen.reset_scontext;
- srole = conf->gen.reset_srole;
+ newextra = record->reset_extra;
+ source = record->reset_source;
+ context = record->reset_scontext;
+ srole = record->reset_srole;
}
if (prohibitValueChange)
{
/* Release newextra, unless it's reset_extra */
- if (newextra && !extra_field_used(&conf->gen, newextra))
+ if (newextra && !extra_field_used(record, newextra))
guc_free(newextra);
if (*conf->variable != newval)
ereport(elevel,
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
errmsg("parameter \"%s\" cannot be changed without restarting the server",
- conf->gen.name)));
+ record->name)));
return 0;
}
record->status &= ~GUC_PENDING_RESTART;
{
/* Save old value to support transaction abort */
if (!makeDefault)
- push_old_value(&conf->gen, action);
+ push_old_value(record, action);
if (conf->assign_hook)
conf->assign_hook(newval, newextra);
*conf->variable = newval;
- set_extra_field(&conf->gen, &conf->gen.extra,
+ set_extra_field(record, &record->extra,
newextra);
- set_guc_source(&conf->gen, source);
- conf->gen.scontext = context;
- conf->gen.srole = srole;
+ set_guc_source(record, source);
+ record->scontext = context;
+ record->srole = srole;
}
if (makeDefault)
{
- if (conf->gen.reset_source <= source)
+ if (record->reset_source <= source)
{
conf->reset_val = newval;
- set_extra_field(&conf->gen, &conf->gen.reset_extra,
+ set_extra_field(record, &record->reset_extra,
newextra);
- conf->gen.reset_source = source;
- conf->gen.reset_scontext = context;
- conf->gen.reset_srole = srole;
+ record->reset_source = source;
+ record->reset_scontext = context;
+ record->reset_srole = srole;
}
- for (GucStack *stack = conf->gen.stack; stack; stack = stack->prev)
+ for (GucStack *stack = record->stack; stack; stack = stack->prev)
{
if (stack->source <= source)
{
stack->prior.val.intval = newval;
- set_extra_field(&conf->gen, &stack->prior.extra,
+ set_extra_field(record, &stack->prior.extra,
newextra);
stack->source = source;
stack->scontext = context;
}
/* Perhaps we didn't install newextra anywhere */
- if (newextra && !extra_field_used(&conf->gen, newextra))
+ if (newextra && !extra_field_used(record, newextra))
guc_free(newextra);
break;
case PGC_REAL:
{
- struct config_real *conf = (struct config_real *) record;
+ struct config_real *conf = &record->_real;
#define newval (newval_union.realval)
else if (source == PGC_S_DEFAULT)
{
newval = conf->boot_val;
- if (!call_real_check_hook(conf, &newval, &newextra,
+ if (!call_real_check_hook(record, &newval, &newextra,
source, elevel))
return 0;
}
else
{
newval = conf->reset_val;
- newextra = conf->gen.reset_extra;
- source = conf->gen.reset_source;
- context = conf->gen.reset_scontext;
- srole = conf->gen.reset_srole;
+ newextra = record->reset_extra;
+ source = record->reset_source;
+ context = record->reset_scontext;
+ srole = record->reset_srole;
}
if (prohibitValueChange)
{
/* Release newextra, unless it's reset_extra */
- if (newextra && !extra_field_used(&conf->gen, newextra))
+ if (newextra && !extra_field_used(record, newextra))
guc_free(newextra);
if (*conf->variable != newval)
ereport(elevel,
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
errmsg("parameter \"%s\" cannot be changed without restarting the server",
- conf->gen.name)));
+ record->name)));
return 0;
}
record->status &= ~GUC_PENDING_RESTART;
{
/* Save old value to support transaction abort */
if (!makeDefault)
- push_old_value(&conf->gen, action);
+ push_old_value(record, action);
if (conf->assign_hook)
conf->assign_hook(newval, newextra);
*conf->variable = newval;
- set_extra_field(&conf->gen, &conf->gen.extra,
+ set_extra_field(record, &record->extra,
newextra);
- set_guc_source(&conf->gen, source);
- conf->gen.scontext = context;
- conf->gen.srole = srole;
+ set_guc_source(record, source);
+ record->scontext = context;
+ record->srole = srole;
}
if (makeDefault)
{
- if (conf->gen.reset_source <= source)
+ if (record->reset_source <= source)
{
conf->reset_val = newval;
- set_extra_field(&conf->gen, &conf->gen.reset_extra,
+ set_extra_field(record, &record->reset_extra,
newextra);
- conf->gen.reset_source = source;
- conf->gen.reset_scontext = context;
- conf->gen.reset_srole = srole;
+ record->reset_source = source;
+ record->reset_scontext = context;
+ record->reset_srole = srole;
}
- for (GucStack *stack = conf->gen.stack; stack; stack = stack->prev)
+ for (GucStack *stack = record->stack; stack; stack = stack->prev)
{
if (stack->source <= source)
{
stack->prior.val.realval = newval;
- set_extra_field(&conf->gen, &stack->prior.extra,
+ set_extra_field(record, &stack->prior.extra,
newextra);
stack->source = source;
stack->scontext = context;
}
/* Perhaps we didn't install newextra anywhere */
- if (newextra && !extra_field_used(&conf->gen, newextra))
+ if (newextra && !extra_field_used(record, newextra))
guc_free(newextra);
break;
case PGC_STRING:
{
- struct config_string *conf = (struct config_string *) record;
+ struct config_string *conf = &record->_string;
GucContext orig_context = context;
GucSource orig_source = source;
Oid orig_srole = srole;
else
newval = NULL;
- if (!call_string_check_hook(conf, &newval, &newextra,
+ if (!call_string_check_hook(record, &newval, &newextra,
source, elevel))
{
guc_free(newval);
* guc.c's control
*/
newval = conf->reset_val;
- newextra = conf->gen.reset_extra;
- source = conf->gen.reset_source;
- context = conf->gen.reset_scontext;
- srole = conf->gen.reset_srole;
+ newextra = record->reset_extra;
+ source = record->reset_source;
+ context = record->reset_scontext;
+ srole = record->reset_srole;
}
if (prohibitValueChange)
strcmp(*conf->variable, newval) != 0);
/* Release newval, unless it's reset_val */
- if (newval && !string_field_used(conf, newval))
+ if (newval && !string_field_used(record, newval))
guc_free(newval);
/* Release newextra, unless it's reset_extra */
- if (newextra && !extra_field_used(&conf->gen, newextra))
+ if (newextra && !extra_field_used(record, newextra))
guc_free(newextra);
if (newval_different)
ereport(elevel,
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
errmsg("parameter \"%s\" cannot be changed without restarting the server",
- conf->gen.name)));
+ record->name)));
return 0;
}
record->status &= ~GUC_PENDING_RESTART;
{
/* Save old value to support transaction abort */
if (!makeDefault)
- push_old_value(&conf->gen, action);
+ push_old_value(record, action);
if (conf->assign_hook)
conf->assign_hook(newval, newextra);
- set_string_field(conf, conf->variable, newval);
- set_extra_field(&conf->gen, &conf->gen.extra,
+ set_string_field(record, conf->variable, newval);
+ set_extra_field(record, &record->extra,
newextra);
- set_guc_source(&conf->gen, source);
- conf->gen.scontext = context;
- conf->gen.srole = srole;
+ set_guc_source(record, source);
+ record->scontext = context;
+ record->srole = srole;
/*
* Ugly hack: during SET session_authorization, forcibly
* that.
*/
if (!is_reload &&
- strcmp(conf->gen.name, "session_authorization") == 0)
+ strcmp(record->name, "session_authorization") == 0)
(void) set_config_with_handle("role", NULL,
value ? "none" : NULL,
orig_context,
if (makeDefault)
{
- if (conf->gen.reset_source <= source)
+ if (record->reset_source <= source)
{
- set_string_field(conf, &conf->reset_val, newval);
- set_extra_field(&conf->gen, &conf->gen.reset_extra,
+ set_string_field(record, &conf->reset_val, newval);
+ set_extra_field(record, &record->reset_extra,
newextra);
- conf->gen.reset_source = source;
- conf->gen.reset_scontext = context;
- conf->gen.reset_srole = srole;
+ record->reset_source = source;
+ record->reset_scontext = context;
+ record->reset_srole = srole;
}
- for (GucStack *stack = conf->gen.stack; stack; stack = stack->prev)
+ for (GucStack *stack = record->stack; stack; stack = stack->prev)
{
if (stack->source <= source)
{
- set_string_field(conf, &stack->prior.val.stringval,
+ set_string_field(record, &stack->prior.val.stringval,
newval);
- set_extra_field(&conf->gen, &stack->prior.extra,
+ set_extra_field(record, &stack->prior.extra,
newextra);
stack->source = source;
stack->scontext = context;
}
/* Perhaps we didn't install newval anywhere */
- if (newval && !string_field_used(conf, newval))
+ if (newval && !string_field_used(record, newval))
guc_free(newval);
/* Perhaps we didn't install newextra anywhere */
- if (newextra && !extra_field_used(&conf->gen, newextra))
+ if (newextra && !extra_field_used(record, newextra))
guc_free(newextra);
break;
case PGC_ENUM:
{
- struct config_enum *conf = (struct config_enum *) record;
+ struct config_enum *conf = &record->_enum;
#define newval (newval_union.enumval)
else if (source == PGC_S_DEFAULT)
{
newval = conf->boot_val;
- if (!call_enum_check_hook(conf, &newval, &newextra,
+ if (!call_enum_check_hook(record, &newval, &newextra,
source, elevel))
return 0;
}
else
{
newval = conf->reset_val;
- newextra = conf->gen.reset_extra;
- source = conf->gen.reset_source;
- context = conf->gen.reset_scontext;
- srole = conf->gen.reset_srole;
+ newextra = record->reset_extra;
+ source = record->reset_source;
+ context = record->reset_scontext;
+ srole = record->reset_srole;
}
if (prohibitValueChange)
{
/* Release newextra, unless it's reset_extra */
- if (newextra && !extra_field_used(&conf->gen, newextra))
+ if (newextra && !extra_field_used(record, newextra))
guc_free(newextra);
if (*conf->variable != newval)
ereport(elevel,
(errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
errmsg("parameter \"%s\" cannot be changed without restarting the server",
- conf->gen.name)));
+ record->name)));
return 0;
}
record->status &= ~GUC_PENDING_RESTART;
{
/* Save old value to support transaction abort */
if (!makeDefault)
- push_old_value(&conf->gen, action);
+ push_old_value(record, action);
if (conf->assign_hook)
conf->assign_hook(newval, newextra);
*conf->variable = newval;
- set_extra_field(&conf->gen, &conf->gen.extra,
+ set_extra_field(record, &record->extra,
newextra);
- set_guc_source(&conf->gen, source);
- conf->gen.scontext = context;
- conf->gen.srole = srole;
+ set_guc_source(record, source);
+ record->scontext = context;
+ record->srole = srole;
}
if (makeDefault)
{
- if (conf->gen.reset_source <= source)
+ if (record->reset_source <= source)
{
conf->reset_val = newval;
- set_extra_field(&conf->gen, &conf->gen.reset_extra,
+ set_extra_field(record, &record->reset_extra,
newextra);
- conf->gen.reset_source = source;
- conf->gen.reset_scontext = context;
- conf->gen.reset_srole = srole;
+ record->reset_source = source;
+ record->reset_scontext = context;
+ record->reset_srole = srole;
}
- for (GucStack *stack = conf->gen.stack; stack; stack = stack->prev)
+ for (GucStack *stack = record->stack; stack; stack = stack->prev)
{
if (stack->source <= source)
{
stack->prior.val.enumval = newval;
- set_extra_field(&conf->gen, &stack->prior.extra,
+ set_extra_field(record, &stack->prior.extra,
newextra);
stack->source = source;
stack->scontext = context;
}
/* Perhaps we didn't install newextra anywhere */
- if (newextra && !extra_field_used(&conf->gen, newextra))
+ if (newextra && !extra_field_used(record, newextra))
guc_free(newextra);
break;
switch (record->vartype)
{
case PGC_BOOL:
- return *((struct config_bool *) record)->variable ? "on" : "off";
+ return *record->_bool.variable ? "on" : "off";
case PGC_INT:
snprintf(buffer, sizeof(buffer), "%d",
- *((struct config_int *) record)->variable);
+ *record->_int.variable);
return buffer;
case PGC_REAL:
snprintf(buffer, sizeof(buffer), "%g",
- *((struct config_real *) record)->variable);
+ *record->_real.variable);
return buffer;
case PGC_STRING:
- return *((struct config_string *) record)->variable ?
- *((struct config_string *) record)->variable : "";
+ return *record->_string.variable ?
+ *record->_string.variable : "";
case PGC_ENUM:
- return config_enum_lookup_by_value((struct config_enum *) record,
- *((struct config_enum *) record)->variable);
+ return config_enum_lookup_by_value(record,
+ *record->_enum.variable);
}
return NULL;
}
switch (record->vartype)
{
case PGC_BOOL:
- return ((struct config_bool *) record)->reset_val ? "on" : "off";
+ return record->_bool.reset_val ? "on" : "off";
case PGC_INT:
snprintf(buffer, sizeof(buffer), "%d",
- ((struct config_int *) record)->reset_val);
+ record->_int.reset_val);
return buffer;
case PGC_REAL:
snprintf(buffer, sizeof(buffer), "%g",
- ((struct config_real *) record)->reset_val);
+ record->_real.reset_val);
return buffer;
case PGC_STRING:
- return ((struct config_string *) record)->reset_val ?
- ((struct config_string *) record)->reset_val : "";
+ return record->_string.reset_val ?
+ record->_string.reset_val : "";
case PGC_ENUM:
- return config_enum_lookup_by_value((struct config_enum *) record,
- ((struct config_enum *) record)->reset_val);
+ return config_enum_lookup_by_value(record,
+ record->_enum.reset_val);
}
return NULL;
}
const char *long_desc,
GucContext context,
int flags,
- enum config_type type,
- size_t sz)
+ enum config_type type)
{
struct config_generic *gen;
context = PGC_SUSET;
/* As above, an OOM here is FATAL */
- gen = (struct config_generic *) guc_malloc(FATAL, sz);
- memset(gen, 0, sz);
+ gen = (struct config_generic *) guc_malloc(FATAL, sizeof(struct config_generic));
+ memset(gen, 0, sizeof(struct config_generic));
gen->name = guc_strdup(FATAL, name);
gen->context = context;
{
const char *name = variable->name;
GUCHashEntry *hentry;
- struct config_string *pHolder;
+ struct config_generic *pHolder;
/* Check mapping between initial and default value */
Assert(check_GUC_init(variable));
errmsg("attempt to redefine parameter \"%s\"", name)));
Assert(hentry->gucvar->vartype == PGC_STRING);
- pHolder = (struct config_string *) hentry->gucvar;
+ pHolder = hentry->gucvar;
/*
* First, set the variable to its default value. We must do this even
/*
* Remove the placeholder from any lists it's in, too.
*/
- RemoveGUCFromLists(&pHolder->gen);
+ RemoveGUCFromLists(pHolder);
/*
* Assign the string value(s) stored in the placeholder to the real
*/
/* First, apply the reset value if any */
- if (pHolder->reset_val)
- (void) set_config_option_ext(name, pHolder->reset_val,
- pHolder->gen.reset_scontext,
- pHolder->gen.reset_source,
- pHolder->gen.reset_srole,
+ if (pHolder->_string.reset_val)
+ (void) set_config_option_ext(name, pHolder->_string.reset_val,
+ pHolder->reset_scontext,
+ pHolder->reset_source,
+ pHolder->reset_srole,
GUC_ACTION_SET, true, WARNING, false);
/* That should not have resulted in stacking anything */
Assert(variable->stack == NULL);
/* Now, apply current and stacked values, in the order they were stacked */
- reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
- *(pHolder->variable),
- pHolder->gen.scontext, pHolder->gen.source,
- pHolder->gen.srole);
+ reapply_stacked_values(variable, pHolder, pHolder->stack,
+ *(pHolder->_string.variable),
+ pHolder->scontext, pHolder->source,
+ pHolder->srole);
/* Also copy over any saved source-location information */
- if (pHolder->gen.sourcefile)
- set_config_sourcefile(name, pHolder->gen.sourcefile,
- pHolder->gen.sourceline);
+ if (pHolder->sourcefile)
+ set_config_sourcefile(name, pHolder->sourcefile,
+ pHolder->sourceline);
/* Now we can free the no-longer-referenced placeholder variable */
free_placeholder(pHolder);
*/
static void
reapply_stacked_values(struct config_generic *variable,
- struct config_string *pHolder,
+ struct config_generic *pHolder,
GucStack *stack,
const char *curvalue,
GucContext curscontext, GucSource cursource,
* this is to be just a transactional assignment. (We leak the stack
* entry.)
*/
- if (curvalue != pHolder->reset_val ||
- curscontext != pHolder->gen.reset_scontext ||
- cursource != pHolder->gen.reset_source ||
- cursrole != pHolder->gen.reset_srole)
+ if (curvalue != pHolder->_string.reset_val ||
+ curscontext != pHolder->reset_scontext ||
+ cursource != pHolder->reset_source ||
+ cursrole != pHolder->reset_srole)
{
(void) set_config_option_ext(name, curvalue,
curscontext, cursource, cursrole,
* doesn't seem worth spending much code on.
*/
static void
-free_placeholder(struct config_string *pHolder)
+free_placeholder(struct config_generic *pHolder)
{
/* Placeholders are always STRING type, so free their values */
- Assert(pHolder->gen.vartype == PGC_STRING);
- set_string_field(pHolder, pHolder->variable, NULL);
- set_string_field(pHolder, &pHolder->reset_val, NULL);
+ Assert(pHolder->vartype == PGC_STRING);
+ set_string_field(pHolder, pHolder->_string.variable, NULL);
+ set_string_field(pHolder, &pHolder->_string.reset_val, NULL);
- guc_free(unconstify(char *, pHolder->gen.name));
+ guc_free(unconstify(char *, pHolder->name));
guc_free(pHolder);
}
GucBoolAssignHook assign_hook,
GucShowHook show_hook)
{
- struct config_bool *var;
-
- var = (struct config_bool *)
- init_custom_variable(name, short_desc, long_desc, context, flags,
- PGC_BOOL, sizeof(struct config_bool));
- var->variable = valueAddr;
- var->boot_val = bootValue;
- var->reset_val = bootValue;
- var->check_hook = check_hook;
- var->assign_hook = assign_hook;
- var->show_hook = show_hook;
- define_custom_variable(&var->gen);
+ struct config_generic *var;
+
+ var = init_custom_variable(name, short_desc, long_desc, context, flags, PGC_BOOL);
+ var->_bool.variable = valueAddr;
+ var->_bool.boot_val = bootValue;
+ var->_bool.reset_val = bootValue;
+ var->_bool.check_hook = check_hook;
+ var->_bool.assign_hook = assign_hook;
+ var->_bool.show_hook = show_hook;
+ define_custom_variable(var);
}
void
GucIntAssignHook assign_hook,
GucShowHook show_hook)
{
- struct config_int *var;
-
- var = (struct config_int *)
- init_custom_variable(name, short_desc, long_desc, context, flags,
- PGC_INT, sizeof(struct config_int));
- var->variable = valueAddr;
- var->boot_val = bootValue;
- var->reset_val = bootValue;
- var->min = minValue;
- var->max = maxValue;
- var->check_hook = check_hook;
- var->assign_hook = assign_hook;
- var->show_hook = show_hook;
- define_custom_variable(&var->gen);
+ struct config_generic *var;
+
+ var = init_custom_variable(name, short_desc, long_desc, context, flags, PGC_INT);
+ var->_int.variable = valueAddr;
+ var->_int.boot_val = bootValue;
+ var->_int.reset_val = bootValue;
+ var->_int.min = minValue;
+ var->_int.max = maxValue;
+ var->_int.check_hook = check_hook;
+ var->_int.assign_hook = assign_hook;
+ var->_int.show_hook = show_hook;
+ define_custom_variable(var);
}
void
GucRealAssignHook assign_hook,
GucShowHook show_hook)
{
- struct config_real *var;
-
- var = (struct config_real *)
- init_custom_variable(name, short_desc, long_desc, context, flags,
- PGC_REAL, sizeof(struct config_real));
- var->variable = valueAddr;
- var->boot_val = bootValue;
- var->reset_val = bootValue;
- var->min = minValue;
- var->max = maxValue;
- var->check_hook = check_hook;
- var->assign_hook = assign_hook;
- var->show_hook = show_hook;
- define_custom_variable(&var->gen);
+ struct config_generic *var;
+
+ var = init_custom_variable(name, short_desc, long_desc, context, flags, PGC_REAL);
+ var->_real.variable = valueAddr;
+ var->_real.boot_val = bootValue;
+ var->_real.reset_val = bootValue;
+ var->_real.min = minValue;
+ var->_real.max = maxValue;
+ var->_real.check_hook = check_hook;
+ var->_real.assign_hook = assign_hook;
+ var->_real.show_hook = show_hook;
+ define_custom_variable(var);
}
void
GucStringAssignHook assign_hook,
GucShowHook show_hook)
{
- struct config_string *var;
-
- var = (struct config_string *)
- init_custom_variable(name, short_desc, long_desc, context, flags,
- PGC_STRING, sizeof(struct config_string));
- var->variable = valueAddr;
- var->boot_val = bootValue;
- var->check_hook = check_hook;
- var->assign_hook = assign_hook;
- var->show_hook = show_hook;
- define_custom_variable(&var->gen);
+ struct config_generic *var;
+
+ var = init_custom_variable(name, short_desc, long_desc, context, flags, PGC_STRING);
+ var->_string.variable = valueAddr;
+ var->_string.boot_val = bootValue;
+ var->_string.check_hook = check_hook;
+ var->_string.assign_hook = assign_hook;
+ var->_string.show_hook = show_hook;
+ define_custom_variable(var);
}
void
GucEnumAssignHook assign_hook,
GucShowHook show_hook)
{
- struct config_enum *var;
-
- var = (struct config_enum *)
- init_custom_variable(name, short_desc, long_desc, context, flags,
- PGC_ENUM, sizeof(struct config_enum));
- var->variable = valueAddr;
- var->boot_val = bootValue;
- var->reset_val = bootValue;
- var->options = options;
- var->check_hook = check_hook;
- var->assign_hook = assign_hook;
- var->show_hook = show_hook;
- define_custom_variable(&var->gen);
+ struct config_generic *var;
+
+ var = init_custom_variable(name, short_desc, long_desc, context, flags, PGC_ENUM);
+ var->_enum.variable = valueAddr;
+ var->_enum.boot_val = bootValue;
+ var->_enum.reset_val = bootValue;
+ var->_enum.options = options;
+ var->_enum.check_hook = check_hook;
+ var->_enum.assign_hook = assign_hook;
+ var->_enum.show_hook = show_hook;
+ define_custom_variable(var);
}
/*
/* Remove it from any lists it's in, too */
RemoveGUCFromLists(var);
/* And free it */
- free_placeholder((struct config_string *) var);
+ free_placeholder(var);
}
}
{
case PGC_BOOL:
{
- struct config_bool *lconf = (struct config_bool *) conf;
+ struct config_bool *lconf = &conf->_bool;
modified = (lconf->boot_val != *(lconf->variable));
}
case PGC_INT:
{
- struct config_int *lconf = (struct config_int *) conf;
+ struct config_int *lconf = &conf->_int;
modified = (lconf->boot_val != *(lconf->variable));
}
case PGC_REAL:
{
- struct config_real *lconf = (struct config_real *) conf;
+ struct config_real *lconf = &conf->_real;
modified = (lconf->boot_val != *(lconf->variable));
}
case PGC_STRING:
{
- struct config_string *lconf = (struct config_string *) conf;
+ struct config_string *lconf = &conf->_string;
if (lconf->boot_val == NULL &&
*lconf->variable == NULL)
case PGC_ENUM:
{
- struct config_enum *lconf = (struct config_enum *) conf;
+ struct config_enum *lconf = &conf->_enum;
modified = (lconf->boot_val != *(lconf->variable));
}
{
case PGC_BOOL:
{
- const struct config_bool *conf = (const struct config_bool *) record;
+ const struct config_bool *conf = &record->_bool;
if (conf->show_hook)
val = conf->show_hook();
case PGC_INT:
{
- const struct config_int *conf = (const struct config_int *) record;
+ const struct config_int *conf = &record->_int;
if (conf->show_hook)
val = conf->show_hook();
case PGC_REAL:
{
- const struct config_real *conf = (const struct config_real *) record;
+ const struct config_real *conf = &record->_real;
if (conf->show_hook)
val = conf->show_hook();
case PGC_STRING:
{
- const struct config_string *conf = (const struct config_string *) record;
+ const struct config_string *conf = &record->_string;
if (conf->show_hook)
val = conf->show_hook();
case PGC_ENUM:
{
- const struct config_enum *conf = (const struct config_enum *) record;
+ const struct config_enum *conf = &record->_enum;
if (conf->show_hook)
val = conf->show_hook();
else
- val = config_enum_lookup_by_value(conf, *conf->variable);
+ val = config_enum_lookup_by_value(record, *conf->variable);
}
break;
{
case PGC_BOOL:
{
- struct config_bool *conf = (struct config_bool *) gconf;
+ struct config_bool *conf = &gconf->_bool;
if (*conf->variable)
fprintf(fp, "true");
case PGC_INT:
{
- struct config_int *conf = (struct config_int *) gconf;
+ struct config_int *conf = &gconf->_int;
fprintf(fp, "%d", *conf->variable);
}
case PGC_REAL:
{
- struct config_real *conf = (struct config_real *) gconf;
+ struct config_real *conf = &gconf->_real;
fprintf(fp, "%.17g", *conf->variable);
}
case PGC_STRING:
{
- struct config_string *conf = (struct config_string *) gconf;
+ struct config_string *conf = &gconf->_string;
if (*conf->variable)
fprintf(fp, "%s", *conf->variable);
case PGC_ENUM:
{
- struct config_enum *conf = (struct config_enum *) gconf;
+ struct config_enum *conf = &gconf->_enum;
fprintf(fp, "%s",
- config_enum_lookup_by_value(conf, *conf->variable));
+ config_enum_lookup_by_value(gconf, *conf->variable));
}
break;
}
case PGC_INT:
{
- struct config_int *conf = (struct config_int *) gconf;
+ struct config_int *conf = &gconf->_int;
/*
* Instead of getting the exact display length, use max
case PGC_STRING:
{
- struct config_string *conf = (struct config_string *) gconf;
+ struct config_string *conf = &gconf->_string;
/*
* If the value is NULL, we transmit it as an empty string.
case PGC_ENUM:
{
- struct config_enum *conf = (struct config_enum *) gconf;
+ struct config_enum *conf = &gconf->_enum;
- valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
+ valsize = strlen(config_enum_lookup_by_value(gconf, *conf->variable));
}
break;
}
{
case PGC_BOOL:
{
- struct config_bool *conf = (struct config_bool *) gconf;
+ struct config_bool *conf = &gconf->_bool;
do_serialize(destptr, maxbytes,
(*conf->variable ? "true" : "false"));
case PGC_INT:
{
- struct config_int *conf = (struct config_int *) gconf;
+ struct config_int *conf = &gconf->_int;
do_serialize(destptr, maxbytes, "%d", *conf->variable);
}
case PGC_REAL:
{
- struct config_real *conf = (struct config_real *) gconf;
+ struct config_real *conf = &gconf->_real;
do_serialize(destptr, maxbytes, "%.*e",
REALTYPE_PRECISION, *conf->variable);
case PGC_STRING:
{
- struct config_string *conf = (struct config_string *) gconf;
+ struct config_string *conf = &gconf->_string;
/* NULL becomes empty string, see estimate_variable_size() */
do_serialize(destptr, maxbytes, "%s",
case PGC_ENUM:
{
- struct config_enum *conf = (struct config_enum *) gconf;
+ struct config_enum *conf = &gconf->_enum;
do_serialize(destptr, maxbytes, "%s",
- config_enum_lookup_by_value(conf, *conf->variable));
+ config_enum_lookup_by_value(gconf, *conf->variable));
}
break;
}
break;
case PGC_STRING:
{
- struct config_string *conf = (struct config_string *) gconf;
+ struct config_string *conf = &gconf->_string;
guc_free(*conf->variable);
if (conf->reset_val && conf->reset_val != *conf->variable)
*/
static bool
-call_bool_check_hook(const struct config_bool *conf, bool *newval, void **extra,
+call_bool_check_hook(const struct config_generic *conf, bool *newval, void **extra,
GucSource source, int elevel)
{
/* Quick success if no hook */
- if (!conf->check_hook)
+ if (!conf->_bool.check_hook)
return true;
/* Reset variables that might be set by hook */
GUC_check_errdetail_string = NULL;
GUC_check_errhint_string = NULL;
- if (!conf->check_hook(newval, extra, source))
+ if (!conf->_bool.check_hook(newval, extra, source))
{
ereport(elevel,
(errcode(GUC_check_errcode_value),
GUC_check_errmsg_string ?
errmsg_internal("%s", GUC_check_errmsg_string) :
errmsg("invalid value for parameter \"%s\": %d",
- conf->gen.name, (int) *newval),
+ conf->name, (int) *newval),
GUC_check_errdetail_string ?
errdetail_internal("%s", GUC_check_errdetail_string) : 0,
GUC_check_errhint_string ?
}
static bool
-call_int_check_hook(const struct config_int *conf, int *newval, void **extra,
+call_int_check_hook(const struct config_generic *conf, int *newval, void **extra,
GucSource source, int elevel)
{
/* Quick success if no hook */
- if (!conf->check_hook)
+ if (!conf->_int.check_hook)
return true;
/* Reset variables that might be set by hook */
GUC_check_errdetail_string = NULL;
GUC_check_errhint_string = NULL;
- if (!conf->check_hook(newval, extra, source))
+ if (!conf->_int.check_hook(newval, extra, source))
{
ereport(elevel,
(errcode(GUC_check_errcode_value),
GUC_check_errmsg_string ?
errmsg_internal("%s", GUC_check_errmsg_string) :
errmsg("invalid value for parameter \"%s\": %d",
- conf->gen.name, *newval),
+ conf->name, *newval),
GUC_check_errdetail_string ?
errdetail_internal("%s", GUC_check_errdetail_string) : 0,
GUC_check_errhint_string ?
}
static bool
-call_real_check_hook(const struct config_real *conf, double *newval, void **extra,
+call_real_check_hook(const struct config_generic *conf, double *newval, void **extra,
GucSource source, int elevel)
{
/* Quick success if no hook */
- if (!conf->check_hook)
+ if (!conf->_real.check_hook)
return true;
/* Reset variables that might be set by hook */
GUC_check_errdetail_string = NULL;
GUC_check_errhint_string = NULL;
- if (!conf->check_hook(newval, extra, source))
+ if (!conf->_real.check_hook(newval, extra, source))
{
ereport(elevel,
(errcode(GUC_check_errcode_value),
GUC_check_errmsg_string ?
errmsg_internal("%s", GUC_check_errmsg_string) :
errmsg("invalid value for parameter \"%s\": %g",
- conf->gen.name, *newval),
+ conf->name, *newval),
GUC_check_errdetail_string ?
errdetail_internal("%s", GUC_check_errdetail_string) : 0,
GUC_check_errhint_string ?
}
static bool
-call_string_check_hook(const struct config_string *conf, char **newval, void **extra,
+call_string_check_hook(const struct config_generic *conf, char **newval, void **extra,
GucSource source, int elevel)
{
volatile bool result = true;
/* Quick success if no hook */
- if (!conf->check_hook)
+ if (!conf->_string.check_hook)
return true;
/*
GUC_check_errdetail_string = NULL;
GUC_check_errhint_string = NULL;
- if (!conf->check_hook(newval, extra, source))
+ if (!conf->_string.check_hook(newval, extra, source))
{
ereport(elevel,
(errcode(GUC_check_errcode_value),
GUC_check_errmsg_string ?
errmsg_internal("%s", GUC_check_errmsg_string) :
errmsg("invalid value for parameter \"%s\": \"%s\"",
- conf->gen.name, *newval ? *newval : ""),
+ conf->name, *newval ? *newval : ""),
GUC_check_errdetail_string ?
errdetail_internal("%s", GUC_check_errdetail_string) : 0,
GUC_check_errhint_string ?
}
static bool
-call_enum_check_hook(const struct config_enum *conf, int *newval, void **extra,
+call_enum_check_hook(const struct config_generic *conf, int *newval, void **extra,
GucSource source, int elevel)
{
/* Quick success if no hook */
- if (!conf->check_hook)
+ if (!conf->_enum.check_hook)
return true;
/* Reset variables that might be set by hook */
GUC_check_errdetail_string = NULL;
GUC_check_errhint_string = NULL;
- if (!conf->check_hook(newval, extra, source))
+ if (!conf->_enum.check_hook(newval, extra, source))
{
ereport(elevel,
(errcode(GUC_check_errcode_value),
GUC_check_errmsg_string ?
errmsg_internal("%s", GUC_check_errmsg_string) :
errmsg("invalid value for parameter \"%s\": \"%s\"",
- conf->gen.name,
+ conf->name,
config_enum_lookup_by_value(conf, *newval)),
GUC_check_errdetail_string ?
errdetail_internal("%s", GUC_check_errdetail_string) : 0,