Skip to content

Commit 18f791a

Browse files
committed
Move genbki.pl's find_defined_symbol to Catalog.pm.
Will be used in Gen_fmgrtab.pl in a followup commit.
1 parent 4736d74 commit 18f791a

File tree

2 files changed

+38
-31
lines changed

2 files changed

+38
-31
lines changed

src/backend/catalog/Catalog.pm

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use warnings;
1919
require Exporter;
2020
our @ISA = qw(Exporter);
2121
our @EXPORT = ();
22-
our @EXPORT_OK = qw(Catalogs SplitDataLine RenameTempFile);
22+
our @EXPORT_OK = qw(Catalogs SplitDataLine RenameTempFile FindDefinedSymbol);
2323

2424
# Call this function with an array of names of header files to parse.
2525
# Returns a nested data structure describing the data in the headers.
@@ -252,6 +252,39 @@ sub RenameTempFile
252252
rename($temp_name, $final_name) || die "rename: $temp_name: $!";
253253
}
254254

255+
256+
# Find a symbol defined in a particular header file and extract the value.
257+
#
258+
# The include path has to be passed as a reference to an array.
259+
sub FindDefinedSymbol
260+
{
261+
my ($catalog_header, $include_path, $symbol) = @_;
262+
263+
for my $path (@$include_path)
264+
{
265+
266+
# Make sure include path ends in a slash.
267+
if (substr($path, -1) ne '/')
268+
{
269+
$path .= '/';
270+
}
271+
my $file = $path . $catalog_header;
272+
next if !-f $file;
273+
open(my $find_defined_symbol, '<', $file) || die "$file: $!";
274+
while (<$find_defined_symbol>)
275+
{
276+
if (/^#define\s+\Q$symbol\E\s+(\S+)/)
277+
{
278+
return $1;
279+
}
280+
}
281+
close $find_defined_symbol;
282+
die "$file: no definition found for $symbol\n";
283+
}
284+
die "$catalog_header: not found in any include directory\n";
285+
}
286+
287+
255288
# verify the number of fields in the passed-in DATA line
256289
sub check_natts
257290
{

src/backend/catalog/genbki.pl

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@
8787
# NB: make sure that the files used here are known to be part of the .bki
8888
# file's dependencies by src/backend/catalog/Makefile.
8989
my $BOOTSTRAP_SUPERUSERID =
90-
find_defined_symbol('pg_authid.h', 'BOOTSTRAP_SUPERUSERID');
90+
Catalog::FindDefinedSymbol('pg_authid.h', \@include_path,
91+
'BOOTSTRAP_SUPERUSERID');
9192
my $PG_CATALOG_NAMESPACE =
92-
find_defined_symbol('pg_namespace.h', 'PG_CATALOG_NAMESPACE');
93+
Catalog::FindDefinedSymbol('pg_namespace.h', \@include_path,
94+
'PG_CATALOG_NAMESPACE');
9395

9496
# Read all the input header files into internal data structures
9597
my $catalogs = Catalog::Catalogs(@input_files);
@@ -500,34 +502,6 @@ sub emit_schemapg_row
500502
return $row;
501503
}
502504

503-
# Find a symbol defined in a particular header file and extract the value.
504-
sub find_defined_symbol
505-
{
506-
my ($catalog_header, $symbol) = @_;
507-
for my $path (@include_path)
508-
{
509-
510-
# Make sure include path ends in a slash.
511-
if (substr($path, -1) ne '/')
512-
{
513-
$path .= '/';
514-
}
515-
my $file = $path . $catalog_header;
516-
next if !-f $file;
517-
open(my $find_defined_symbol, '<', $file) || die "$file: $!";
518-
while (<$find_defined_symbol>)
519-
{
520-
if (/^#define\s+\Q$symbol\E\s+(\S+)/)
521-
{
522-
return $1;
523-
}
524-
}
525-
close $find_defined_symbol;
526-
die "$file: no definition found for $symbol\n";
527-
}
528-
die "$catalog_header: not found in any include directory\n";
529-
}
530-
531505
sub usage
532506
{
533507
die <<EOM;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy