Skip to content

Commit 7169c0b

Browse files
committed
gen_guc_tables.pl: Validate required GUC fields before code generation
Previously, gen_guc_tables.pl would emit "Use of uninitialized value" warnings if required fields were missing in guc_parameters.dat (for example, when an integer or real GUC omitted the 'max' value). The resulting error messages were unclear and did not identify which GUC entry was problematic. Add explicit validation of required fields depending on the parameter type, and fail with a clear and specific message such as: guc_parameters.dat:1909: error: entry "max_index_keys" of type "int" is missing required field "max" No changes to generated guc_tables.c. Author: Chao Li <lic@highgo.com> Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://www.postgresql.org/message-id/flat/CAEoWx2%3DoP4LgHi771_OKhPPUS7B-CTqCs%3D%3DuQcNXWrwBoAm5Vg%40mail.gmail.com
1 parent 2256af4 commit 7169c0b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/backend/utils/misc/gen_guc_tables.pl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,52 @@ sub dquote
3838
return q{"} . $s =~ s/"/\\"/gr . q{"};
3939
}
4040

41+
sub validate_guc_entry
42+
{
43+
my ($entry) = @_;
44+
45+
my @required_common =
46+
qw(name type context group short_desc variable boot_val);
47+
48+
my %required_by_type = (
49+
int => [qw(min max)],
50+
real => [qw(min max)],
51+
enum => [qw(options)],
52+
bool => [], # no extra required fields
53+
string => [], # no extra required fields
54+
);
55+
56+
for my $f (@required_common)
57+
{
58+
unless (defined $entry->{$f})
59+
{
60+
die sprintf(
61+
qq{%s:%d: error: entry "%s" is missing required field "%s"\n},
62+
$input_fname, $entry->{line_number},
63+
$entry->{name} // '<unknown>', $f);
64+
}
65+
}
66+
67+
unless (exists $required_by_type{ $entry->{type} })
68+
{
69+
die sprintf(
70+
qq{%s:%d: error: entry "%s" has unrecognized GUC type "%s"\n},
71+
$input_fname, $entry->{line_number},
72+
$entry->{name}, $entry->{type} // '<unknown>');
73+
}
74+
75+
for my $f (@{ $required_by_type{ $entry->{type} } })
76+
{
77+
unless (defined $entry->{$f})
78+
{
79+
die sprintf(
80+
qq{%s:%d: error: entry "%s" of type "%s" is missing required field "%s"\n},
81+
$input_fname, $entry->{line_number}, $entry->{name},
82+
$entry->{type}, $f);
83+
}
84+
}
85+
}
86+
4187
# Print GUC table.
4288
sub print_table
4389
{
@@ -50,6 +96,8 @@ sub print_table
5096

5197
foreach my $entry (@{$parse})
5298
{
99+
validate_guc_entry($entry);
100+
53101
if (defined($prev_name) && lc($prev_name) ge lc($entry->{name}))
54102
{
55103
die sprintf(

0 commit comments

Comments
 (0)