Hi, As per discussion in [1] splitting the patch. Part1 moves replacement logic in initdb of NAMEDATALEN, FLOAT8PASSBYVAL, SIZEOF_VOID_P, ALIGNOF_POINTER to compile time via genbki.pl.
-- Thanks and regards, Krishnakumar (KK). [Microsoft] [1] https://www.postgresql.org/message-id/flat/CAPMWgZ9TCByVjpfdsgyte4rx%3DYsrAttYay2xDK4UN4Lm%3D-wJMQ%40mail.gmail.com
From 2b968de3dd559aa31095214f96773569ebec8b21 Mon Sep 17 00:00:00 2001 From: "Krishnakumar R (KK)" <kksrcv...@gmail.com> Date: Mon, 4 Dec 2023 01:25:20 -0800 Subject: [PATCH v4] Move some BKI token replacement from initdb to compile time via genbki.pl. Here are some details: - NAMEDATALEN, FLOAT8PASSBYVAL, SIZEOF_VOID_P, ALIGNOF_POINTER are replaced during compilation from genbki.pl by reading header files. - SIZEOF_VOID_P is available only after configuration (in pg_config.h). A new parameter include-conf had to be added to genbki to point to header files generated after configuration. --- src/backend/catalog/Makefile | 2 +- src/backend/catalog/genbki.pl | 34 ++++++++++++++++++++++++++++++++- src/bin/initdb/initdb.c | 12 ------------ src/include/catalog/meson.build | 1 + src/tools/msvc/Solution.pm | 2 +- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/backend/catalog/Makefile b/src/backend/catalog/Makefile index ec7b6f5362..9859b52662 100644 --- a/src/backend/catalog/Makefile +++ b/src/backend/catalog/Makefile @@ -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 $@ diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl index 380bc23c82..f7c8390e6d 100644 --- a/src/backend/catalog/genbki.pl +++ b/src/backend/catalog/genbki.pl @@ -25,13 +25,15 @@ use Catalog; 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; @@ -39,6 +41,7 @@ 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 '/') @@ -180,6 +183,12 @@ my $FirstUnpinnedObjectId = # 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! @@ -634,6 +643,23 @@ EOM 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 @@ -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}; @@ -1106,6 +1137,7 @@ Options: --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 diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 0c6f5ceb0a..54ec8f8421 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -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)); diff --git a/src/include/catalog/meson.build b/src/include/catalog/meson.build index dcb3c5f766..eb9cdc889c 100644 --- a/src/include/catalog/meson.build +++ b/src/include/catalog/meson.build @@ -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@' ], diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index a980b51f5d..35769d4777 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -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"; -- 2.40.1