Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteeee069

Browse files
committed
Fix Gen_fmgrtab.sh to not rely on hard-wired knowledge of the column numbers
in pg_proc. Also make it not emit duplicate extern declarations, and make ita bit more bulletproof in some other small ways. Likewise fix the equallyhard-wired, and utterly undocumented, knowledge in the MSVC build scripts.For testing purposes and perhaps other uses in future, pull out that portionof the MSVC scripts into a standalone perl script equivalent toGen_fmgrtab.sh, and make it generate actually identical output, rather thanjust more-or-less-the-same output.Motivated by looking at Pavel's variadic function patch. Whether or notthat gets accepted, we can be sure that pg_proc's column set will changeagain in the future; it's time to not have to deal with this gotcha.
1 parentdab421d commiteeee069

File tree

3 files changed

+237
-83
lines changed

3 files changed

+237
-83
lines changed

‎src/backend/utils/Gen_fmgrtab.pl

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#! /usr/bin/perl -w
2+
#-------------------------------------------------------------------------
3+
#
4+
# Gen_fmgrtab.pl
5+
# Perl equivalent of Gen_fmgrtab.sh
6+
#
7+
# Usage: perl Gen_fmgrtab.pl path-to-pg_proc.h
8+
#
9+
# The reason for implementing this functionality twice is that we don't
10+
# require people to have perl to build from a tarball, but on the other
11+
# hand Windows can't deal with shell scripts.
12+
#
13+
# Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
14+
# Portions Copyright (c) 1994, Regents of the University of California
15+
#
16+
#
17+
# IDENTIFICATION
18+
# $PostgreSQL: pgsql/src/backend/utils/Gen_fmgrtab.pl,v 1.1 2008/06/23 17:54:29 tgl Exp $
19+
#
20+
#-------------------------------------------------------------------------
21+
22+
use strict;
23+
use warnings;
24+
25+
# Collect arguments
26+
my$infile =shift;
27+
defined($infile) ||die"$0: missing required argument: pg_proc.h\n";
28+
29+
# Note: see Gen_fmgrtab.sh for detailed commentary on what this is doing
30+
31+
# Collect column numbers for pg_proc columns we need
32+
my ($proname,$prolang,$proisstrict,$proretset,$pronargs,$prosrc);
33+
34+
open(I,$infile) ||die"Could not open$infile:$!";
35+
while (<I>)
36+
{
37+
if (m/#define Anum_pg_proc_proname\s+(\d+)/) {
38+
$proname =$1;
39+
}
40+
if (m/#define Anum_pg_proc_prolang\s+(\d+)/) {
41+
$prolang =$1;
42+
}
43+
if (m/#define Anum_pg_proc_proisstrict\s+(\d+)/) {
44+
$proisstrict =$1;
45+
}
46+
if (m/#define Anum_pg_proc_proretset\s+(\d+)/) {
47+
$proretset =$1;
48+
}
49+
if (m/#define Anum_pg_proc_pronargs\s+(\d+)/) {
50+
$pronargs =$1;
51+
}
52+
if (m/#define Anum_pg_proc_prosrc\s+(\d+)/) {
53+
$prosrc =$1;
54+
}
55+
}
56+
close(I);
57+
58+
# Collect the raw data
59+
my@fmgr = ();
60+
61+
open(I,$infile) ||die"Could not open$infile:$!";
62+
while (<I>)
63+
{
64+
nextunless (/^DATA/);
65+
s/^[^O]*OID[^=]*=[\t]*//;
66+
s/\(//;
67+
s/"[^"]*"/"xxx"/g;
68+
my@p =split;
69+
nextif ($p[$prolang]ne"12");
70+
push@fmgr,
71+
{
72+
oid=>$p[0],
73+
proname=>$p[$proname],
74+
strict=>$p[$proisstrict],
75+
retset=>$p[$proretset],
76+
nargs=>$p[$pronargs],
77+
prosrc=>$p[$prosrc],
78+
};
79+
}
80+
close(I);
81+
82+
# Emit headers for both files
83+
open(H,'>',"$$-fmgroids.h") ||die"Could not open$$-fmgroids.h:$!";
84+
print H
85+
qq|/*-------------------------------------------------------------------------
86+
*
87+
* fmgroids.h
88+
* Macros that define the OIDs of built-in functions.
89+
*
90+
* These macros can be used to avoid a catalog lookup when a specific
91+
* fmgr-callable function needs to be referenced.
92+
*
93+
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
94+
* Portions Copyright (c) 1994, Regents of the University of California
95+
*
96+
* NOTES
97+
*******************************
98+
**** DO NOT EDIT THIS FILE! ***
99+
*******************************
100+
*
101+
*It has been GENERATED by$0
102+
*from$infile
103+
*
104+
*-------------------------------------------------------------------------
105+
*/
106+
#ifndef FMGROIDS_H
107+
#define FMGROIDS_H
108+
109+
/*
110+
*Constant macros for the OIDs of entries in pg_proc.
111+
*
112+
*NOTE: macros are named after the prosrc value, ie the actual C name
113+
*of the implementing function, not the proname which may be overloaded.
114+
*For example, we want to be able to assign different macro names to both
115+
*char_text() and name_text() even though these both appear with proname
116+
*'text'. If the same C function appears in more than one pg_proc entry,
117+
*its equivalent macro will be defined with the lowest OID among those
118+
*entries.
119+
*/
120+
|;
121+
122+
open(T,'>',"$$-fmgrtab.c") ||die"Could not open$$-fmgrtab.c:$!";
123+
print T
124+
qq|/*-------------------------------------------------------------------------
125+
*
126+
* fmgrtab.c
127+
* The function manager's table of internal functions.
128+
*
129+
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
130+
* Portions Copyright (c) 1994, Regents of the University of California
131+
*
132+
* NOTES
133+
*
134+
*******************************
135+
**** DO NOT EDIT THIS FILE! ***
136+
*******************************
137+
*
138+
*It has been GENERATED by$0
139+
*from$infile
140+
*
141+
*-------------------------------------------------------------------------
142+
*/
143+
144+
#include "postgres.h"
145+
146+
#include "utils/fmgrtab.h"
147+
148+
|;
149+
150+
# Emit #define's and extern's -- only one per prosrc value
151+
my%seenit;
152+
foreachmy$s (sort {$a->{oid}<=>$b->{oid}}@fmgr)
153+
{
154+
nextif$seenit{$s->{prosrc}};
155+
$seenit{$s->{prosrc}} = 1;
156+
print H"#define F_" .uc$s->{prosrc} ."$s->{oid}\n";
157+
print T"extern Datum$s->{prosrc} (PG_FUNCTION_ARGS);\n";
158+
}
159+
160+
# Create the fmgr_builtins table
161+
print T"\nconst FmgrBuiltin fmgr_builtins[] = {\n";
162+
my%bmap;
163+
$bmap{'t'} ='true';
164+
$bmap{'f'} ='false';
165+
foreachmy$s (sort {$a->{oid}<=>$b->{oid}}@fmgr)
166+
{
167+
print T
168+
" {$s->{oid},\"$s->{prosrc}\",$s->{nargs},$bmap{$s->{strict}},$bmap{$s->{retset}},$s->{prosrc} },\n";
169+
}
170+
171+
# And add the file footers.
172+
print H"\n#endif /* FMGROIDS_H */\n";
173+
close(H);
174+
175+
print T
176+
qq| /* dummy entry is easier than getting rid of comma after last real one */
177+
/* (not that there has ever been anything wrong with *having* a
178+
comma after the last field in an array initializer) */
179+
{ 0, NULL, 0, false, false, NULL }
180+
};
181+
182+
/* Note fmgr_nbuiltins excludes the dummy entry */
183+
const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
184+
|;
185+
186+
close(T);
187+
188+
# Finally, rename the completed files into place.
189+
rename"$$-fmgroids.h","fmgroids.h"
190+
||die"Could not rename$$-fmgroids.h to fmgroids.h:$!";
191+
rename"$$-fmgrtab.c","fmgrtab.c"
192+
||die"Could not rename$$-fmgrtab.c to fmgrtab.c:$!";
193+
194+
exit 0;

