summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Haas2022-04-08 12:06:10 +0000
committerRobert Haas2022-04-08 12:06:10 +0000
commit80900d4690916a30f278d877eb5a7a42b14c3f0a (patch)
tree3af2b7bddf6dbc831fb142af86082e34a76c1305
parent57d6aea00fcefec3825a5948ce05cf2b4941097b (diff)
Helper script to apply PGDLLIMPORT markings.
This script isn't terribly smart and won't necessarily catch every case, but it catches many of them and is better than a totally manual approach. Patch by me, reviewed by Andrew Dunstan. Discussion: http://postgr.es/m/CA+TgmoYanc1_FSfimhgiWSqVyP5KKmh5NP2BWNwDhO8Pg2vGYQ@mail.gmail.com
-rwxr-xr-xsrc/tools/mark_pgdllimport.pl75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/tools/mark_pgdllimport.pl b/src/tools/mark_pgdllimport.pl
new file mode 100755
index 0000000000..3152c1428b
--- /dev/null
+++ b/src/tools/mark_pgdllimport.pl
@@ -0,0 +1,75 @@
+#!/usr/bin/perl
+
+#----------------------------------------------------------------------
+#
+# mark_pgdllimport.pl
+# Perl script that tries to add PGDLLIMPORT markings to PostgreSQL
+# header files.
+#
+# This relies on a few idiosyncracies of the PostgreSQL cding style,
+# such as the fact that we always use "extern" in function
+# declarations, and that we don't use // comments. It's not very
+# smart and may not catch all cases.
+#
+# It's probably a good idea to run pgindent on any files that this
+# script modifies before committing.
+#
+# Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
+# Portions Copyright (c) 1994, Regents of the University of California
+#
+# src/tools/mark_pgdllimport.pl
+#
+#----------------------------------------------------------------------
+
+use strict;
+use warnings;
+
+for my $include_file (@ARGV)
+{
+ open(my $rfh, '<', $include_file) || die "$include_file: $!";
+ my $buffer = '';
+ my $num_pgdllimport_added = 0;
+
+ while (my $raw_line = <$rfh>)
+ {
+ my $needs_pgdllimport = 1;
+
+ # By convention we declare global variables explicitly extern. We're
+ # looking for those not already marked with PGDLLIMPORT.
+ $needs_pgdllimport = 0 if $raw_line !~ /^extern\s+/
+ || $raw_line =~ /PGDLLIMPORT/;
+
+ # Make a copy of the line and perform a simple-minded comment strip.
+ # Also strip trailing whitespace.
+ my $stripped_line = $raw_line;
+ $stripped_line =~ s/\/\*.*\*\///g;
+ $stripped_line =~ s/\s+$//;
+
+ # Variable declarations should end in a semicolon. If we see an
+ # opening parenthesis, it's probably a function declaration.
+ $needs_pgdllimport = 0 if $stripped_line !~ /;$/
+ || $stripped_line =~ /\(/;
+
+ # Add PGDLLIMPORT marker, if required.
+ if ($needs_pgdllimport)
+ {
+ $raw_line =~ s/^extern/extern PGDLLIMPORT/;
+ ++$num_pgdllimport_added;
+ }
+
+ # Add line to buffer.
+ $buffer .= $raw_line;
+ }
+
+ close($rfh);
+
+ # If we added any PGDLLIMPORT markers, rewrite the file.
+ if ($num_pgdllimport_added > 0)
+ {
+ printf "%s: adding %d PGDLLIMPORT markers\n",
+ $include_file, $num_pgdllimport_added;
+ open(my $wfh, '>', $include_file) || die "$include_file: $!";
+ print $wfh $buffer;
+ close($wfh);
+ }
+}