|
64 | 64 |
|
65 | 65 | # Collect certain fields from pg_proc.dat.
|
66 | 66 | my @fmgr = ();
|
| 67 | +my %proname_counts; |
67 | 68 |
|
68 | 69 | foreach my $row (@{ $catalog_data{pg_proc} })
|
69 | 70 | {
|
70 | 71 | my %bki_values = %$row;
|
71 | 72 |
|
72 |
| - # Select out just the rows for internal-language procedures. |
73 |
| - next if $bki_values{prolang} ne 'internal'; |
74 |
| - |
75 | 73 | push @fmgr,
|
76 | 74 | {
|
77 | 75 | oid => $bki_values{oid},
|
| 76 | + name => $bki_values{proname}, |
| 77 | + lang => $bki_values{prolang}, |
78 | 78 | strict => $bki_values{proisstrict},
|
79 | 79 | retset => $bki_values{proretset},
|
80 | 80 | nargs => $bki_values{pronargs},
|
| 81 | + args => $bki_values{proargtypes}, |
81 | 82 | prosrc => $bki_values{prosrc},
|
82 | 83 | };
|
| 84 | + |
| 85 | + # Count so that we can detect overloaded pronames. |
| 86 | + $proname_counts{ $bki_values{proname} }++; |
83 | 87 | }
|
84 | 88 |
|
85 | 89 | # Emit headers for both files
|
|
122 | 126 | /*
|
123 | 127 | * Constant macros for the OIDs of entries in pg_proc.
|
124 | 128 | *
|
125 |
| - * NOTE: macros are named after the prosrc value, ie the actual C name |
126 |
| - * of the implementing function, not the proname which may be overloaded. |
127 |
| - * For example, we want to be able to assign different macro names to both |
128 |
| - * char_text() and name_text() even though these both appear with proname |
129 |
| - * 'text'. If the same C function appears in more than one pg_proc entry, |
130 |
| - * its equivalent macro will be defined with the lowest OID among those |
131 |
| - * entries. |
| 129 | + * F_XXX macros are named after the proname field; if that is not unique, |
| 130 | + * we append the proargtypes field, replacing spaces with underscores. |
| 131 | + * For example, we have F_OIDEQ because that proname is unique, but |
| 132 | + * F_POW_FLOAT8_FLOAT8 (among others) because that proname is not. |
132 | 133 | */
|
133 | 134 | OFH
|
134 | 135 |
|
|
186 | 187 |
|
187 | 188 | TFH
|
188 | 189 |
|
189 |
| -# Emit #define's and extern's -- only one per prosrc value |
| 190 | +# Emit fmgroids.h and fmgrprotos.h entries in OID order. |
190 | 191 | my %seenit;
|
191 | 192 | foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
|
192 | 193 | {
|
193 |
| - next if $seenit{ $s->{prosrc} }; |
194 |
| - $seenit{ $s->{prosrc} } = 1; |
195 |
| - print $ofh "#define F_" . uc $s->{prosrc} . " $s->{oid}\n"; |
196 |
| - print $pfh "extern Datum $s->{prosrc}(PG_FUNCTION_ARGS);\n"; |
| 194 | + my $sqlname = $s->{name}; |
| 195 | + $sqlname .= "_" . $s->{args} if ($proname_counts{ $s->{name} } > 1); |
| 196 | + $sqlname =~ s/\s+/_/g; |
| 197 | + print $ofh "#define F_" . uc $sqlname . " $s->{oid}\n"; |
| 198 | + # We want only one extern per internal-language function |
| 199 | + if ($s->{lang} eq 'internal' && !$seenit{ $s->{prosrc} }) |
| 200 | + { |
| 201 | + $seenit{ $s->{prosrc} } = 1; |
| 202 | + print $pfh "extern Datum $s->{prosrc}(PG_FUNCTION_ARGS);\n"; |
| 203 | + } |
197 | 204 | }
|
198 | 205 |
|
199 | 206 | # Create the fmgr_builtins table, collect data for fmgr_builtin_oid_index
|
|
206 | 213 | my $fmgr_count = 0;
|
207 | 214 | foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
|
208 | 215 | {
|
| 216 | + next if $s->{lang} ne 'internal'; |
| 217 | + |
| 218 | + print $tfh ",\n" if ($fmgr_count > 0); |
209 | 219 | print $tfh
|
210 | 220 | " { $s->{oid}, $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, \"$s->{prosrc}\", $s->{prosrc} }";
|
211 | 221 |
|
212 | 222 | $fmgr_builtin_oid_index[ $s->{oid} ] = $fmgr_count++;
|
213 | 223 | $last_builtin_oid = $s->{oid};
|
214 |
| - |
215 |
| - if ($fmgr_count <= $#fmgr) |
216 |
| - { |
217 |
| - print $tfh ",\n"; |
218 |
| - } |
219 |
| - else |
220 |
| - { |
221 |
| - print $tfh "\n"; |
222 |
| - } |
223 | 224 | }
|
224 |
| -print $tfh "};\n"; |
| 225 | +print $tfh "\n};\n"; |
225 | 226 |
|
226 | 227 | printf $tfh qq|
|
227 | 228 | const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin));
|
|
0 commit comments