summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2025-10-03 08:27:18 +0200
committerPeter Eisentraut <peter@eisentraut.org>2025-10-29 09:52:29 +0100
commita13833c35f9e07fe978bf6fad984d6f5f25f59cd (patch)
tree4d6dfd2addd1952b374715e39079c8c8d9550189 /src/include
parent2724830929ba29a5cf95fba6134ca4dcbfdb4109 (diff)
Reorganize GUC structs
Instead of having five separate GUC structs, one for each type, with the generic part contained in each of them, flip it around and have one common struct, with the type-specific part has a subfield. The very original GUC design had type-specific structs and type-specific lists, and the membership in one of the lists defined the type. But now the structs themselves know the type (from the .vartype field), and they are all loaded into a common hash table at run time, and so this original separation no longer makes sense. It creates a bunch of inconsistencies in the code about whether the type-specific or the generic struct is the primary struct, and a lot of casting in between, which makes certain assumptions about the struct layouts. After the change, all these casts are gone and all the data is accessed via normal field references. Also, various code is simplified because only one kind of struct needs to be processed. Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Discussion: https://www.postgresql.org/message-id/flat/8fdfb91e-60fb-44fa-8df6-f5dea47353c9@eisentraut.org
Diffstat (limited to 'src/include')
-rw-r--r--src/include/utils/guc_tables.h180
1 files changed, 91 insertions, 89 deletions
diff --git a/src/include/utils/guc_tables.h b/src/include/utils/guc_tables.h
index 3de3d809545..bbfcc633014 100644
--- a/src/include/utils/guc_tables.h
+++ b/src/include/utils/guc_tables.h
@@ -132,6 +132,84 @@ typedef struct guc_stack
config_var_value masked; /* SET value in a GUC_SET_LOCAL entry */
} GucStack;
+
+/* GUC records for specific variable types */
+
+struct config_bool
+{
+ /* constant fields, must be set correctly in initial value: */
+ bool *variable;
+ bool boot_val;
+ GucBoolCheckHook check_hook;
+ GucBoolAssignHook assign_hook;
+ GucShowHook show_hook;
+ /* variable fields, initialized at runtime: */
+ bool reset_val;
+};
+
+struct config_int
+{
+ /* constant fields, must be set correctly in initial value: */
+ int *variable;
+ int boot_val;
+ int min;
+ int max;
+ GucIntCheckHook check_hook;
+ GucIntAssignHook assign_hook;
+ GucShowHook show_hook;
+ /* variable fields, initialized at runtime: */
+ int reset_val;
+};
+
+struct config_real
+{
+ /* constant fields, must be set correctly in initial value: */
+ double *variable;
+ double boot_val;
+ double min;
+ double max;
+ GucRealCheckHook check_hook;
+ GucRealAssignHook assign_hook;
+ GucShowHook show_hook;
+ /* variable fields, initialized at runtime: */
+ double reset_val;
+};
+
+/*
+ * A note about string GUCs: the boot_val is allowed to be NULL, which leads
+ * to the reset_val and the actual variable value (*variable) also being NULL.
+ * However, there is no way to set a NULL value subsequently using
+ * set_config_option or any other GUC API. Also, GUC APIs such as SHOW will
+ * display a NULL value as an empty string. Callers that choose to use a NULL
+ * boot_val should overwrite the setting later in startup, or else be careful
+ * that NULL doesn't have semantics that are visibly different from an empty
+ * string.
+ */
+struct config_string
+{
+ /* constant fields, must be set correctly in initial value: */
+ char **variable;
+ const char *boot_val;
+ GucStringCheckHook check_hook;
+ GucStringAssignHook assign_hook;
+ GucShowHook show_hook;
+ /* variable fields, initialized at runtime: */
+ char *reset_val;
+};
+
+struct config_enum
+{
+ /* constant fields, must be set correctly in initial value: */
+ int *variable;
+ int boot_val;
+ const struct config_enum_entry *options;
+ GucEnumCheckHook check_hook;
+ GucEnumAssignHook assign_hook;
+ GucShowHook show_hook;
+ /* variable fields, initialized at runtime: */
+ int reset_val;
+};
+
/*
* Generic fields applicable to all types of variables
*
@@ -200,6 +278,16 @@ struct config_generic
char *sourcefile; /* file current setting is from (NULL if not
* set in config file) */
int sourceline; /* line in source file */
+
+ /* fields for specific variable types */
+ union
+ {
+ struct config_bool _bool;
+ struct config_int _int;
+ struct config_real _real;
+ struct config_string _string;
+ struct config_enum _enum;
+ };
};
/* bit values in status field */
@@ -212,100 +300,14 @@ struct config_generic
#define GUC_NEEDS_REPORT 0x0004 /* new value must be reported to client */
-/* GUC records for specific variable types */
-
-struct config_bool
-{
- struct config_generic gen;
- /* constant fields, must be set correctly in initial value: */
- bool *variable;
- bool boot_val;
- GucBoolCheckHook check_hook;
- GucBoolAssignHook assign_hook;
- GucShowHook show_hook;
- /* variable fields, initialized at runtime: */
- bool reset_val;
-};
-
-struct config_int
-{
- struct config_generic gen;
- /* constant fields, must be set correctly in initial value: */
- int *variable;
- int boot_val;
- int min;
- int max;
- GucIntCheckHook check_hook;
- GucIntAssignHook assign_hook;
- GucShowHook show_hook;
- /* variable fields, initialized at runtime: */
- int reset_val;
-};
-
-struct config_real
-{
- struct config_generic gen;
- /* constant fields, must be set correctly in initial value: */
- double *variable;
- double boot_val;
- double min;
- double max;
- GucRealCheckHook check_hook;
- GucRealAssignHook assign_hook;
- GucShowHook show_hook;
- /* variable fields, initialized at runtime: */
- double reset_val;
-};
-
-/*
- * A note about string GUCs: the boot_val is allowed to be NULL, which leads
- * to the reset_val and the actual variable value (*variable) also being NULL.
- * However, there is no way to set a NULL value subsequently using
- * set_config_option or any other GUC API. Also, GUC APIs such as SHOW will
- * display a NULL value as an empty string. Callers that choose to use a NULL
- * boot_val should overwrite the setting later in startup, or else be careful
- * that NULL doesn't have semantics that are visibly different from an empty
- * string.
- */
-struct config_string
-{
- struct config_generic gen;
- /* constant fields, must be set correctly in initial value: */
- char **variable;
- const char *boot_val;
- GucStringCheckHook check_hook;
- GucStringAssignHook assign_hook;
- GucShowHook show_hook;
- /* variable fields, initialized at runtime: */
- char *reset_val;
-};
-
-struct config_enum
-{
- struct config_generic gen;
- /* constant fields, must be set correctly in initial value: */
- int *variable;
- int boot_val;
- const struct config_enum_entry *options;
- GucEnumCheckHook check_hook;
- GucEnumAssignHook assign_hook;
- GucShowHook show_hook;
- /* variable fields, initialized at runtime: */
- int reset_val;
-};
-
/* constant tables corresponding to enums above and in guc.h */
extern PGDLLIMPORT const char *const config_group_names[];
extern PGDLLIMPORT const char *const config_type_names[];
extern PGDLLIMPORT const char *const GucContext_Names[];
extern PGDLLIMPORT const char *const GucSource_Names[];
-/* data arrays defining all the built-in GUC variables */
-extern PGDLLIMPORT struct config_bool ConfigureNamesBool[];
-extern PGDLLIMPORT struct config_int ConfigureNamesInt[];
-extern PGDLLIMPORT struct config_real ConfigureNamesReal[];
-extern PGDLLIMPORT struct config_string ConfigureNamesString[];
-extern PGDLLIMPORT struct config_enum ConfigureNamesEnum[];
+/* data array defining all the built-in GUC variables */
+extern PGDLLIMPORT struct config_generic ConfigureNames[];
/* lookup GUC variables, returning config_generic pointers */
extern struct config_generic *find_option(const char *name,
@@ -326,7 +328,7 @@ extern struct config_generic **get_guc_variables(int *num_vars);
extern void build_guc_variables(void);
/* search in enum options */
-extern const char *config_enum_lookup_by_value(const struct config_enum *record, int val);
+extern const char *config_enum_lookup_by_value(const struct config_generic *record, int val);
extern bool config_enum_lookup_by_name(const struct config_enum *record,
const char *value, int *retval);
extern char *config_enum_get_options(const struct config_enum *record,