From a13833c35f9e07fe978bf6fad984d6f5f25f59cd Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 3 Oct 2025 08:27:18 +0200 Subject: 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 Reviewed-by: Heikki Linnakangas Discussion: https://www.postgresql.org/message-id/flat/8fdfb91e-60fb-44fa-8df6-f5dea47353c9@eisentraut.org --- src/backend/utils/misc/gen_guc_tables.pl | 53 ++++++++++++++------------------ 1 file changed, 23 insertions(+), 30 deletions(-) (limited to 'src/backend/utils/misc/gen_guc_tables.pl') diff --git a/src/backend/utils/misc/gen_guc_tables.pl b/src/backend/utils/misc/gen_guc_tables.pl index b187259bf1e..3efde02bab8 100644 --- a/src/backend/utils/misc/gen_guc_tables.pl +++ b/src/backend/utils/misc/gen_guc_tables.pl @@ -25,10 +25,7 @@ my $parse = Catalog::ParseData($input_fname); open my $ofh, '>', $output_fname or die; print_boilerplate($ofh, $output_fname, 'GUC tables'); -foreach my $type (qw(bool int real string enum)) -{ - print_one_table($ofh, $type); -} +print_table($ofh); close $ofh; @@ -41,56 +38,52 @@ sub dquote return q{"} . $s =~ s/"/\\"/gr . q{"}; } -# Print GUC table for one type. -sub print_one_table +# Print GUC table. +sub print_table { - my ($ofh, $type) = @_; - my $Type = ucfirst $type; + my ($ofh) = @_; print $ofh "\n\n"; - print $ofh "struct config_${type} ConfigureNames${Type}[] =\n"; + print $ofh "struct config_generic ConfigureNames[] =\n"; print $ofh "{\n"; foreach my $entry (@{$parse}) { - next if $entry->{type} ne $type; - print $ofh "#ifdef $entry->{ifdef}\n" if $entry->{ifdef}; print $ofh "\t{\n"; - print $ofh "\t\t{\n"; - printf $ofh "\t\t\t.name = %s,\n", dquote($entry->{name}); - printf $ofh "\t\t\t.context = %s,\n", $entry->{context}; - printf $ofh "\t\t\t.group = %s,\n", $entry->{group}; - printf $ofh "\t\t\t.short_desc = gettext_noop(%s),\n", + printf $ofh "\t\t.name = %s,\n", dquote($entry->{name}); + printf $ofh "\t\t.context = %s,\n", $entry->{context}; + printf $ofh "\t\t.group = %s,\n", $entry->{group}; + printf $ofh "\t\t.short_desc = gettext_noop(%s),\n", dquote($entry->{short_desc}); - printf $ofh "\t\t\t.long_desc = gettext_noop(%s),\n", + printf $ofh "\t\t.long_desc = gettext_noop(%s),\n", dquote($entry->{long_desc}) if $entry->{long_desc}; - printf $ofh "\t\t\t.flags = %s,\n", $entry->{flags} - if $entry->{flags}; - printf $ofh "\t\t\t.vartype = %s,\n", ('PGC_' . uc($type)); - print $ofh "\t\t},\n"; - printf $ofh "\t\t.variable = &%s,\n", $entry->{variable}; - printf $ofh "\t\t.boot_val = %s,\n", $entry->{boot_val}; - printf $ofh "\t\t.min = %s,\n", $entry->{min} + printf $ofh "\t\t.flags = %s,\n", $entry->{flags} if $entry->{flags}; + printf $ofh "\t\t.vartype = %s,\n", ('PGC_' . uc($entry->{type})); + printf $ofh "\t\t._%s = {\n", $entry->{type}; + printf $ofh "\t\t\t.variable = &%s,\n", $entry->{variable}; + printf $ofh "\t\t\t.boot_val = %s,\n", $entry->{boot_val}; + printf $ofh "\t\t\t.min = %s,\n", $entry->{min} if $entry->{type} eq 'int' || $entry->{type} eq 'real'; - printf $ofh "\t\t.max = %s,\n", $entry->{max} + printf $ofh "\t\t\t.max = %s,\n", $entry->{max} if $entry->{type} eq 'int' || $entry->{type} eq 'real'; - printf $ofh "\t\t.options = %s,\n", $entry->{options} + printf $ofh "\t\t\t.options = %s,\n", $entry->{options} if $entry->{type} eq 'enum'; - printf $ofh "\t\t.check_hook = %s,\n", $entry->{check_hook} + printf $ofh "\t\t\t.check_hook = %s,\n", $entry->{check_hook} if $entry->{check_hook}; - printf $ofh "\t\t.assign_hook = %s,\n", $entry->{assign_hook} + printf $ofh "\t\t\t.assign_hook = %s,\n", $entry->{assign_hook} if $entry->{assign_hook}; - printf $ofh "\t\t.show_hook = %s,\n", $entry->{show_hook} + printf $ofh "\t\t\t.show_hook = %s,\n", $entry->{show_hook} if $entry->{show_hook}; + print $ofh "\t\t},\n"; print $ofh "\t},\n"; print $ofh "#endif\n" if $entry->{ifdef}; print $ofh "\n"; } print $ofh "\t/* End-of-list marker */\n"; - print $ofh "\t{{0}}\n"; + print $ofh "\t{0}\n"; print $ofh "};\n"; return; -- cgit v1.2.3