}
# Rename temporary files to final names.
-# Call this function with the final file name --- we append .tmp automatically
+# Call this function with the final file name and the .tmp extension
+# Note: recommended extension is ".tmp$$", so that parallel make steps
+# can't use the same temp files
sub RenameTempFile
{
my $final_name = shift;
- my $temp_name = $final_name . '.tmp';
+ my $extension = shift;
+ my $temp_name = $final_name . $extension;
print "Writing $final_name\n";
rename($temp_name, $final_name) || die "rename: $temp_name: $!";
}
}
# Open temp files
-open BKI, '>', $output_path . 'postgres.bki.tmp'
- || die "can't open postgres.bki.tmp: $!";
-open SCHEMAPG, '>', $output_path . 'schemapg.h.tmp'
- || die "can't open 'schemapg.h.tmp: $!";
-open DESCR, '>', $output_path . 'postgres.description.tmp'
- || die "can't open postgres.description.tmp: $!";
-open SHDESCR, '>', $output_path . 'postgres.shdescription.tmp'
- || die "can't open postgres.shdescription.tmp: $!";
+my $tmpext = ".tmp$$";
+my $bkifile = $output_path . 'postgres.bki';
+open BKI, '>', $bkifile . $tmpext
+ or die "can't open $bkifile$tmpext: $!";
+my $schemafile = $output_path . 'schemapg.h';
+open SCHEMAPG, '>', $schemafile . $tmpext
+ or die "can't open $schemafile$tmpext: $!";
+my $descrfile = $output_path . 'postgres.description';
+open DESCR, '>', $descrfile . $tmpext
+ or die "can't open $descrfile$tmpext: $!";
+my $shdescrfile = $output_path . 'postgres.shdescription';
+open SHDESCR, '>', $shdescrfile . $tmpext
+ or die "can't open $shdescrfile$tmpext: $!";
# Fetch some special data that we will substitute into the output file.
# CAUTION: be wary about what symbols you substitute into the .bki file here!
# We're done emitting data
close BKI;
+close SCHEMAPG;
close DESCR;
close SHDESCR;
-close SCHEMAPG;
# Finally, rename the completed files into place.
-Catalog::RenameTempFile($output_path . 'postgres.bki');
-Catalog::RenameTempFile($output_path . 'postgres.description');
-Catalog::RenameTempFile($output_path . 'postgres.shdescription');
-Catalog::RenameTempFile($output_path . 'schemapg.h');
+Catalog::RenameTempFile($bkifile, $tmpext);
+Catalog::RenameTempFile($schemafile, $tmpext);
+Catalog::RenameTempFile($descrfile, $tmpext);
+Catalog::RenameTempFile($shdescrfile, $tmpext);
exit 0;
my $data = $catalogs->{pg_proc}->{data};
foreach my $row (@$data)
{
-
# To construct fmgroids.h and fmgrtab.c, we need to inspect some
# of the individual data fields. Just splitting on whitespace
# won't work, because some quoted fields might contain internal
nargs => $row->{pronargs},
prosrc => $row->{prosrc},
};
+
+ # Hack to work around memory leak in some versions of Perl
+ $row = undef;
}
# Emit headers for both files
-open H, '>', $output_path . 'fmgroids.h.tmp' || die "Could not open fmgroids.h.tmp: $!";
+my $tmpext = ".tmp$$";
+my $oidsfile = $output_path . 'fmgroids.h';
+my $tabfile = $output_path . 'fmgrtab.c';
+
+open H, '>', $oidsfile . $tmpext or die "Could not open $oidsfile$tmpext: $!";
+open T, '>', $tabfile . $tmpext or die "Could not open $tabfile$tmpext: $!";
+
print H
qq|/*-------------------------------------------------------------------------
*
*/
|;
-open T, '>', $output_path . 'fmgrtab.c.tmp' || die "Could not open fmgrtab.c.tmp: $!";
print T
qq|/*-------------------------------------------------------------------------
*
# And add the file footers.
print H "\n#endif /* FMGROIDS_H */\n";
-close(H);
print T
qq| /* dummy entry is easier than getting rid of comma after last real one */
const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;
|;
+close(H);
close(T);
# Finally, rename the completed files into place.
-Catalog::RenameTempFile($output_path . 'fmgroids.h');
-Catalog::RenameTempFile($output_path . 'fmgrtab.c');
+Catalog::RenameTempFile($oidsfile, $tmpext);
+Catalog::RenameTempFile($tabfile, $tmpext);
sub usage
{