‎src/backend/utils/Gen_fmgrtab.sh

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
# Gen_fmgrtab.sh
55
# shell script to generate fmgroids.h and fmgrtab.c from pg_proc.h
66
#
7+
# NOTE: if you change this, you need to fix Gen_fmgrtab.pl too!
8+
#
79
# Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
810
# Portions Copyright (c) 1994, Regents of the University of California
911
#
1012
#
1113
# IDENTIFICATION
12-
# $PostgreSQL: pgsql/src/backend/utils/Gen_fmgrtab.sh,v 1.39 2008/05/02 14:16:24 petere Exp $
14+
# $PostgreSQL: pgsql/src/backend/utils/Gen_fmgrtab.sh,v 1.40 2008/06/23 17:54:29 tgl Exp $
1315
#
1416
#-------------------------------------------------------------------------
1517

@@ -70,20 +72,35 @@ TABLEFILE=fmgrtab.c
7072

7173
trap'echo "Caught signal." ; cleanup ; exit 1' 1 2 15
7274

75+
#
76+
# Collect the column numbers of the pg_proc columns we need. Because we will
77+
# be looking at data that includes the OID as the first column, add one to
78+
# each column number.
79+
#
80+
proname=`egrep'^#define Anum_pg_proc_proname[ ]'$INFILE|$AWK'{print $3+1}'`
81+
prolang=`egrep'^#define Anum_pg_proc_prolang[ ]'$INFILE|$AWK'{print $3+1}'`
82+
proisstrict=`egrep'^#define Anum_pg_proc_proisstrict[ ]'$INFILE|$AWK'{print $3+1}'`
83+
proretset=`egrep'^#define Anum_pg_proc_proretset[ ]'$INFILE|$AWK'{print $3+1}'`
84+
pronargs=`egrep'^#define Anum_pg_proc_pronargs[ ]'$INFILE|$AWK'{print $3+1}'`
85+
prosrc=`egrep'^#define Anum_pg_proc_prosrc[ ]'$INFILE|$AWK'{print $3+1}'`
7386

