Skip to content

Move some BKI token replacement from initdb to compile time via genbk… #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/catalog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ generated-header-symlinks: $(top_builddir)/src/include/catalog/header-stamp
# instead is cheating a bit, but it will achieve the goal of updating the
# version number when it changes.
bki-stamp: genbki.pl Catalog.pm $(POSTGRES_BKI_SRCS) $(POSTGRES_BKI_DATA) $(top_srcdir)/configure.ac $(top_srcdir)/src/include/access/transam.h
$(PERL) $< --include-path=$(top_srcdir)/src/include/ \
$(PERL) $< --include-path=$(top_srcdir)/src/include/ --include-conf=$(top_builddir)/src/include/ \
--set-version=$(MAJORVERSION) $(POSTGRES_BKI_SRCS)
touch $@

Expand Down
34 changes: 33 additions & 1 deletion src/backend/catalog/genbki.pl
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,23 @@
my $output_path = '';
my $major_version;
my $include_path;
my $include_conf;

my $num_errors = 0;

GetOptions(
'output:s' => \$output_path,
'set-version:s' => \$major_version,
'include-path:s' => \$include_path) || usage();
'include-path:s' => \$include_path,
'include-conf:s' => \$include_conf) || usage();

# Sanity check arguments.
die "No input files.\n" unless @ARGV;
die "--set-version must be specified.\n" unless $major_version;
die "Invalid version string: $major_version\n"
unless $major_version =~ /^\d+$/;
die "--include-path must be specified.\n" unless $include_path;
die "--include-conf must be specified.\n" unless $include_conf;

# Make sure paths end with a slash.
if ($output_path ne '' && substr($output_path, -1) ne '/')
Expand Down Expand Up @@ -180,6 +183,12 @@
# Hash of next available OID, indexed by catalog name.
my %GenbkiNextOids;

my $NameDataLen=Catalog::FindDefinedSymbol('pg_config_manual.h', $include_path,
'NAMEDATALEN');
my $SizeOfPointer=Catalog::FindDefinedSymbol('pg_config.h', $include_conf,
'SIZEOF_VOID_P');
my $Float8PassByVal=$SizeOfPointer >= 8 ? "true": "false";
my $AlignOfPointer=$SizeOfPointer == 4 ? "i" : "d";

# Fetch some special data that we will substitute into the output file.
# CAUTION: be wary about what symbols you substitute into the .bki file here!
Expand Down Expand Up @@ -634,6 +643,23 @@
my $symbol = form_pg_type_symbol($bki_values{typname});
$bki_values{oid_symbol} = $symbol
if defined $symbol;

if ($bki_values{typlen} eq 'NAMEDATALEN')
{
$bki_values{typlen} = $NameDataLen;
}
if ($bki_values{typlen} eq 'SIZEOF_POINTER')
{
$bki_values{typlen} = $SizeOfPointer;
}
if ($bki_values{typalign} eq 'ALIGNOF_POINTER')
{
$bki_values{typalign} = $AlignOfPointer;
}
if ($bki_values{typbyval} eq 'FLOAT8PASSBYVAL')
{
$bki_values{typbyval} = $Float8PassByVal;
}
}

# Write to postgres.bki
Expand Down Expand Up @@ -812,6 +838,11 @@ sub gen_pg_attribute
($row{attnotnull} eq 't'
&& ($row{attlen} eq 'NAMEDATALEN' || $row{attlen} > 0));

if ($row{attnotnull} eq 't' && ($row{attlen} eq 'NAMEDATALEN'))
{
$row{attlen} = $NameDataLen;
}

# If it's bootstrapped, put an entry in postgres.bki.
print_bki_insert(\%row, $schema) if $table->{bootstrap};

Expand Down Expand Up @@ -1106,6 +1137,7 @@ sub usage
--output Output directory (default '.')
--set-version PostgreSQL version number for initdb cross-check
--include-path Include path in source tree
--include-conf Include file path generated after configuration

genbki.pl generates postgres.bki and symbol definition
headers from specially formatted header files and .dat
Expand Down
12 changes: 0 additions & 12 deletions src/bin/initdb/initdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1498,18 +1498,6 @@ bootstrap_template1(void)

/* Substitute for various symbols used in the BKI file */

sprintf(buf, "%d", NAMEDATALEN);
bki_lines = replace_token(bki_lines, "NAMEDATALEN", buf);

sprintf(buf, "%d", (int) sizeof(Pointer));
bki_lines = replace_token(bki_lines, "SIZEOF_POINTER", buf);

bki_lines = replace_token(bki_lines, "ALIGNOF_POINTER",
(sizeof(Pointer) == 4) ? "i" : "d");

bki_lines = replace_token(bki_lines, "FLOAT8PASSBYVAL",
FLOAT8PASSBYVAL ? "true" : "false");

bki_lines = replace_token(bki_lines, "POSTGRES",
escape_quotes_bki(username));

Expand Down
1 change: 1 addition & 0 deletions src/include/catalog/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ generated_catalog_headers = custom_target('generated_catalog_headers',
perl,
files('../../backend/catalog/genbki.pl'),
'--include-path=@SOURCE_ROOT@/src/include',
'--include-conf=@BUILD_ROOT@/src/include',
'--set-version=' + pg_version_major.to_string(),
'--output=@OUTDIR@', '@INPUT@'
],
Expand Down
2 changes: 1 addition & 1 deletion src/tools/msvc/Solution.pm
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ EOF
chdir('src/backend/catalog');
my $bki_srcs = join(' ../../../src/include/catalog/', @bki_srcs);
system(
"perl genbki.pl --include-path ../../../src/include/ --set-version=$majorver $bki_srcs"
"perl genbki.pl --include-path ../../../src/include/ --include-conf ../../../src/include/ --set-version=$majorver $bki_srcs"
);
open(my $f, '>', 'bki-stamp')
|| confess "Could not touch bki-stamp";
Expand Down
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