summaryrefslogtreecommitdiff
path: root/src/backend/utils/misc/help_config.c
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/backend/utils/misc/help_config.c
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/backend/utils/misc/help_config.c')
-rw-r--r--src/backend/utils/misc/help_config.c59
1 files changed, 22 insertions, 37 deletions
diff --git a/src/backend/utils/misc/help_config.c b/src/backend/utils/misc/help_config.c
index 86812ac881f..2810715693c 100644
--- a/src/backend/utils/misc/help_config.c
+++ b/src/backend/utils/misc/help_config.c
@@ -23,23 +23,8 @@
#include "utils/help_config.h"
-/*
- * This union allows us to mix the numerous different types of structs
- * that we are organizing.
- */
-typedef union
-{
- struct config_generic generic;
- struct config_bool _bool;
- struct config_real real;
- struct config_int integer;
- struct config_string string;
- struct config_enum _enum;
-} mixedStruct;
-
-
-static void printMixedStruct(mixedStruct *structToPrint);
-static bool displayStruct(mixedStruct *structToDisplay);
+static void printMixedStruct(const struct config_generic *structToPrint);
+static bool displayStruct(const struct config_generic *structToDisplay);
void
@@ -55,7 +40,7 @@ GucInfoMain(void)
for (int i = 0; i < numOpts; i++)
{
- mixedStruct *var = (mixedStruct *) guc_vars[i];
+ const struct config_generic *var = guc_vars[i];
if (displayStruct(var))
printMixedStruct(var);
@@ -70,11 +55,11 @@ GucInfoMain(void)
* should be displayed to the user.
*/
static bool
-displayStruct(mixedStruct *structToDisplay)
+displayStruct(const struct config_generic *structToDisplay)
{
- return !(structToDisplay->generic.flags & (GUC_NO_SHOW_ALL |
- GUC_NOT_IN_SAMPLE |
- GUC_DISALLOW_IN_FILE));
+ return !(structToDisplay->flags & (GUC_NO_SHOW_ALL |
+ GUC_NOT_IN_SAMPLE |
+ GUC_DISALLOW_IN_FILE));
}
@@ -83,14 +68,14 @@ displayStruct(mixedStruct *structToDisplay)
* a different format, depending on what the user wants to see.
*/
static void
-printMixedStruct(mixedStruct *structToPrint)
+printMixedStruct(const struct config_generic *structToPrint)
{
printf("%s\t%s\t%s\t",
- structToPrint->generic.name,
- GucContext_Names[structToPrint->generic.context],
- _(config_group_names[structToPrint->generic.group]));
+ structToPrint->name,
+ GucContext_Names[structToPrint->context],
+ _(config_group_names[structToPrint->group]));
- switch (structToPrint->generic.vartype)
+ switch (structToPrint->vartype)
{
case PGC_BOOL:
@@ -101,26 +86,26 @@ printMixedStruct(mixedStruct *structToPrint)
case PGC_INT:
printf("INTEGER\t%d\t%d\t%d\t",
- structToPrint->integer.reset_val,
- structToPrint->integer.min,
- structToPrint->integer.max);
+ structToPrint->_int.reset_val,
+ structToPrint->_int.min,
+ structToPrint->_int.max);
break;
case PGC_REAL:
printf("REAL\t%g\t%g\t%g\t",
- structToPrint->real.reset_val,
- structToPrint->real.min,
- structToPrint->real.max);
+ structToPrint->_real.reset_val,
+ structToPrint->_real.min,
+ structToPrint->_real.max);
break;
case PGC_STRING:
printf("STRING\t%s\t\t\t",
- structToPrint->string.boot_val ? structToPrint->string.boot_val : "");
+ structToPrint->_string.boot_val ? structToPrint->_string.boot_val : "");
break;
case PGC_ENUM:
printf("ENUM\t%s\t\t\t",
- config_enum_lookup_by_value(&structToPrint->_enum,
+ config_enum_lookup_by_value(structToPrint,
structToPrint->_enum.boot_val));
break;
@@ -130,6 +115,6 @@ printMixedStruct(mixedStruct *structToPrint)
}
printf("%s\t%s\n",
- (structToPrint->generic.short_desc == NULL) ? "" : _(structToPrint->generic.short_desc),
- (structToPrint->generic.long_desc == NULL) ? "" : _(structToPrint->generic.long_desc));
+ (structToPrint->short_desc == NULL) ? "" : _(structToPrint->short_desc),
+ (structToPrint->long_desc == NULL) ? "" : _(structToPrint->long_desc));
}