7487
#
75-
# Generate the file containing raw pg_proc tuple data
76-
# (but only for "internal" language procedures...).
77-
# Basically we strip off the DATA macro call, leaving procedure OID as $1
88+
# Generate the file containing raw pg_proc data. We do three things here:
89+
# 1. Strip off the DATA macro call, leaving procedure OID as $1
7890
# and all the pg_proc field values as $2, $3, etc on each line.
91+
# 2. Fold quoted fields to simple "xxx". We need this because such fields
92+
# may contain whitespace, which would confuse awk's counting of fields.
93+
# Fortunately, this script doesn't need to look at any fields that might
94+
# need quoting, so this simple hack is sufficient.
95+
# 3. Select out just the rows for internal-language procedures.
7996
#
80-
# Note assumption here thatprolang == $5 andINTERNALlanguageId == 12.
97+
# Note assumption here that INTERNALlanguageId == 12.
8198
#
8299
egrep'^DATA'$INFILE| \
83-
sed -e's/^.*OID[^=]*=[^0-9]*//' \
84-
-e's/(//g' \
85-
-e's/[ ]*).*$//'| \
86-
$AWK'$5 == "12" { print }'| \
100+
sed -e's/^[^O]*OID[^=]*=[]*//' \
101+
-e's/(//' \
102+
-e's/"[^"]*"/"xxx"/g'| \
103+
$AWK"\$$prolang ==\"12\" { print }"| \
87104
sort -n>$SORTEDFILE
88105

