#! /usr/bin/perl #------------------------------------------------------------------------- # # Gen_fmgrtab.pl # Perl script that generates fmgroids.h, fmgrprotos.h, and fmgrtab.c # from pg_proc.dat # # Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group # Portions Copyright (c) 1994, Regents of the University of California # # # IDENTIFICATION # src/backend/utils/Gen_fmgrtab.pl # #-------------------------------------------------------------------------
use Catalog;
use strict;
use warnings FATAL => 'all';
use Getopt::Long;
# Make sure output_path ends in a slash. if ($output_path ne '' && substr($output_path, -1) ne '/')
{
$output_path .= '/';
}
# Sanity check arguments.
die "No input files.\n" unless @ARGV;
die "--include-path must be specified.\n" unless $include_path;
# Read all the input files into internal data structures. # Note: We pass data file names as arguments and then look for matching # headers to parse the schema from. This is backwards from genbki.pl, # but the Makefile dependencies look more sensible this way. # We currently only need pg_proc, but retain the possibility of reading # more than one data file.
my %catalogs;
my %catalog_data; foreach my $datfile (@ARGV)
{
$datfile =~ /(.+)\.dat$/
or die "Input files need to be data (.dat) files.\n";
my $header = "$1.h";
die "There in no header file corresponding to $datfile" if !-e $header;
my $catalog = Catalog::ParseHeader($header);
my $catname = $catalog->{catname};
my $schema = $catalog->{columns};
# Count so that we can detect overloaded pronames.
$proname_counts{ $bki_values{proname} }++;
}
# Emit headers for both files
my $tmpext = ".tmp$$";
my $oidsfile = $output_path . 'fmgroids.h';
my $protosfile = $output_path . 'fmgrprotos.h';
my $tabfile = $output_path . 'fmgrtab.c';
open my $ofh, '>', $oidsfile . $tmpext
or die "Could not open $oidsfile$tmpext: $!";
open my $pfh, '>', $protosfile . $tmpext
or die "Could not open $protosfile$tmpext: $!";
open my $tfh, '>', $tabfile . $tmpext
or die "Could not open $tabfile$tmpext: $!";
print $ofh <<OFH;
/*-------------------------------------------------------------------------
*
* fmgroids.h
* 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-2025, 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 src/backend/utils/Gen_fmgrtab.pl
*
*-------------------------------------------------------------------------
*/ #ifndef FMGROIDS_H #define FMGROIDS_H
/*
* Constant macros for the OIDs of entries in pg_proc.
*
* F_XXX macros are named after the proname field; if that is not unique,
* we append the proargtypes field, replacing spaces with underscores.
* For example, we have F_OIDEQ because that proname is unique, but
* F_POW_FLOAT8_FLOAT8 (among others) because that proname is not.
*/
OFH
print $pfh <<PFH;
/*-------------------------------------------------------------------------
*
* fmgrprotos.h
* Prototypes for built-in functions.
*
* Portions Copyright (c) 1996-2025, 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 src/backend/utils/Gen_fmgrtab.pl
*
*-------------------------------------------------------------------------
*/
#ifndef FMGRPROTOS_H #define FMGRPROTOS_H
#include "fmgr.h"
PFH
print $tfh <<TFH;
/*-------------------------------------------------------------------------
*
* fmgrtab.c
* The function manager's table of internal functions.
*
* Portions Copyright (c) 1996-2025, 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 src/backend/utils/Gen_fmgrtab.pl
*
*-------------------------------------------------------------------------
*/
# Emit fmgroids.h and fmgrprotos.h entries in OID order.
my %seenit; foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
{
my $sqlname = $s->{name};
$sqlname .= "_" . $s->{args} if ($proname_counts{ $s->{name} } > 1);
$sqlname =~ s/\s+/_/g;
print $ofh "#define F_" . uc $sqlname . " $s->{oid}\n"; # We want only one extern per internal-language, non-aggregate function if ( $s->{lang} eq 'internal'
&& $s->{kind} ne 'a'
&& !$seenit{ $s->{prosrc} })
{
$seenit{ $s->{prosrc} } = 1;
print $pfh "extern Datum $s->{prosrc}(PG_FUNCTION_ARGS);\n";
}
}
# Create the fmgr_builtins table, collect data for fmgr_builtin_oid_index
print $tfh "\nconst FmgrBuiltin fmgr_builtins[] = {\n";
my %bmap;
$bmap{'t'} = 'true';
$bmap{'f'} = 'false';
my @fmgr_builtin_oid_index;
my $last_builtin_oid = 0;
my $fmgr_count = 0;
foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
{
next if $s->{lang} ne 'internal'; # We do not need entries for aggregate functions
next if $s->{kind} eq 'a';
for (my $i = 0; $i <= $last_builtin_oid; $i++)
{
my $oid = $fmgr_builtin_oid_index[$i];
# fmgr_builtin_oid_index is sparse, map nonexistent functions to # InvalidOidBuiltinMapping if (not defined $oid)
{
$oid = 'InvalidOidBuiltinMapping';
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.