# Collect certain fields from pg_proc.dat.
my @fmgr = ();
+my %proname_counts;
foreach my $row (@{ $catalog_data{pg_proc} })
{
my %bki_values = %$row;
- # Select out just the rows for internal-language procedures.
- next if $bki_values{prolang} ne 'internal';
-
push @fmgr,
{
oid => $bki_values{oid},
+ name => $bki_values{proname},
+ lang => $bki_values{prolang},
strict => $bki_values{proisstrict},
retset => $bki_values{proretset},
nargs => $bki_values{pronargs},
+ args => $bki_values{proargtypes},
prosrc => $bki_values{prosrc},
};
+
+ # Count so that we can detect overloaded pronames.
+ $proname_counts{ $bki_values{proname} }++;
}
# Emit headers for both files
/*
* 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.
+ * 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
TFH
-# Emit #define's and extern's -- only one per prosrc value
+# Emit fmgroids.h and fmgrprotos.h entries in OID order.
my %seenit;
foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
{
- next if $seenit{ $s->{prosrc} };
- $seenit{ $s->{prosrc} } = 1;
- print $ofh "#define F_" . uc $s->{prosrc} . " $s->{oid}\n";
- print $pfh "extern Datum $s->{prosrc}(PG_FUNCTION_ARGS);\n";
+ 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 function
+ if ($s->{lang} eq 'internal' && !$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
my $fmgr_count = 0;
foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
{
+ next if $s->{lang} ne 'internal';
+
+ print $tfh ",\n" if ($fmgr_count > 0);
print $tfh
" { $s->{oid}, $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, \"$s->{prosrc}\", $s->{prosrc} }";
$fmgr_builtin_oid_index[ $s->{oid} ] = $fmgr_count++;
$last_builtin_oid = $s->{oid};
-
- if ($fmgr_count <= $#fmgr)
- {
- print $tfh ",\n";
- }
- else
- {
- print $tfh "\n";
- }
}
-print $tfh "};\n";
+print $tfh "\n};\n";
printf $tfh qq|
const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin));