Skip to content

Commit 6359989

Browse files
committed
Generate GUC tables from .dat file
Store the information in guc_tables.c in a .dat file similar to the catalog data in src/include/catalog/, and generate a part of guc_tables.c from that. The goal is to make it easier to edit that information, and to be able to make changes to the downstream data structures more easily. (Essentially, those are the same reasons as for the original adoption of the .dat format.) Reviewed-by: John Naylor <johncnaylorls@gmail.com> Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: David E. Wheeler <david@justatheory.com> Discussion: https://www.postgresql.org/message-id/flat/dae6fe89-1e0c-4c3f-8d92-19d23374fb10%40eisentraut.org
1 parent aba8f61 commit 6359989

File tree

12 files changed

+3683
-4742
lines changed

12 files changed

+3683
-4742
lines changed

src/backend/utils/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
/fmgroids.h
33
/fmgrprotos.h
44
/fmgr-stamp
5+
/guc_tables.inc.c
56
/probes.h
67
/errcodes.h

src/backend/utils/Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ generated-header-symlinks: $(top_builddir)/src/include/utils/header-stamp submak
4343
submake-adt-headers:
4444
$(MAKE) -C adt jsonpath_gram.h
4545

46-
$(SUBDIRS:%=%-recursive): fmgr-stamp errcodes.h
46+
$(SUBDIRS:%=%-recursive): fmgr-stamp errcodes.h guc_tables.inc.c
4747

4848
# fmgr-stamp records the last time we ran Gen_fmgrtab.pl. We don't rely on
4949
# the timestamps of the individual output files, because the Perl script
@@ -55,6 +55,9 @@ fmgr-stamp: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(top_srcdir)/src/include/ca
5555
errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl
5656
$(PERL) $(srcdir)/generate-errcodes.pl --outfile $@ $<
5757

58+
guc_tables.inc.c: $(top_srcdir)/src/backend/utils/misc/guc_parameters.dat $(top_srcdir)/src/backend/utils/misc/gen_guc_tables.pl
59+
$(PERL) $(top_srcdir)/src/backend/utils/misc/gen_guc_tables.pl $< $@
60+
5861
ifeq ($(enable_dtrace), yes)
5962
probes.h: postprocess_dtrace.sed probes.h.tmp
6063
sed -f $^ >$@
@@ -70,8 +73,8 @@ endif
7073
# These generated headers must be symlinked into src/include/.
7174
# We use header-stamp to record that we've done this because the symlinks
7275
# themselves may appear older than fmgr-stamp.
73-
$(top_builddir)/src/include/utils/header-stamp: fmgr-stamp errcodes.h probes.h
74-
cd '$(dir $@)' && for file in fmgroids.h fmgrprotos.h errcodes.h probes.h; do \
76+
$(top_builddir)/src/include/utils/header-stamp: fmgr-stamp errcodes.h probes.h guc_tables.inc.c
77+
cd '$(dir $@)' && for file in fmgroids.h fmgrprotos.h errcodes.h probes.h guc_tables.inc.c; do \
7578
rm -f $$file && $(LN_S) "../../../$(subdir)/$$file" . ; \
7679
done
7780
touch $@
@@ -89,4 +92,4 @@ uninstall-data:
8992

