mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
Get rid of the need for manual maintenance of the initial contents of
pg_attribute, by having genbki.pl derive the information from the various catalog header files. This greatly simplifies modification of the "bootstrapped" catalogs. This patch finally kills genbki.sh and Gen_fmgrtab.sh; we now rely entirely on Perl scripts for those build steps. To avoid creating a Perl build dependency where there was not one before, the output files generated by these scripts are now treated as distprep targets, ie, they will be built and shipped in tarballs. But you will need a reasonably modern Perl (probably at least 5.6) if you want to build from a CVS pull. The changes to the MSVC build process are untested, and may well break --- we'll soon find out from the buildfarm. John Naylor, based on ideas from Robert Haas and others
This commit is contained in:
@ -2,85 +2,89 @@
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Gen_fmgrtab.pl
|
||||
# Perl equivalent of Gen_fmgrtab.sh
|
||||
#
|
||||
# Usage: perl Gen_fmgrtab.pl path-to-pg_proc.h
|
||||
#
|
||||
# The reason for implementing this functionality twice is that we don't
|
||||
# require people to have perl to build from a tarball, but on the other
|
||||
# hand Windows can't deal with shell scripts.
|
||||
# Perl script that generates fmgroids.h and fmgrtab.c from pg_proc.h
|
||||
#
|
||||
# Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
||||
# Portions Copyright (c) 1994, Regents of the University of California
|
||||
#
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $PostgreSQL: pgsql/src/backend/utils/Gen_fmgrtab.pl,v 1.3 2010/01/02 16:57:53 momjian Exp $
|
||||
# $PostgreSQL: pgsql/src/backend/utils/Gen_fmgrtab.pl,v 1.4 2010/01/05 01:06:56 tgl Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
use Catalog;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
# Collect arguments
|
||||
my $infile = shift;
|
||||
defined($infile) || die "$0: missing required argument: pg_proc.h\n";
|
||||
|
||||
# Note: see Gen_fmgrtab.sh for detailed commentary on what this is doing
|
||||
|
||||
# Collect column numbers for pg_proc columns we need
|
||||
my ($proname, $prolang, $proisstrict, $proretset, $pronargs, $prosrc);
|
||||
|
||||
open(I, $infile) || die "Could not open $infile: $!";
|
||||
while (<I>)
|
||||
my $infile; # pg_proc.h
|
||||
my $output_path = '';
|
||||
while (@ARGV)
|
||||
{
|
||||
if (m/#define Anum_pg_proc_proname\s+(\d+)/) {
|
||||
$proname = $1;
|
||||
my $arg = shift @ARGV;
|
||||
if ($arg !~ /^-/)
|
||||
{
|
||||
$infile = $arg;
|
||||
}
|
||||
if (m/#define Anum_pg_proc_prolang\s+(\d+)/) {
|
||||
$prolang = $1;
|
||||
elsif ($arg =~ /^-o/)
|
||||
{
|
||||
$output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
|
||||
}
|
||||
if (m/#define Anum_pg_proc_proisstrict\s+(\d+)/) {
|
||||
$proisstrict = $1;
|
||||
}
|
||||
if (m/#define Anum_pg_proc_proretset\s+(\d+)/) {
|
||||
$proretset = $1;
|
||||
}
|
||||
if (m/#define Anum_pg_proc_pronargs\s+(\d+)/) {
|
||||
$pronargs = $1;
|
||||
}
|
||||
if (m/#define Anum_pg_proc_prosrc\s+(\d+)/) {
|
||||
$prosrc = $1;
|
||||
else
|
||||
{
|
||||
usage();
|
||||
}
|
||||
}
|
||||
close(I);
|
||||
|
||||
# Collect the raw data
|
||||
my @fmgr = ();
|
||||
|
||||
open(I, $infile) || die "Could not open $infile: $!";
|
||||
while (<I>)
|
||||
# Make sure output_path ends in a slash.
|
||||
if ($output_path ne '' && substr($output_path, -1) ne '/')
|
||||
{
|
||||
next unless (/^DATA/);
|
||||
s/^[^O]*OID[^=]*=[ \t]*//;
|
||||
s/\(//;
|
||||
s/"[^"]*"/"xxx"/g;
|
||||
my @p = split;
|
||||
next if ($p[$prolang] ne "12");
|
||||
$output_path .= '/';
|
||||
}
|
||||
|
||||
# Read all the data from the include/catalog files.
|
||||
my $catalogs = Catalog::Catalogs($infile);
|
||||
|
||||
# Collect the raw data from pg_proc.h.
|
||||
my @fmgr = ();
|
||||
my @attnames;
|
||||
foreach my $column ( @{ $catalogs->{pg_proc}->{columns} } )
|
||||
{
|
||||
push @attnames, keys %$column;
|
||||
}
|
||||
|
||||
my $data = $catalogs->{pg_proc}->{data};
|
||||
foreach my $row (@$data)
|
||||
{
|
||||
|
||||
# To construct fmgroids.h and fmgrtab.c, we need to inspect some
|
||||
# of the individual data fields. Just splitting on whitespace
|
||||
# won't work, because some quoted fields might contain internal
|
||||
# whitespace. We handle this by folding them all to a simple
|
||||
# "xxx". Fortunately, this script doesn't need to look at any
|
||||
# fields that might need quoting, so this simple hack is
|
||||
# sufficient.
|
||||
$row->{bki_values} =~ s/"[^"]*"/"xxx"/g;
|
||||
@{$row}{@attnames} = split /\s+/, $row->{bki_values};
|
||||
|
||||
# Select out just the rows for internal-language procedures.
|
||||
# Note assumption here that INTERNALlanguageId is 12.
|
||||
next if $row->{prolang} ne '12';
|
||||
|
||||
push @fmgr,
|
||||
{
|
||||
oid => $p[0],
|
||||
proname => $p[$proname],
|
||||
strict => $p[$proisstrict],
|
||||
retset => $p[$proretset],
|
||||
nargs => $p[$pronargs],
|
||||
prosrc => $p[$prosrc],
|
||||
oid => $row->{oid},
|
||||
strict => $row->{proisstrict},
|
||||
retset => $row->{proretset},
|
||||
nargs => $row->{pronargs},
|
||||
prosrc => $row->{prosrc},
|
||||
};
|
||||
}
|
||||
close(I);
|
||||
|
||||
# Emit headers for both files
|
||||
open(H, '>', "$$-fmgroids.h") || die "Could not open $$-fmgroids.h: $!";
|
||||
open H, '>', $output_path . 'fmgroids.h.tmp' || die "Could not open fmgroids.h.tmp: $!";
|
||||
print H
|
||||
qq|/*-------------------------------------------------------------------------
|
||||
*
|
||||
@ -119,7 +123,7 @@ qq|/*-------------------------------------------------------------------------
|
||||
*/
|
||||
|;
|
||||
|
||||
open(T, '>', "$$-fmgrtab.c") || die "Could not open $$-fmgrtab.c: $!";
|
||||
open T, '>', $output_path . 'fmgrtab.c.tmp' || die "Could not open fmgrtab.c.tmp: $!";
|
||||
print T
|
||||
qq|/*-------------------------------------------------------------------------
|
||||
*
|
||||
@ -186,9 +190,18 @@ const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
|
||||
close(T);
|
||||
|
||||
# Finally, rename the completed files into place.
|
||||
rename "$$-fmgroids.h", "fmgroids.h"
|
||||
|| die "Could not rename $$-fmgroids.h to fmgroids.h: $!";
|
||||
rename "$$-fmgrtab.c", "fmgrtab.c"
|
||||
|| die "Could not rename $$-fmgrtab.c to fmgrtab.c: $!";
|
||||
Catalog::RenameTempFile($output_path . 'fmgroids.h');
|
||||
Catalog::RenameTempFile($output_path . 'fmgrtab.c');
|
||||
|
||||
sub usage
|
||||
{
|
||||
die <<EOM;
|
||||
Usage: perl -I [directory of Catalog.pm] Gen_fmgrtab.pl [path to pg_proc.h]
|
||||
|
||||
Gen_fmgrtab.pl generates fmgroids.h and fmgrtab.c from pg_proc.h
|
||||
|
||||
Report bugs to <pgsql-bugs\@postgresql.org>.
|
||||
EOM
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
@ -1,253 +0,0 @@
|
||||
#! /bin/sh
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Gen_fmgrtab.sh
|
||||
# shell script to generate fmgroids.h and fmgrtab.c from pg_proc.h
|
||||
#
|
||||
# NOTE: if you change this, you need to fix Gen_fmgrtab.pl too!
|
||||
#
|
||||
# Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
||||
# Portions Copyright (c) 1994, Regents of the University of California
|
||||
#
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $PostgreSQL: pgsql/src/backend/utils/Gen_fmgrtab.sh,v 1.42 2010/01/02 16:57:53 momjian Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
CMDNAME=`basename $0`
|
||||
|
||||
if [ x"$AWK" = x"" ]; then
|
||||
AWK=awk
|
||||
fi
|
||||
|
||||
cleanup(){
|
||||
[ x"$noclean" != x"t" ] && rm -f "$SORTEDFILE" "$$-$OIDSFILE" "$$-$TABLEFILE"
|
||||
}
|
||||
|
||||
noclean=
|
||||
|
||||
#
|
||||
# Process command line switches.
|
||||
#
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
case $1 in
|
||||
--noclean)
|
||||
noclean=t
|
||||
;;
|
||||
--help)
|
||||
echo "$CMDNAME generates fmgroids.h and fmgrtab.c from pg_proc.h."
|
||||
echo
|
||||
echo "Usage:"
|
||||
echo " $CMDNAME inputfile"
|
||||
echo
|
||||
echo "The environment variable AWK determines which Awk program"
|
||||
echo "to use. The default is \`awk'."
|
||||
echo
|
||||
echo "Report bugs to <pgsql-bugs@postgresql.org>."
|
||||
exit 0
|
||||
;;
|
||||
-*)
|
||||
echo "$CMDNAME: invalid option: $1"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
INFILE=$1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
|
||||
if [ x"$INFILE" = x ] ; then
|
||||
echo "$CMDNAME: no input file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SORTEDFILE="$$-fmgr.data"
|
||||
OIDSFILE=fmgroids.h
|
||||
TABLEFILE=fmgrtab.c
|
||||
|
||||
|
||||
trap 'echo "Caught signal." ; cleanup ; exit 1' 1 2 15
|
||||
|
||||
#
|
||||
# Collect the column numbers of the pg_proc columns we need. Because we will
|
||||
# be looking at data that includes the OID as the first column, add one to
|
||||
# each column number.
|
||||
#
|
||||
proname=`egrep '^#define Anum_pg_proc_proname[ ]' $INFILE | $AWK '{print $3+1}'`
|
||||
prolang=`egrep '^#define Anum_pg_proc_prolang[ ]' $INFILE | $AWK '{print $3+1}'`
|
||||
proisstrict=`egrep '^#define Anum_pg_proc_proisstrict[ ]' $INFILE | $AWK '{print $3+1}'`
|
||||
proretset=`egrep '^#define Anum_pg_proc_proretset[ ]' $INFILE | $AWK '{print $3+1}'`
|
||||
pronargs=`egrep '^#define Anum_pg_proc_pronargs[ ]' $INFILE | $AWK '{print $3+1}'`
|
||||
prosrc=`egrep '^#define Anum_pg_proc_prosrc[ ]' $INFILE | $AWK '{print $3+1}'`
|
||||
|
||||
#
|
||||
# Generate the file containing raw pg_proc data. We do three things here:
|
||||
# 1. Strip off the DATA macro call, leaving procedure OID as $1
|
||||
# and all the pg_proc field values as $2, $3, etc on each line.
|
||||
# 2. Fold quoted fields to simple "xxx". We need this because such fields
|
||||
# may contain whitespace, which would confuse awk's counting of fields.
|
||||
# Fortunately, this script doesn't need to look at any fields that might
|
||||
# need quoting, so this simple hack is sufficient.
|
||||
# 3. Select out just the rows for internal-language procedures.
|
||||
#
|
||||
# Note assumption here that INTERNALlanguageId == 12.
|
||||
#
|
||||
egrep '^DATA' $INFILE | \
|
||||
sed -e 's/^[^O]*OID[^=]*=[ ]*//' \
|
||||
-e 's/(//' \
|
||||
-e 's/"[^"]*"/"xxx"/g' | \
|
||||
$AWK "\$$prolang == \"12\" { print }" | \
|
||||
sort -n > $SORTEDFILE
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
cleanup
|
||||
echo "$CMDNAME failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
cpp_define=`echo $OIDSFILE | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | sed -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
|
||||
|
||||
#
|
||||
# Generate fmgroids.h
|
||||
#
|
||||
cat > "$$-$OIDSFILE" <<FuNkYfMgRsTuFf
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* $OIDSFILE
|
||||
* Macros that define the OIDs of built-in functions.
|
||||
*
|
||||
* These macros can be used to avoid a catalog lookup when a specific
|
||||
* fmgr-callable function needs to be referenced.
|
||||
*
|
||||
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* NOTES
|
||||
* ******************************
|
||||
* *** DO NOT EDIT THIS FILE! ***
|
||||
* ******************************
|
||||
*
|
||||
* It has been GENERATED by $CMDNAME
|
||||
* from $INFILE
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef $cpp_define
|
||||
#define $cpp_define
|
||||
|
||||
/*
|
||||
* Constant macros for the OIDs of entries in pg_proc.
|
||||
*
|
||||
* NOTE: macros are named after the prosrc value, ie the actual C name
|
||||
* of the implementing function, not the proname which may be overloaded.
|
||||
* For example, we want to be able to assign different macro names to both
|
||||
* char_text() and name_text() even though these both appear with proname
|
||||
* 'text'. If the same C function appears in more than one pg_proc entry,
|
||||
* its equivalent macro will be defined with the lowest OID among those
|
||||
* entries.
|
||||
*/
|
||||
FuNkYfMgRsTuFf
|
||||
|
||||
tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' < $SORTEDFILE | \
|
||||
$AWK "{ if (seenit[\$$prosrc]++ == 0)
|
||||
printf \"#define F_%s %s\\n\", \$$prosrc, \$1; }" >> "$$-$OIDSFILE"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
cleanup
|
||||
echo "$CMDNAME failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat >> "$$-$OIDSFILE" <<FuNkYfMgRsTuFf
|
||||
|
||||
#endif /* $cpp_define */
|
||||
FuNkYfMgRsTuFf
|
||||
|
||||
#
|
||||
# Generate fmgr's built-in-function table.
|
||||
#
|
||||
# Print out the function declarations, then the table that refers to them.
|
||||
#
|
||||
cat > "$$-$TABLEFILE" <<FuNkYfMgRtAbStUfF
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* $TABLEFILE
|
||||
* The function manager's table of internal functions.
|
||||
*
|
||||
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
* ******************************
|
||||
* *** DO NOT EDIT THIS FILE! ***
|
||||
* ******************************
|
||||
*
|
||||
* It has been GENERATED by $CMDNAME
|
||||
* from $INFILE
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "utils/fmgrtab.h"
|
||||
|
||||
FuNkYfMgRtAbStUfF
|
||||
|
||||
$AWK "{ if (seenit[\$$prosrc]++ == 0)
|
||||
print \"extern Datum\", \$$prosrc, \"(PG_FUNCTION_ARGS);\"; }" $SORTEDFILE >> "$$-$TABLEFILE"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
cleanup
|
||||
echo "$CMDNAME failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
cat >> "$$-$TABLEFILE" <<FuNkYfMgRtAbStUfF
|
||||
|
||||
const FmgrBuiltin fmgr_builtins[] = {
|
||||
FuNkYfMgRtAbStUfF
|
||||
|
||||
# Note: using awk arrays to translate from pg_proc values to fmgrtab values
|
||||
# may seem tedious, but avoid the temptation to write a quick x?y:z
|
||||
# conditional expression instead. Not all awks have conditional expressions.
|
||||
|
||||
$AWK "BEGIN {
|
||||
Bool[\"t\"] = \"true\";
|
||||
Bool[\"f\"] = \"false\";
|
||||
}
|
||||
{ printf (\" { %d, \\\"%s\\\", %d, %s, %s, %s },\\n\"),
|
||||
\$1, \$$prosrc, \$$pronargs, Bool[\$$proisstrict], Bool[\$$proretset], \$$prosrc ;
|
||||
}" $SORTEDFILE >> "$$-$TABLEFILE"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
cleanup
|
||||
echo "$CMDNAME failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat >> "$$-$TABLEFILE" <<FuNkYfMgRtAbStUfF
|
||||
/* dummy entry is easier than getting rid of comma after last real one */
|
||||
/* (not that there has ever been anything wrong with *having* a
|
||||
comma after the last field in an array initializer) */
|
||||
{ 0, NULL, 0, false, false, NULL }
|
||||
};
|
||||
|
||||
/* Note fmgr_nbuiltins excludes the dummy entry */
|
||||
const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
|
||||
FuNkYfMgRtAbStUfF
|
||||
|
||||
# We use the temporary files to avoid problems with concurrent runs
|
||||
# (which can happen during parallel make).
|
||||
mv "$$-$OIDSFILE" $OIDSFILE
|
||||
mv "$$-$TABLEFILE" $TABLEFILE
|
||||
|
||||
cleanup
|
||||
exit 0
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# Makefile for utils
|
||||
#
|
||||
# $PostgreSQL: pgsql/src/backend/utils/Makefile,v 1.28 2008/08/01 13:16:09 alvherre Exp $
|
||||
# $PostgreSQL: pgsql/src/backend/utils/Makefile,v 1.29 2010/01/05 01:06:56 tgl Exp $
|
||||
#
|
||||
|
||||
subdir = src/backend/utils
|
||||
@ -11,14 +11,20 @@ include $(top_builddir)/src/Makefile.global
|
||||
OBJS = fmgrtab.o
|
||||
SUBDIRS = adt cache error fmgr hash init mb misc mmgr resowner sort time
|
||||
|
||||
# location of Catalog.pm
|
||||
catalogdir = $(top_srcdir)/src/backend/catalog
|
||||
|
||||
include $(top_srcdir)/src/backend/common.mk
|
||||
|
||||
all: fmgroids.h probes.h
|
||||
|
||||
$(SUBDIRS:%=%-recursive): fmgroids.h
|
||||
|
||||
fmgroids.h fmgrtab.c: Gen_fmgrtab.sh $(top_srcdir)/src/include/catalog/pg_proc.h
|
||||
AWK='$(AWK)' $(SHELL) $< $(top_srcdir)/src/include/catalog/pg_proc.h
|
||||
# see explanation in ../parser/Makefile
|
||||
fmgroids.h: fmgrtab.c ;
|
||||
|
||||
fmgrtab.c: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.h
|
||||
$(PERL) -I $(catalogdir) $< $(top_srcdir)/src/include/catalog/pg_proc.h
|
||||
|
||||
ifneq ($(enable_dtrace), yes)
|
||||
probes.h: Gen_dummy_probes.sed
|
||||
@ -34,5 +40,10 @@ else
|
||||
endif
|
||||
|
||||
|
||||
# fmgroids.h and fmgrtab.c are in the distribution tarball, so they
|
||||
# are not cleaned here.
|
||||
clean:
|
||||
rm -f fmgroids.h fmgrtab.c probes.h
|
||||
rm -f probes.h
|
||||
|
||||
maintainer-clean: clean
|
||||
rm -f fmgroids.h fmgrtab.c
|
||||
|
3
src/backend/utils/cache/relcache.c
vendored
3
src/backend/utils/cache/relcache.c
vendored
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.295 2010/01/02 16:57:55 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.296 2010/01/05 01:06:56 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -50,6 +50,7 @@
|
||||
#include "catalog/pg_rewrite.h"
|
||||
#include "catalog/pg_tablespace.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "catalog/schemapg.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "miscadmin.h"
|
||||
#include "optimizer/clauses.h"
|
||||
|
Reference in New Issue
Block a user