mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
Generate fmgr prototypes automatically
Gen_fmgrtab.pl creates a new file fmgrprotos.h, which contains prototypes for all functions registered in pg_proc.h. This avoids having to manually maintain these prototypes across a random variety of header files. It also automatically enforces a correct function signature, and since there are warnings about missing prototypes, it will detect functions that are defined but not registered in pg_proc.h (or otherwise used). Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com>
This commit is contained in:
@@ -87,9 +87,11 @@ foreach my $row (@$data)
|
||||
# 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 H, '>', $oidsfile . $tmpext or die "Could not open $oidsfile$tmpext: $!";
|
||||
open P, '>', $protosfile . $tmpext or die "Could not open $protosfile$tmpext: $!";
|
||||
open T, '>', $tabfile . $tmpext or die "Could not open $tabfile$tmpext: $!";
|
||||
|
||||
print H
|
||||
@@ -130,6 +132,33 @@ qq|/*-------------------------------------------------------------------------
|
||||
*/
|
||||
|;
|
||||
|
||||
print P
|
||||
qq|/*-------------------------------------------------------------------------
|
||||
*
|
||||
* fmgrprotos.h
|
||||
* Prototypes for built-in functions.
|
||||
*
|
||||
* Portions Copyright (c) 1996-2016, 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 $0
|
||||
* from $infile
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef FMGRPROTOS_H
|
||||
#define FMGRPROTOS_H
|
||||
|
||||
#include "fmgr.h"
|
||||
|
||||
|;
|
||||
|
||||
print T
|
||||
qq|/*-------------------------------------------------------------------------
|
||||
*
|
||||
@@ -154,6 +183,7 @@ qq|/*-------------------------------------------------------------------------
|
||||
#include "postgres.h"
|
||||
|
||||
#include "utils/fmgrtab.h"
|
||||
#include "utils/fmgrprotos.h"
|
||||
|
||||
|;
|
||||
|
||||
@@ -164,7 +194,7 @@ foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
|
||||
next if $seenit{ $s->{prosrc} };
|
||||
$seenit{ $s->{prosrc} } = 1;
|
||||
print H "#define F_" . uc $s->{prosrc} . " $s->{oid}\n";
|
||||
print T "extern Datum $s->{prosrc} (PG_FUNCTION_ARGS);\n";
|
||||
print P "extern Datum $s->{prosrc}(PG_FUNCTION_ARGS);\n";
|
||||
}
|
||||
|
||||
# Create the fmgr_builtins table
|
||||
@@ -180,6 +210,7 @@ foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
|
||||
|
||||
# And add the file footers.
|
||||
print H "\n#endif /* FMGROIDS_H */\n";
|
||||
print P "\n#endif /* FMGRPROTOS_H */\n";
|
||||
|
||||
print T
|
||||
qq| /* dummy entry is easier than getting rid of comma after last real one */
|
||||
@@ -193,10 +224,12 @@ const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
|
||||
|;
|
||||
|
||||
close(H);
|
||||
close(P);
|
||||
close(T);
|
||||
|
||||
# Finally, rename the completed files into place.
|
||||
Catalog::RenameTempFile($oidsfile, $tmpext);
|
||||
Catalog::RenameTempFile($protosfile, $tmpext);
|
||||
Catalog::RenameTempFile($tabfile, $tmpext);
|
||||
|
||||
sub usage
|
||||
|
||||
Reference in New Issue
Block a user