9093
clean:
9194
rm -f probes.h probes.h.tmp
92-
rm -f fmgroids.h fmgrprotos.h fmgrtab.c fmgr-stamp errcodes.h
95+
rm -f fmgroids.h fmgrprotos.h fmgrtab.c fmgr-stamp errcodes.h guc_tables.inc.c
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/perl
2+
#----------------------------------------------------------------------
3+
#
4+
# Generate guc_tables.c from guc_parameters.dat.
5+
#
6+
# Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7+
# Portions Copyright (c) 1994, Regents of the University of California
8+
#
9+
# src/backend/utils/misc/gen_guc_tables.pl
10+
#
11+
#----------------------------------------------------------------------
12+
13+
use strict;
14+
use warnings FATAL => 'all';
15+
16+
use FindBin;
17+
use lib "$FindBin::RealBin/../../catalog";
18+
use Catalog;
19+
20+
die "Usage: $0 INPUT_FILE OUTPUT_FILE\n" unless @ARGV == 2;
21+
my ($input_fname, $output_fname) = @ARGV;
22+
23+
my $parse = Catalog::ParseData($input_fname);
24+
25+
open my $ofh, '>', $output_fname or die;
26+
27+
print_boilerplate($ofh, $output_fname, 'GUC tables');
28+
foreach my $type (qw(bool int real string enum))
29+
{
30+
print_one_table($ofh, $type);
31+
}
32+
33+
close $ofh;
34+
35+
36+
# Adds double quotes and escapes as necessary for C strings.
37+
sub dquote
38+
{
39+
my ($s) = @_;
40+
41+
return q{"} . $s =~ s/"/\\"/gr . q{"};
42+
}
43+
44+
# Print GUC table for one type.
45+
sub print_one_table
46+
{
47+
my ($ofh, $type) = @_;
48+
my $Type = ucfirst $type;
49+
50+
print $ofh "\n\n";
51+
print $ofh "struct config_${type} ConfigureNames${Type}[] =\n";
52+
print $ofh "{\n";
53+
54+
foreach my $entry (@{$parse})
55+
{
56+
next if $entry->{type} ne $type;
57+
58+
print $ofh "#ifdef $entry->{ifdef}\n" if $entry->{ifdef};
59+
print $ofh "\t{\n";
60+
printf $ofh "\t\t{%s, %s, %s,\n",
61+
dquote($entry->{name}),
62+
$entry->{context},
63+
$entry->{group};
64+
printf $ofh "\t\t\tgettext_noop(%s),\n", dquote($entry->{short_desc});
65+
if ($entry->{long_desc})
66+
{
67+
printf $ofh "\t\t\tgettext_noop(%s)", dquote($entry->{long_desc});
68+
}
69+
else
70+
{
71+
print $ofh "\t\t\tNULL";
72+
}
73+
if ($entry->{flags})
74+
{
75+
print $ofh ",\n\t\t\t$entry->{flags}\n";
76+
}
77+
else
78+
{
79+
print $ofh "\n";
80+
}
81+
print $ofh "\t\t},\n";
82+
print $ofh "\t\t&$entry->{variable},\n";
83+
print $ofh "\t\t$entry->{boot_val},";
84+
print $ofh " $entry->{min},"
85+
if $entry->{type} eq 'int' || $entry->{type} eq 'real';
86+
print $ofh " $entry->{max},"
87+
if $entry->{type} eq 'int' || $entry->{type} eq 'real';
88+
print $ofh " $entry->{options},"
89+
if $entry->{type} eq 'enum';
90+
print $ofh "\n";
91+
printf $ofh "\t\t%s, %s, %s\n",
92+
($entry->{check_hook} || 'NULL'),
93+
($entry->{assign_hook} || 'NULL'),
94+
($entry->{show_hook} || 'NULL');
95+
print $ofh "\t},\n";
96+
print $ofh "#endif\n" if $entry->{ifdef};
97+
print $ofh "\n";
98+
}
99+
100+
print $ofh "\t/* End-of-list marker */\n";
101+
print $ofh "\t{{0}}\n";
102+
print $ofh "};\n";
103+
104+
return;
105+
}
106+
107+
sub print_boilerplate
108+
{
109+
my ($fh, $fname, $descr) = @_;
110+
printf $fh <<EOM, $fname, $descr;
111+
/*-------------------------------------------------------------------------
112+
*
113+
* %s
114+
* %s
115+
*
116+
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
117+
* Portions Copyright (c) 1994, Regents of the University of California
118+
*
119+
* NOTES
120+
* ******************************
121+
* *** DO NOT EDIT THIS FILE! ***
122+
* ******************************
123+
*
124+
* It has been GENERATED by src/backend/utils/misc/gen_guc_tables.pl
125+
*
126+
*-------------------------------------------------------------------------
127+
*/
128+
EOM
129+
130+
return;
131+
}

0 commit comments

Comments
 (0)