v1-0001-Dumb-script-to-apply-PGDLLIMPORT-markings.patch

application/octet-stream

Filename: v1-0001-Dumb-script-to-apply-PGDLLIMPORT-markings.patch
Type: application/octet-stream
Part: 0
Message: Re: Mark all GUC variable as PGDLLIMPORT

Patch

Format: format-patch
Series: patch v1-0001
Subject: Dumb script to apply PGDLLIMPORT markings.
File+
src/tools/mark_pgdllimport.pl 47 0
From 2ca0b4de166ed62958d4467a48d16c49a058b57a Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Tue, 15 Feb 2022 08:44:28 -0500
Subject: [PATCH v1 1/2] Dumb script to apply PGDLLIMPORT markings.

---
 src/tools/mark_pgdllimport.pl | 47 +++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100755 src/tools/mark_pgdllimport.pl

diff --git a/src/tools/mark_pgdllimport.pl b/src/tools/mark_pgdllimport.pl
new file mode 100755
index 0000000000..020ef7364c
--- /dev/null
+++ b/src/tools/mark_pgdllimport.pl
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+
+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 (<$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 !/^extern\s+/ || /PGDLLIMPORT/;
+
+		# Variable declarations should end in a semicolon, but if the semicolon
+		# is preceded by a closing parenthesis, it's probably a function
+		# declaration.
+		$needs_pgdllimport = 0 if !/;$/ || /\);$/;
+
+		# Add PGDLLIMPORT marker, if required.
+		if ($needs_pgdllimport)
+		{
+			s/^extern/extern PGDLLIMPORT/;
+			++$num_pgdllimport_added;
+		}
+
+		# Add line to buffer.
+		$buffer .= $_;
+	}
+
+	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);
+	}
+}
-- 
2.24.3 (Apple Git-128)