|
21 | 21 | # Collect arguments
|
22 | 22 | my $infile; # pg_proc.h
|
23 | 23 | my $output_path = '';
|
| 24 | +my @include_path; |
| 25 | + |
24 | 26 | while (@ARGV)
|
25 | 27 | {
|
26 | 28 | my $arg = shift @ARGV;
|
|
32 | 34 | {
|
33 | 35 | $output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
|
34 | 36 | }
|
| 37 | + elsif ($arg =~ /^-I/) |
| 38 | + { |
| 39 | + push @include_path, length($arg) > 2 ? substr($arg, 2) : shift @ARGV; |
| 40 | + } |
35 | 41 | else
|
36 | 42 | {
|
37 | 43 | usage();
|
|
44 | 50 | $output_path .= '/';
|
45 | 51 | }
|
46 | 52 |
|
| 53 | +# Sanity check arguments. |
| 54 | +die "No input files.\n" if !$infile; |
| 55 | +die "No include path; you must specify -I at least once.\n" if !@include_path; |
| 56 | + |
| 57 | +my $FirstBootstrapObjectId = |
| 58 | + Catalog::FindDefinedSymbol('access/transam.h', \@include_path, 'FirstBootstrapObjectId'); |
| 59 | + |
47 | 60 | # Read all the data from the include/catalog files.
|
48 | 61 | my $catalogs = Catalog::Catalogs($infile);
|
49 | 62 |
|
|
176 | 189 |
|
177 | 190 | #include "postgres.h"
|
178 | 191 |
|
| 192 | +#include "access/transam.h" |
179 | 193 | #include "utils/fmgrtab.h"
|
180 | 194 | #include "utils/fmgrprotos.h"
|
181 | 195 |
|
|
191 | 205 | print $pfh "extern Datum $s->{prosrc}(PG_FUNCTION_ARGS);\n";
|
192 | 206 | }
|
193 | 207 |
|
194 |
| -# Create the fmgr_builtins table |
| 208 | +# Create the fmgr_builtins table, collect data for fmgr_builtin_oid_index |
195 | 209 | print $tfh "\nconst FmgrBuiltin fmgr_builtins[] = {\n";
|
196 | 210 | my %bmap;
|
197 | 211 | $bmap{'t'} = 'true';
|
198 | 212 | $bmap{'f'} = 'false';
|
| 213 | +my @fmgr_builtin_oid_index; |
| 214 | +my $fmgr_count = 0; |
199 | 215 | foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
|
200 | 216 | {
|
201 | 217 | print $tfh
|
202 |
| -" { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, $s->{prosrc} },\n"; |
| 218 | +" { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, $s->{prosrc} }"; |
| 219 | + |
| 220 | + $fmgr_builtin_oid_index[$s->{oid}] = $fmgr_count++; |
| 221 | + |
| 222 | + if ($fmgr_count <= $#fmgr) |
| 223 | + { |
| 224 | + print $tfh ",\n"; |
| 225 | + } |
| 226 | + else |
| 227 | + { |
| 228 | + print $tfh "\n"; |
| 229 | + } |
| 230 | +} |
| 231 | +print $tfh "};\n"; |
| 232 | + |
| 233 | +print $tfh qq| |
| 234 | +const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)); |
| 235 | +|; |
| 236 | + |
| 237 | + |
| 238 | +# Create fmgr_builtins_oid_index table. |
| 239 | +# |
| 240 | +# Note that the array has to be filled up to FirstBootstrapObjectId, |
| 241 | +# as we can't rely on zero initialization as 0 is a valid mapping. |
| 242 | +print $tfh qq| |
| 243 | +const uint16 fmgr_builtin_oid_index[FirstBootstrapObjectId] = { |
| 244 | +|; |
| 245 | + |
| 246 | +for (my $i = 0; $i < $FirstBootstrapObjectId; $i++) |
| 247 | +{ |
| 248 | + my $oid = $fmgr_builtin_oid_index[$i]; |
| 249 | + |
| 250 | + # fmgr_builtin_oid_index is sparse, map nonexistant functions to |
| 251 | + # InvalidOidBuiltinMapping |
| 252 | + if (not defined $oid) |
| 253 | + { |
| 254 | + $oid = 'InvalidOidBuiltinMapping'; |
| 255 | + } |
| 256 | + |
| 257 | + if ($i + 1 == $FirstBootstrapObjectId) |
| 258 | + { |
| 259 | + print $tfh " $oid\n"; |
| 260 | + } |
| 261 | + else |
| 262 | + { |
| 263 | + print $tfh " $oid,\n"; |
| 264 | + } |
203 | 265 | }
|
| 266 | +print $tfh "};\n"; |
| 267 | + |
204 | 268 |
|
205 | 269 | # And add the file footers.
|
206 | 270 | print $ofh "\n#endif /* FMGROIDS_H */\n";
|
207 | 271 | print $pfh "\n#endif /* FMGRPROTOS_H */\n";
|
208 | 272 |
|
209 |
| -print $tfh |
210 |
| -qq| /* dummy entry is easier than getting rid of comma after last real one */ |
211 |
| - /* (not that there has ever been anything wrong with *having* a |
212 |
| - comma after the last field in an array initializer) */ |
213 |
| - { 0, NULL, 0, false, false, NULL } |
214 |
| -}; |
215 |
| -
|
216 |
| -/* Note fmgr_nbuiltins excludes the dummy entry */ |
217 |
| -const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1; |
218 |
| -|; |
219 |
| - |
220 | 273 | close($ofh);
|
221 | 274 | close($pfh);
|
222 | 275 | close($tfh);
|
|
0 commit comments