89106
if [$?-ne 0 ];then
@@ -120,7 +137,7 @@ cat > "$$-$OIDSFILE" <<FuNkYfMgRsTuFf
120137
*
121138
*-------------------------------------------------------------------------
122139
*/
123-
#ifndef$cpp_define
140+
#ifndef$cpp_define
124141
#define$cpp_define
125142
126143
/*
@@ -136,12 +153,9 @@ cat > "$$-$OIDSFILE" <<FuNkYfMgRsTuFf
136153
*/
137154
FuNkYfMgRsTuFf
138155

139-
# Note assumption here that prosrc == $(NF-3).
140-
141156
tr'abcdefghijklmnopqrstuvwxyz''ABCDEFGHIJKLMNOPQRSTUVWXYZ'<$SORTEDFILE| \
142-
$AWK'
143-
BEGIN{ OFS = ""; }
144-
{ if (seenit[$(NF-3)]++ == 0) print "#define F_", $(NF-3), " ", $1; }'>>"$$-$OIDSFILE"
157+
$AWK"{ if (seenit[\$$prosrc]++ == 0)
158+
printf\"#define F_%s %s\\n\",\$$prosrc,\$1; }">>"$$-$OIDSFILE"
145159

146160
if [$?-ne 0 ];then
147161
cleanup
@@ -151,7 +165,7 @@ fi
151165

152166
cat>>"$$-$OIDSFILE"<<FuNkYfMgRsTuFf
153167
154-
#endif/*$cpp_define */
168+
#endif/*$cpp_define */
155169
FuNkYfMgRsTuFf
156170

157171
#
@@ -186,9 +200,8 @@ cat > "$$-$TABLEFILE" <<FuNkYfMgRtAbStUfF
186200
187201
FuNkYfMgRtAbStUfF
188202

189-
# Note assumption here that prosrc == $(NF-3).
190-
191-
$AWK'{ print "extern Datum", $(NF-3), "(PG_FUNCTION_ARGS);"; }'$SORTEDFILE>>"$$-$TABLEFILE"
203+
$AWK"{ if (seenit[\$$prosrc]++ == 0)
204+
print\"extern Datum\",\$$prosrc,\"(PG_FUNCTION_ARGS);\"; }"$SORTEDFILE>>"$$-$TABLEFILE"
192205

193206
if [$?-ne 0 ];then
194207
cleanup
@@ -205,17 +218,14 @@ FuNkYfMgRtAbStUfF
205218
# Note: using awk arrays to translate from pg_proc values to fmgrtab values
206219
# may seem tedious, but avoid the temptation to write a quick x?y:z
207220
# conditional expression instead. Not all awks have conditional expressions.
208-
#
209-
# Note assumptions here that prosrc == $(NF-3), pronargs == $13,
210-
# proisstrict == $10, proretset == $11
211221

212-
$AWK'BEGIN {
213-
Bool["t"] = "true"
214-
Bool["f"] = "false"
222+
$AWK"BEGIN {
223+
Bool[\"t\"] =\"true\";
224+
Bool[\"f\"] =\"false\";
215225
}
216-
{ printf (" { %d, \"%s\", %d, %s, %s, %s },\n"), \
217-
$1,$(NF-3), $13, Bool[$10], Bool[$11],$(NF-3)
218-
}'$SORTEDFILE>>"$$-$TABLEFILE"
226+
{ printf (\" { %d,\\\"%s\\\", %d, %s, %s, %s },\\n\"),
227+
\$1,\$$prosrc,\$$pronargs, Bool[\$$proisstrict], Bool[\$$proretset],\$$prosrc ;
228+
}"$SORTEDFILE>>"$$-$TABLEFILE"
219229

220230
if [$?-ne 0 ];then
221231
cleanup
@@ -232,7 +242,6 @@ cat >> "$$-$TABLEFILE" <<FuNkYfMgRtAbStUfF
232242
233243
/* Note fmgr_nbuiltins excludes the dummy entry */
234244
const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
235-
236245
FuNkYfMgRtAbStUfF
237246

238247
# We use the temporary files to avoid problems with concurrent runs

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp