Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e7a808f

Browse files
committed
Assorted minor cleanups for bootstrap-data Perl scripts.
FindDefinedSymbol was intended to take an array of possible include paths, but it never actually worked correctly for any but the first array element. Since there's no use-case for more than one path anyway, let's just simplify this code and its callers by redefining it as taking only one include path. Minor other code-beautification without functional effects, except that in one place we format the output as pgindent would do. John Naylor Discussion: https://postgr.es/m/CAJVSVGXM_n32hTTkircW4_K1LQFsJNb6xjs0pAP4QC0ZpyJfPQ@mail.gmail.com
1 parent 06f66cf commit e7a808f

File tree

5 files changed

+36
-42
lines changed

5 files changed

+36
-42
lines changed

src/backend/catalog/Catalog.pm

+17-21
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ sub ParseHeader
198198
else
199199
{
200200
die
201-
"unknown column option $attopt on column $attname";
201+
"unknown or misformatted column option $attopt on column $attname";
202202
}
203203

204204
if ($column{forcenull} and $column{forcenotnull})
@@ -370,34 +370,30 @@ sub RenameTempFile
370370
}
371371

372372
# Find a symbol defined in a particular header file and extract the value.
373-
#
374-
# The include path has to be passed as a reference to an array.
373+
# include_path should be the path to src/include/.
375374
sub FindDefinedSymbol
376375
{
377376
my ($catalog_header, $include_path, $symbol) = @_;
377+
my $value;
378378

379-
for my $path (@$include_path)
379+
# Make sure include path ends in a slash.
380+
if (substr($include_path, -1) ne '/')
380381
{
381-
382-
# Make sure include path ends in a slash.
383-
if (substr($path, -1) ne '/')
384-
{
385-
$path .= '/';
386-
}
387-
my $file = $path . $catalog_header;
388-
next if !-f $file;
389-
open(my $find_defined_symbol, '<', $file) || die "$file: $!";
390-
while (<$find_defined_symbol>)
382+
$include_path .= '/';
383+
}
384+
my $file = $include_path . $catalog_header;
385+
open(my $find_defined_symbol, '<', $file) || die "$file: $!";
386+
while (<$find_defined_symbol>)
387+
{
388+
if (/^#define\s+\Q$symbol\E\s+(\S+)/)
391389
{
392-
if (/^#define\s+\Q$symbol\E\s+(\S+)/)
393-
{
394-
return $1;
395-
}
390+
$value = $1;
391+
last;
396392
}
397-
close $find_defined_symbol;
398-
die "$file: no definition found for $symbol\n";
399393
}
400-
die "$catalog_header: not found in any include directory\n";
394+
close $find_defined_symbol;
395+
return $value if defined $value;
396+
die "$file: no definition found for $symbol\n";
401397
}
402398

403399
# Similar to FindDefinedSymbol, but looks in the bootstrap metadata.

src/backend/catalog/genbki.pl

+2-3
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,7 @@
357357
}
358358

359359
# Emit Anum_* constants
360-
print $def
361-
sprintf("#define Anum_%s_%s %s\n", $catname, $attname, $attnum);
360+
printf $def "#define Anum_%s_%s %s\n", $catname, $attname, $attnum;
362361
}
363362
print $bki "\n )\n";
364363

@@ -493,7 +492,7 @@
493492
}
494493

495494
print $bki "close $catname\n";
496-
print $def sprintf("\n#endif\t\t\t\t\t\t\t/* %s_D_H */\n", uc $catname);
495+
printf $def "\n#endif\t\t\t\t\t\t\t/* %s_D_H */\n", uc $catname;
497496

498497
# Close and rename definition header
499498
close $def;

src/backend/utils/Gen_fmgrtab.pl

+16-16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# Collect arguments
2323
my @input_files;
2424
my $output_path = '';
25-
my @include_path;
25+
my $include_path;
2626

2727
while (@ARGV)
2828
{
@@ -37,7 +37,7 @@
3737
}
3838
elsif ($arg =~ /^-I/)
3939
{
40-
push @include_path, length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
40+
$include_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
4141
}
4242
else
4343
{
@@ -52,8 +52,8 @@
5252
}
5353

5454
# Sanity check arguments.
55-
die "No input files.\n" if !@input_files;
56-
die "No include path; you must specify -I at least once.\n" if !@include_path;
55+
die "No input files.\n" if !@input_files;
56+
die "No include path; you must specify -I.\n" if !$include_path;
5757

5858
# Read all the input files into internal data structures.
5959
# Note: We pass data file names as arguments and then look for matching
@@ -80,7 +80,7 @@
8080

8181
# Fetch some values for later.
8282
my $FirstBootstrapObjectId =
83-
Catalog::FindDefinedSymbol('access/transam.h', \@include_path,
83+
Catalog::FindDefinedSymbol('access/transam.h', $include_path,
8484
'FirstBootstrapObjectId');
8585
my $INTERNALlanguageId =
8686
Catalog::FindDefinedSymbolFromData($catalog_data{pg_language},
@@ -119,8 +119,8 @@
119119
open my $tfh, '>', $tabfile . $tmpext
120120
or die "Could not open $tabfile$tmpext: $!";
121121

122-
print $ofh
123-
qq|/*-------------------------------------------------------------------------
122+
print $ofh <<OFH;
123+
/*-------------------------------------------------------------------------
124124
*
125125
* fmgroids.h
126126
* Macros that define the OIDs of built-in functions.
@@ -154,10 +154,10 @@
154154
* its equivalent macro will be defined with the lowest OID among those
155155
* entries.
156156
*/
157-
|;
157+
OFH
158158

159-
print $pfh
160-
qq|/*-------------------------------------------------------------------------
159+
print $pfh <<PFH;
160+
/*-------------------------------------------------------------------------
161161
*
162162
* fmgrprotos.h
163163
* Prototypes for built-in functions.
@@ -180,10 +180,10 @@
180180
181181
#include "fmgr.h"
182182
183-
|;
183+
PFH
184184

185-
print $tfh
186-
qq|/*-------------------------------------------------------------------------
185+
print $tfh <<TFH;
186+
/*-------------------------------------------------------------------------
187187
*
188188
* fmgrtab.c
189189
* The function manager's table of internal functions.
@@ -208,7 +208,7 @@
208208
#include "utils/fmgrtab.h"
209209
#include "utils/fmgrprotos.h"
210210
211-
|;
211+
TFH
212212

213213
# Emit #define's and extern's -- only one per prosrc value
214214
my %seenit;
@@ -282,8 +282,8 @@
282282

283283

284284
# And add the file footers.
285-
print $ofh "\n#endif /* FMGROIDS_H */\n";
286-
print $pfh "\n#endif /* FMGRPROTOS_H */\n";
285+
print $ofh "\n#endif\t\t\t\t\t\t\t/* FMGROIDS_H */\n";
286+
print $pfh "\n#endif\t\t\t\t\t\t\t/* FMGRPROTOS_H */\n";
287287

288288
close($ofh);
289289
close($pfh);

src/include/catalog/reformat_dat_file.pl

-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
open my $dat, '>', $datfile
126126
or die "can't open $datfile: $!";
127127

128-
# Write the data.
129128
foreach my $data (@{ $catalog_data{$catname} })
130129
{
131130

src/include/catalog/unused_oids

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ my $oids = Catalog::FindAllOidsFromHeaders(@input_files);
3434

3535
# Also push FirstBootstrapObjectId to serve as a terminator for the last gap.
3636
my $FirstBootstrapObjectId =
37-
Catalog::FindDefinedSymbol('access/transam.h', [".."],
37+
Catalog::FindDefinedSymbol('access/transam.h', '..',
3838
'FirstBootstrapObjectId');
3939
push @{$oids}, $FirstBootstrapObjectId;
4040

0 commit comments

Comments
 (0)