VS 2015 support in src/tools/msvc

Started by Michael Paquieralmost 10 years ago134 messages
#1Michael Paquier
michael.paquier@gmail.com

Hi all,

Microsoft provides a set of VMs that one can use for testing and
Windows 10 is in the set:
https://dev.windows.com/en-us/microsoft-edge/tools/vms/windows/
I have grabbed one and installed the community version of Visual
Studio 2015 so I think that I am going to be able to compile Postgres
with VS2015 with a bit of black magic.

My goal is double:
1) As far as things have been discussed, VS2015 is making difficult
the compilation of Postgres, particularly for locales. So I'd like to
see what are the problems behind that and see if we can patch it
properly. This would facilitate the integration of cmake as well for
Windows.
2) src/tools/msvc stuff has support only up to VS2013. I think that it
would be nice to bump that a bit and get something for 9.5~.

So, would there be interest for a patch on the perl scripts in
src/tools/msvc or are they considered a lost cause? Having a look at
the failures could be done with the cmake work, but it seems a bit
premature to me to look at that for the moment, and having support for
VS2015 with 9.5 (support for new versions of VS won a backpatch the
last couple of years) would be a good thing I think.

Thoughts?
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Petr Jelinek
petr@2ndquadrant.com
In reply to: Michael Paquier (#1)
Re: VS 2015 support in src/tools/msvc

On 03/03/16 15:02, Michael Paquier wrote:

Hi all,

Microsoft provides a set of VMs that one can use for testing and
Windows 10 is in the set:
https://dev.windows.com/en-us/microsoft-edge/tools/vms/windows/
I have grabbed one and installed the community version of Visual
Studio 2015 so I think that I am going to be able to compile Postgres
with VS2015 with a bit of black magic.

My goal is double:
1) As far as things have been discussed, VS2015 is making difficult
the compilation of Postgres, particularly for locales. So I'd like to
see what are the problems behind that and see if we can patch it
properly. This would facilitate the integration of cmake as well for
Windows.

The locale problem is that:
a) the MS crt headers are broken for this particular part due to
unfinished refactoring, even their msvcrt sources don't compile with
them, if you read them it's obvious they forgot to put one variable in
the struct
b) we are using somewhat legacy API there that's internally implemented
as hacks over the new API (string parsing and generation and stuff is
happening there)
c) the non-legacy API works only on Vista+ and does not support the old
locale names (which is why the legacy api that is written on top of this
has to do the string parsing and generation)

To me the least bad solution for MSVC 2015 and codepage detection seemed
to use the new API when possible (GetLocaleInfoEx and friends) and fall
back to our old string parsing that we did pre-VC2013 when it's not,
since afaics it works correctly on all the locale names that are not
supported by the new API. It means that MSVC 2015 builds would be Vista+
but I honestly don't see that as big issue given Microsoft's own policy
about old Windows versions.

2) src/tools/msvc stuff has support only up to VS2013. I think that it
would be nice to bump that a bit and get something for 9.5~.

Yeah, we'll also have to do something about perl 5.22 compatibility
there as psed is not included in the core distribution anymore from that
version and we use it to generate one header file IIRC.

So, would there be interest for a patch on the perl scripts in
src/tools/msvc or are they considered a lost cause? Having a look at
the failures could be done with the cmake work, but it seems a bit
premature to me to look at that for the moment, and having support for
VS2015 with 9.5 (support for new versions of VS won a backpatch the
last couple of years) would be a good thing I think.

+1, and I can help (at least review and testing if nothing else).

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Petr Jelinek (#2)
Re: VS 2015 support in src/tools/msvc

Petr Jelinek <petr@2ndquadrant.com> writes:

On 03/03/16 15:02, Michael Paquier wrote:

So, would there be interest for a patch on the perl scripts in
src/tools/msvc or are they considered a lost cause? Having a look at
the failures could be done with the cmake work, but it seems a bit
premature to me to look at that for the moment, and having support for
VS2015 with 9.5 (support for new versions of VS won a backpatch the
last couple of years) would be a good thing I think.

+1, and I can help (at least review and testing if nothing else).

Yeah. At this point, the earliest the cmake work could land is 9.7,
and TBH I do not think we are committed to landing it at all. So it'd
behoove us to fix at least HEAD, and probably older branches too,
to work with up-to-date MSVC.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#3)
Re: VS 2015 support in src/tools/msvc

Tom Lane wrote:

Yeah. At this point, the earliest the cmake work could land is 9.7,
and TBH I do not think we are committed to landing it at all. So it'd
behoove us to fix at least HEAD, and probably older branches too,
to work with up-to-date MSVC.

In that case we should probably add the configure check for IPC::Run
that was proposed in another thread.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#4)
Re: VS 2015 support in src/tools/msvc

Alvaro Herrera <alvherre@2ndquadrant.com> writes:

Tom Lane wrote:

Yeah. At this point, the earliest the cmake work could land is 9.7,
and TBH I do not think we are committed to landing it at all. So it'd
behoove us to fix at least HEAD, and probably older branches too,
to work with up-to-date MSVC.

In that case we should probably add the configure check for IPC::Run
that was proposed in another thread.

Yeah, agreed. I opposed it at the time because I thought we might be
considering cmake conversion for 9.6. But now that that's missed the
final 9.6 commitfest, we'd better operate on the assumption that it's
not landing anytime soon.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#1)
Re: VS 2015 support in src/tools/msvc

On 03/03/2016 09:02 AM, Michael Paquier wrote:

Hi all,

Microsoft provides a set of VMs that one can use for testing and
Windows 10 is in the set:
https://dev.windows.com/en-us/microsoft-edge/tools/vms/windows/
I have grabbed one and installed the community version of Visual
Studio 2015 so I think that I am going to be able to compile Postgres
with VS2015 with a bit of black magic.

My goal is double:
1) As far as things have been discussed, VS2015 is making difficult
the compilation of Postgres, particularly for locales. So I'd like to
see what are the problems behind that and see if we can patch it
properly. This would facilitate the integration of cmake as well for
Windows.
2) src/tools/msvc stuff has support only up to VS2013. I think that it
would be nice to bump that a bit and get something for 9.5~.

So, would there be interest for a patch on the perl scripts in
src/tools/msvc or are they considered a lost cause? Having a look at
the failures could be done with the cmake work, but it seems a bit
premature to me to look at that for the moment, and having support for
VS2015 with 9.5 (support for new versions of VS won a backpatch the
last couple of years) would be a good thing I think.

I am not holding my breath on cmake. Until we have something pretty
solid on that front I'm going to assume it's not happening. If we're
going to support VS2015 (and I think we should) then it should be
supported for all live branches if possible. I'm assuming the changes
would be pretty localized, at least in src/tools/msvc, and adding a new
compile shouldn't break anything with existing compilers.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Magnus Hagander
magnus@hagander.net
In reply to: Andrew Dunstan (#6)
Re: VS 2015 support in src/tools/msvc

On Thu, Mar 3, 2016 at 6:18 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

On 03/03/2016 09:02 AM, Michael Paquier wrote:

Hi all,

Microsoft provides a set of VMs that one can use for testing and
Windows 10 is in the set:
https://dev.windows.com/en-us/microsoft-edge/tools/vms/windows/
I have grabbed one and installed the community version of Visual
Studio 2015 so I think that I am going to be able to compile Postgres
with VS2015 with a bit of black magic.

My goal is double:
1) As far as things have been discussed, VS2015 is making difficult
the compilation of Postgres, particularly for locales. So I'd like to
see what are the problems behind that and see if we can patch it
properly. This would facilitate the integration of cmake as well for
Windows.
2) src/tools/msvc stuff has support only up to VS2013. I think that it
would be nice to bump that a bit and get something for 9.5~.

So, would there be interest for a patch on the perl scripts in
src/tools/msvc or are they considered a lost cause? Having a look at
the failures could be done with the cmake work, but it seems a bit
premature to me to look at that for the moment, and having support for
VS2015 with 9.5 (support for new versions of VS won a backpatch the
last couple of years) would be a good thing I think.

I am not holding my breath on cmake. Until we have something pretty solid
on that front I'm going to assume it's not happening. If we're going to
support VS2015 (and I think we should) then it should be supported for all
live branches if possible. I'm assuming the changes would be pretty
localized, at least in src/tools/msvc, and adding a new compile shouldn't
break anything with existing compilers.

+1.

Definitely do it for HEAD.

Then if it gets backpatched is going to depend on the locality I think. If
it's just the build system then it should be no problem, but I thought
Michael also suggested some API changes. If that's so, then it is going to
depend on how invasive those are. But that part should be done for HEAD
regardless, so it's definitely worth the effort to figure out exactly what
it involves.

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

#8Petr Jelinek
petr@2ndquadrant.com
In reply to: Magnus Hagander (#7)
Re: VS 2015 support in src/tools/msvc

On 03/03/16 18:41, Magnus Hagander wrote:

On Thu, Mar 3, 2016 at 6:18 PM, Andrew Dunstan <andrew@dunslane.net
<mailto:andrew@dunslane.net>> wrote:

On 03/03/2016 09:02 AM, Michael Paquier wrote:

Microsoft provides a set of VMs that one can use for testing and
Windows 10 is in the set:
https://dev.windows.com/en-us/microsoft-edge/tools/vms/windows/
I have grabbed one and installed the community version of Visual
Studio 2015 so I think that I am going to be able to compile
Postgres
with VS2015 with a bit of black magic.

So, would there be interest for a patch on the perl scripts in
src/tools/msvc or are they considered a lost cause? Having a look at
the failures could be done with the cmake work, but it seems a bit
premature to me to look at that for the moment, and having
support for
VS2015 with 9.5 (support for new versions of VS won a backpatch the
last couple of years) would be a good thing I think.

I am not holding my breath on cmake. Until we have something pretty
solid on that front I'm going to assume it's not happening. If we're
going to support VS2015 (and I think we should) then it should be
supported for all live branches if possible. I'm assuming the
changes would be pretty localized, at least in src/tools/msvc, and
adding a new compile shouldn't break anything with existing compilers.

+1.

Definitely do it for HEAD.

Then if it gets backpatched is going to depend on the locality I think.
If it's just the build system then it should be no problem, but I
thought Michael also suggested some API changes. If that's so, then it
is going to depend on how invasive those are. But that part should be
done for HEAD regardless, so it's definitely worth the effort to figure
out exactly what it involves.

Well the source code does not compile on MSVC2015, the perl changes
needed are really tiny, there is some code that needs changes to work
with 2015, particularly in the locale code-page detection area so it's
definitely not just build system. But I think it should be fairly
localized and fenced by ifdef anyway.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#9Michael Paquier
michael.paquier@gmail.com
In reply to: Petr Jelinek (#8)
Re: VS 2015 support in src/tools/msvc

On Fri, Mar 4, 2016 at 7:21 AM, Petr Jelinek <petr@2ndquadrant.com> wrote:

Well the source code does not compile on MSVC2015, the perl changes needed
are really tiny, there is some code that needs changes to work with 2015,
particularly in the locale code-page detection area so it's definitely not
just build system. But I think it should be fairly localized and fenced by
ifdef anyway.

Yeah, that's my first impression as well. We should not need any APIs
changes and the changes would be limited to if extra blocks with
_MSC_VER, if that would occur then I definitely agree that patching
only HEAD is the way to go. I'll look at that today and the next
couple of days, let's see what I can get out of it...
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#10Michael Paquier
michael.paquier@gmail.com
In reply to: Michael Paquier (#9)
1 attachment(s)
Re: VS 2015 support in src/tools/msvc

On Fri, Mar 4, 2016 at 9:36 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Yeah, that's my first impression as well. We should not need any APIs
changes and the changes would be limited to if extra blocks with
_MSC_VER, if that would occur then I definitely agree that patching
only HEAD is the way to go. I'll look at that today and the next
couple of days, let's see what I can get out of it...

So, I have finally been able to set up my environment correctly, and I
am at a stage where I can compile Postgres with VS 2015 thanks to the
patch attached that extends src/tools/msvc to do so. Unsurprisingly,
the first failures detected are related to locales :)

I still need to dig into that in more details. For the time being the
patch attached is useful IMO to plug in VS 2015 with the existing
infrastructure. So if anybody has a Windows environment, feel free to
play with it and dig into those problems. I'll update this thread once
I have a more advanced status.
Regards,
--
Michael

Attachments:

vs-2015-support.patchapplication/x-patch; name=vs-2015-support.patchDownload
From 2e0a84eab407baacbc7372a08c6b533b97e2736b Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Fri, 4 Mar 2016 15:25:55 +0900
Subject: [PATCH] Add support for VS 2015

---
 doc/src/sgml/install-windows.sgml |  8 ++++----
 src/tools/msvc/MSBuildProject.pm  | 23 +++++++++++++++++++++++
 src/tools/msvc/Solution.pm        | 26 ++++++++++++++++++++++++++
 src/tools/msvc/VSObjectFactory.pm | 12 ++++++++++--
 4 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index f08cca7..148180b 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -19,10 +19,10 @@
  <para>
   There are several different ways of building PostgreSQL on
   <productname>Windows</productname>. The simplest way to build with
-  Microsoft tools is to install <productname>Visual Studio Express 2013
+  Microsoft tools is to install <productname>Visual Studio Express 2015
   for Windows Desktop</productname> and use the included
   compiler. It is also possible to build with the full
-  <productname>Microsoft Visual C++ 2005 to 2013</productname>.
+  <productname>Microsoft Visual C++ 2005 to 2015</productname>.
   In some cases that requires the installation of the
   <productname>Windows SDK</productname> in addition to the compiler.
  </para>
@@ -77,7 +77,7 @@
   <productname>Visual Studio Express</productname> or some versions of the
   <productname>Microsoft Windows SDK</productname>. If you do not already have a
   <productname>Visual Studio</productname> environment set up, the easiest
-  ways are to use the compilers from <productname>Visual Studio Express 2013
+  ways are to use the compilers from <productname>Visual Studio Express 2015
   for Windows Desktop</productname> or those in the <productname>Windows SDK
   7.1</productname>, which are both free downloads from Microsoft.
  </para>
@@ -85,7 +85,7 @@
  <para>
   PostgreSQL is known to support compilation using the compilers shipped with
   <productname>Visual Studio 2005</productname> to
-  <productname>Visual Studio 2013</productname> (including Express editions),
+  <productname>Visual Studio 2015</productname> (including Express editions),
   as well as standalone Windows SDK releases 6.0 to 7.1.
   64-bit PostgreSQL builds are only supported with
   <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 3d60b64..d7638b4 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -465,4 +465,27 @@ sub new
 	return $self;
 }
 
+package VC2015Project;
+
+#
+# Package that encapsulates a Visual C++ 2015 project file
+#
+
+use strict;
+use warnings;
+use base qw(VC2012Project);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{vcver}           = '14.00';
+	$self->{PlatformToolset} = 'v140';
+	$self->{ToolsVersion}    = '14.0';
+
+	return $self;
+}
+
 1;
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index ac116b7..e627a7b 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -778,6 +778,32 @@ sub new
 	return $self;
 }
 
+package VS2015Solution;
+
+#
+# Package that encapsulates a Visual Studio 2015 solution file
+#
+
+use Carp;
+use strict;
+use warnings;
+use base qw(Solution);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{solutionFileVersion}        = '14.00';
+	$self->{vcver}                      = '14.00';
+	$self->{visualStudioName}           = 'Visual Studio 2015';
+	$self->{VisualStudioVersion}        = '14.0.24730.2';
+	$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
+
+	return $self;
+}
+
 sub GetAdditionalHeaders
 {
 	my ($self, $f) = @_;
diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm
index fee4684..4190ada 100644
--- a/src/tools/msvc/VSObjectFactory.pm
+++ b/src/tools/msvc/VSObjectFactory.pm
@@ -49,6 +49,10 @@ sub CreateSolution
 	{
 		return new VS2013Solution(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VS2015Solution(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -84,6 +88,10 @@ sub CreateProject
 	{
 		return new VC2013Project(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VC2015Project(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion
 sub _GetVisualStudioVersion
 {
 	my ($major, $minor) = @_;
-	if ($major > 12)
+	if ($major > 14)
 	{
 		carp
 "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
-		return '12.00';
+		return '14.00';
 	}
 	elsif ($major < 6)
 	{
-- 
2.7.2

#11Michael Paquier
michael.paquier@gmail.com
In reply to: Michael Paquier (#10)
5 attachment(s)
Re: VS 2015 support in src/tools/msvc

On Fri, Mar 4, 2016 at 3:54 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

I still need to dig into that in more details. For the time being the
patch attached is useful IMO to plug in VS 2015 with the existing
infrastructure. So if anybody has a Windows environment, feel free to
play with it and dig into those problems. I'll update this thread once
I have a more advanced status.

OK, attached are a set of patches that allowed me to compile Postgres
using VS2015, in more details:
- 0001, as mentioned by Petr upthread, psed is removed from the core
distribution of Perl in 5.22, so when installing ActivePerl it is not
possible to create probes.h, and the code compilation would fail. I
bumped into that so here is a patch. What I am proposing here is to
replace psed by sed, sed being available in MSYS like bison and flex,
so when building using MSVC the environment to set up is normally
already good to go even with this additional dependency. Now, it is
important to mention that probes.h is not part of a source tarball. I
think that we would want probes.h to be part of a source tarball so as
it would be possible to compile the code on Windows using MSVC without
having to install MSYS. I haven't done that in this patch, thoughts on
the matter are welcome.
- 0002, which adds support for VS2015 in src/tools/scripts
- 0003, to address a compilation failure that I bumped into when
compiling ecpg. In src/port, TIMEZONE_GLOBAL and TZNAME_GLOBAL refer
to respectively timezone and tzname, however for win32, those should
be _timezone and _tzname. See here:
https://msdn.microsoft.com/en-us/library/htb3tdkc.aspx
- 0004, which is to address the problem of the missing lc_codepage
from locale.h in src/port/. I have been pondering about the use of
more fancy routines like GetLocaleInfoEx as mentioned by Petr
upthread. However, I think that we had better avoid any kind of
complication and just fall back to the old code path should _MSC_VER

= 1900. We could always reuse lc_codepage if it gets reintroduced in

a future version of VS.

This set of patches is clearly a work-in-progress, but I am at the
point where feedback is welcome, and the code can compile. The issue
wit psed is something I think could be backpatched a bit more than the
VS2015 core patches, support for perl 5.22 happening on all the
supported branches.
Note that I did not bump into the stdbool issues. Note as well that VS
has complained about a couple of warnings. I am attaching them in the
file named VS2015_warnings.txt. Those are quite interesting as well.
--
Michael

Attachments:

VS2015_warnings.txttext/plain; charset=US-ASCII; name=VS2015_warnings.txtDownload
0001-Replace-dependency-to-psed-by-sed.patchapplication/x-patch; name=0001-Replace-dependency-to-psed-by-sed.patchDownload
From 818ca5c42853f231c8875ade94fc78657b77db29 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Fri, 4 Mar 2016 22:54:35 +0900
Subject: [PATCH 1/4] Replace dependency to psed by sed

psed has been removed from the code packaging of perl in 5.22 and
it is used by the perl scripts in src/tools/msvc on Windows to create
probes.h.

Like Bison and Flex, sed is available as part of MSYS, so when compiling
the code from git the environment to set up does not change much.

Note to reviewers of this patch: we may want to have probes.h part of
a source tarball to allow people to compile Postgres on Windows without
having to install MSYS to satisfy the dependency with sed..
---
 doc/src/sgml/install-windows.sgml | 23 +++++++++++++++--------
 src/tools/msvc/Solution.pm        |  2 +-
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index f08cca7..6c11d2d 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -196,8 +196,8 @@ $ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
     </varlistentry>
 
     <varlistentry>
-     <term><productname>Bison</productname> and
-      <productname>Flex</productname></term>
+     <term><productname>Bison</productname>,
+      <productname>Flex</productname> and <productname>sed</productname></term>
      <listitem>
      <para>
       <productname>Bison</productname> and <productname>Flex</productname> are
@@ -207,9 +207,15 @@ $ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
      </para>
 
      <para>
-      Both <productname>Bison</productname> and <productname>Flex</productname>
-      are included in the <productname>msys</productname> tool suite, available
-      from <ulink url="http://www.mingw.org/wiki/MSYS"></> as part of the
+      <productname>sed</productname> is required to build from Git and to build
+      from a release file.
+     </para>
+
+     <para>
+      <productname>Bison</productname>, <productname>Flex</productname> and
+      <productname>sed</productname> are included in the
+      <productname>msys</productname> tool suite, available from
+      <ulink url="http://www.mingw.org/wiki/MSYS"></> as part of the
       <productname>MinGW</productname> compiler suite. You can also get
       <productname>msys</productname> as part of
       <productname>msysGit</productname> from <ulink url="http://git-scm.com/"></>.
@@ -217,9 +223,10 @@ $ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
 
      <para>
       You will need to add the directory containing
-      <filename>flex.exe</filename> and <filename>bison.exe</filename> to the
-      PATH environment variable in <filename>buildenv.pl</filename> unless
-      they are already in PATH. In the case of MinGW, the directory is the
+      <filename>flex.exe</filename>, <filename>bison.exe</filename> and
+      <filename>sed.exe</filename> to the PATH environment variable in
+      <filename>buildenv.pl</filename> unless they are already in PATH.
+      In the case of MinGW, the directory is the
       <filename>\msys\1.0\bin</filename> subdirectory of your MinGW
       installation directory. For msysGit, it's the <filename>bin</filename>
       directory in your Git install directory. Do not add the MinGW compiler
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index ac116b7..cb1d1a4 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -313,7 +313,7 @@ s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY
 	{
 		print "Generating probes.h...\n";
 		system(
-'psed -f src/backend/utils/Gen_dummy_probes.sed src/backend/utils/probes.d > src/include/utils/probes.h'
+'sed -f src/backend/utils/Gen_dummy_probes.sed src/backend/utils/probes.d > src/include/utils/probes.h'
 		);
 	}
 
-- 
2.7.2

0002-Add-support-for-VS-2015-in-MSVC-scripts.patchapplication/x-patch; name=0002-Add-support-for-VS-2015-in-MSVC-scripts.patchDownload
From ce7711c86be7783f2062677ac5e4a1d5c0c8b4ab Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Fri, 4 Mar 2016 15:25:55 +0900
Subject: [PATCH 2/4] Add support for VS 2015 in MSVC scripts

One can use that to compile with the latest version of Visual Studio
on Windows.
---
 doc/src/sgml/install-windows.sgml |  8 ++++----
 src/tools/msvc/MSBuildProject.pm  | 23 +++++++++++++++++++++++
 src/tools/msvc/Solution.pm        | 26 ++++++++++++++++++++++++++
 src/tools/msvc/VSObjectFactory.pm | 12 ++++++++++--
 4 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index 6c11d2d..c47f47e 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -19,10 +19,10 @@
  <para>
   There are several different ways of building PostgreSQL on
   <productname>Windows</productname>. The simplest way to build with
-  Microsoft tools is to install <productname>Visual Studio Express 2013
+  Microsoft tools is to install <productname>Visual Studio Express 2015
   for Windows Desktop</productname> and use the included
   compiler. It is also possible to build with the full
-  <productname>Microsoft Visual C++ 2005 to 2013</productname>.
+  <productname>Microsoft Visual C++ 2005 to 2015</productname>.
   In some cases that requires the installation of the
   <productname>Windows SDK</productname> in addition to the compiler.
  </para>
@@ -77,7 +77,7 @@
   <productname>Visual Studio Express</productname> or some versions of the
   <productname>Microsoft Windows SDK</productname>. If you do not already have a
   <productname>Visual Studio</productname> environment set up, the easiest
-  ways are to use the compilers from <productname>Visual Studio Express 2013
+  ways are to use the compilers from <productname>Visual Studio Express 2015
   for Windows Desktop</productname> or those in the <productname>Windows SDK
   7.1</productname>, which are both free downloads from Microsoft.
  </para>
@@ -85,7 +85,7 @@
  <para>
   PostgreSQL is known to support compilation using the compilers shipped with
   <productname>Visual Studio 2005</productname> to
-  <productname>Visual Studio 2013</productname> (including Express editions),
+  <productname>Visual Studio 2015</productname> (including Express editions),
   as well as standalone Windows SDK releases 6.0 to 7.1.
   64-bit PostgreSQL builds are only supported with
   <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 3d60b64..d7638b4 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -465,4 +465,27 @@ sub new
 	return $self;
 }
 
+package VC2015Project;
+
+#
+# Package that encapsulates a Visual C++ 2015 project file
+#
+
+use strict;
+use warnings;
+use base qw(VC2012Project);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{vcver}           = '14.00';
+	$self->{PlatformToolset} = 'v140';
+	$self->{ToolsVersion}    = '14.0';
+
+	return $self;
+}
+
 1;
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index cb1d1a4..0f7a141 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -778,6 +778,32 @@ sub new
 	return $self;
 }
 
+package VS2015Solution;
+
+#
+# Package that encapsulates a Visual Studio 2015 solution file
+#
+
+use Carp;
+use strict;
+use warnings;
+use base qw(Solution);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{solutionFileVersion}        = '14.00';
+	$self->{vcver}                      = '14.00';
+	$self->{visualStudioName}           = 'Visual Studio 2015';
+	$self->{VisualStudioVersion}        = '14.0.24730.2';
+	$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
+
+	return $self;
+}
+
 sub GetAdditionalHeaders
 {
 	my ($self, $f) = @_;
diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm
index fee4684..4190ada 100644
--- a/src/tools/msvc/VSObjectFactory.pm
+++ b/src/tools/msvc/VSObjectFactory.pm
@@ -49,6 +49,10 @@ sub CreateSolution
 	{
 		return new VS2013Solution(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VS2015Solution(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -84,6 +88,10 @@ sub CreateProject
 	{
 		return new VC2013Project(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VC2015Project(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion
 sub _GetVisualStudioVersion
 {
 	my ($major, $minor) = @_;
-	if ($major > 12)
+	if ($major > 14)
 	{
 		carp
 "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
-		return '12.00';
+		return '14.00';
 	}
 	elsif ($major < 6)
 	{
-- 
2.7.2

0003-Fix-declaration-of-TIMEZONE_GLOBAL-and-TZNAME_GLOBAL.patchapplication/x-patch; name=0003-Fix-declaration-of-TIMEZONE_GLOBAL-and-TZNAME_GLOBAL.patchDownload
From 2aad0ede5275493be67ecdc3a158ce016d111555 Mon Sep 17 00:00:00 2001
From: John Doe <john@example.com>
Date: Fri, 4 Mar 2016 21:38:24 -0800
Subject: [PATCH 3/4] Fix declaration of TIMEZONE_GLOBAL and TZNAME_GLOBAL for
 WIN32

When compiling the code with WIN32, those two variables were declared
as timezone and tzname, while the objects present for MSVC are _timezone
and _tzname.
---
 src/include/port.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/include/port.h b/src/include/port.h
index cb13dd8..455f723 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -214,12 +214,12 @@ extern int	pgkill(int pid, int sig);
 extern int	pclose_check(FILE *stream);
 
 /* Global variable holding time zone information. */
-#ifndef __CYGWIN__
-#define TIMEZONE_GLOBAL timezone
-#define TZNAME_GLOBAL tzname
-#else
+#if defined(WIN32) || defined(__CYGWIN__)
 #define TIMEZONE_GLOBAL _timezone
 #define TZNAME_GLOBAL _tzname
+#else
+#define TIMEZONE_GLOBAL timezone
+#define TZNAME_GLOBAL tzname
 #endif
 
 #if defined(WIN32) || defined(__CYGWIN__)
-- 
2.7.2

0004-Fix-use-of-locales-for-VS-2015.patchapplication/x-patch; name=0004-Fix-use-of-locales-for-VS-2015.patchDownload
From f0e4f35d9ea383f0cac49f2ed8050c92969abe5c Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Fri, 4 Mar 2016 23:10:04 +0900
Subject: [PATCH 4/4] Fix use of locales for VS 2015

lc_codepage is a flag missing from locale.h, causing this code path
introduced in VS 2012 to fail. Perhaps there is a reason for this field
to have been clobbered, but let's fall back to the pre-VS-2012 code
parsing directly LC_TYPE to get the codepage wanted.
---
 src/port/chklocale.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..a7d88fb 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -203,7 +203,16 @@ win32_langinfo(const char *ctype)
 {
 	char	   *r = NULL;
 
-#if (_MSC_VER >= 1700)
+	/*
+	 * lc_codepage is correctly declared in Visual Studio 2012 and 2013.
+	 * However in VS 2015 this flag is missing from locale.h, visibly this
+	 * is an error of refactoring from Microsoft that is at the origin of
+	 * this missing field, causing a compilation failure in this code path.
+	 * Hence, it is more reliable to fall back to other code path grabbing
+	 * the codepage from the ctype name itself. If VS gets back this field
+	 * in the future, we may want to relax the use of _create_locale here.
+	 */
+#if (_MSC_VER >= 1700) && (_MSC_VER <= 1800)
 	_locale_t	loct = NULL;
 
 	loct = _create_locale(LC_CTYPE, ctype);
-- 
2.7.2

#12Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Michael Paquier (#11)
Re: VS 2015 support in src/tools/msvc

Michael Paquier wrote:

- 0001, as mentioned by Petr upthread, psed is removed from the core
distribution of Perl in 5.22, so when installing ActivePerl it is not
possible to create probes.h, and the code compilation would fail. I
bumped into that so here is a patch. What I am proposing here is to
replace psed by sed, sed being available in MSYS like bison and flex,
so when building using MSVC the environment to set up is normally
already good to go even with this additional dependency. Now, it is
important to mention that probes.h is not part of a source tarball. I
think that we would want probes.h to be part of a source tarball so as
it would be possible to compile the code on Windows using MSVC without
having to install MSYS. I haven't done that in this patch, thoughts on
the matter are welcome.

I think the path of least resistance is to change the sed script into a
Perl script. Should be fairly simple ...

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#13Michael Paquier
michael.paquier@gmail.com
In reply to: Alvaro Herrera (#12)
Re: VS 2015 support in src/tools/msvc

On Sat, Mar 5, 2016 at 12:08 AM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:

Michael Paquier wrote:

- 0001, as mentioned by Petr upthread, psed is removed from the core
distribution of Perl in 5.22, so when installing ActivePerl it is not
possible to create probes.h, and the code compilation would fail. I
bumped into that so here is a patch. What I am proposing here is to
replace psed by sed, sed being available in MSYS like bison and flex,
so when building using MSVC the environment to set up is normally
already good to go even with this additional dependency. Now, it is
important to mention that probes.h is not part of a source tarball. I
think that we would want probes.h to be part of a source tarball so as
it would be possible to compile the code on Windows using MSVC without
having to install MSYS. I haven't done that in this patch, thoughts on
the matter are welcome.

I think the path of least resistance is to change the sed script into a
Perl script. Should be fairly simple ...

Yes that's possible as well. It would be better to use the same
process for *nix platforms as well.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#14Craig Ringer
craig@2ndquadrant.com
In reply to: Michael Paquier (#11)
Re: VS 2015 support in src/tools/msvc

On 4 March 2016 at 22:23, Michael Paquier <michael.paquier@gmail.com> wrote:

On Fri, Mar 4, 2016 at 3:54 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

I still need to dig into that in more details. For the time being the
patch attached is useful IMO to plug in VS 2015 with the existing
infrastructure. So if anybody has a Windows environment, feel free to
play with it and dig into those problems. I'll update this thread once
I have a more advanced status.

OK, attached are a set of patches that allowed me to compile Postgres
using VS2015, in more details:
- 0001, as mentioned by Petr upthread, psed is removed from the core
distribution of Perl in 5.22, so when installing ActivePerl it is not
possible to create probes.h, and the code compilation would fail. I
bumped into that so here is a patch. What I am proposing here is to
replace psed by sed, sed being available in MSYS like bison and flex,
so when building using MSVC the environment to set up is normally
already good to go even with this additional dependency.

The assumption here is that we're using msys to provide bison and flex
(probably via msysgit), so adding sed isn't any more intrusive.

I think that's reasonable, but wanted to spell it out since right now msys
isn't actually a dependency of the MSVC builds, just a convenient way to
get some of the dependencies. This still adds a new dependency, but it's
one most people will have anyway. If they're using bison/flex from gnuwin32
or whatever instead they can get sed there too. So +1, sensible.

Now, it is
important to mention that probes.h is not part of a source tarball. I
think that we would want probes.h to be part of a source tarball so as
it would be possible to compile the code on Windows using MSVC without
having to install MSYS. I haven't done that in this patch, thoughts on
the matter are welcome.

That's consistent with how we include the generated scanner and lexer files
etc in the source tarball, so +1.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

#15Petr Jelinek
petr@2ndquadrant.com
In reply to: Michael Paquier (#11)
Re: VS 2015 support in src/tools/msvc

On 04/03/16 15:23, Michael Paquier wrote:

OK, attached are a set of patches that allowed me to compile Postgres
using VS2015, in more details:
- 0001, as mentioned by Petr upthread, psed is removed from the core
distribution of Perl in 5.22, so when installing ActivePerl it is not
possible to create probes.h, and the code compilation would fail. I
bumped into that so here is a patch. What I am proposing here is to
replace psed by sed, sed being available in MSYS like bison and flex,
so when building using MSVC the environment to set up is normally
already good to go even with this additional dependency. Now, it is
important to mention that probes.h is not part of a source tarball. I
think that we would want probes.h to be part of a source tarball so as
it would be possible to compile the code on Windows using MSVC without
having to install MSYS. I haven't done that in this patch, thoughts on
the matter are welcome.

I vote for just using sed considering we need flex and bison anyway.

- 0003, to address a compilation failure that I bumped into when
compiling ecpg. In src/port, TIMEZONE_GLOBAL and TZNAME_GLOBAL refer
to respectively timezone and tzname, however for win32, those should
be _timezone and _tzname. See here:
https://msdn.microsoft.com/en-us/library/htb3tdkc.aspx

Yep I hit that one as well, looks good.

- 0004, which is to address the problem of the missing lc_codepage
from locale.h in src/port/. I have been pondering about the use of
more fancy routines like GetLocaleInfoEx as mentioned by Petr
upthread. However, I think that we had better avoid any kind of
complication and just fall back to the old code path should _MSC_VER

= 1900. We could always reuse lc_codepage if it gets reintroduced in

a future version of VS.

Well I am worried that this way we might break existing installs which
means we can't backpatch this. The problem here is that the fallback
code does not support the <language>-<REGION> format which Microsoft
documents everywhere as recommended locale format. The good news is that
our own initdb won't auto-generate those when no locale was specified as
it uses the setlocale() which returns the legacy (and not recommended)
locale names and our fallback code can handle those. But manually set
locales can be a problem.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#16Michael Paquier
michael.paquier@gmail.com
In reply to: Petr Jelinek (#15)
Re: VS 2015 support in src/tools/msvc

On Sat, Mar 5, 2016 at 1:41 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

On 04/03/16 15:23, Michael Paquier wrote:

OK, attached are a set of patches that allowed me to compile Postgres
using VS2015, in more details:
- 0001, as mentioned by Petr upthread, psed is removed from the core
distribution of Perl in 5.22, so when installing ActivePerl it is not
possible to create probes.h, and the code compilation would fail. I
bumped into that so here is a patch. What I am proposing here is to
replace psed by sed, sed being available in MSYS like bison and flex,
so when building using MSVC the environment to set up is normally
already good to go even with this additional dependency. Now, it is
important to mention that probes.h is not part of a source tarball. I
think that we would want probes.h to be part of a source tarball so as
it would be possible to compile the code on Windows using MSVC without
having to install MSYS. I haven't done that in this patch, thoughts on
the matter are welcome.

I vote for just using sed considering we need flex and bison anyway.

OK cool, we could go with something else than sed to generate probes.h
but that seems sensible considering that this should definitely be
back-patched. Not sure what the others think about adding a new file
in the source tarball by default though.

- 0003, to address a compilation failure that I bumped into when
compiling ecpg. In src/port, TIMEZONE_GLOBAL and TZNAME_GLOBAL refer
to respectively timezone and tzname, however for win32, those should
be _timezone and _tzname. See here:
https://msdn.microsoft.com/en-us/library/htb3tdkc.aspx

Yep I hit that one as well, looks good.

MinGW would react to that correctly I think. If I look at
mingw/include/timezone.h, both timezone and _timezone are defined. I
would think that this is intentional to declare both there.

- 0004, which is to address the problem of the missing lc_codepage
from locale.h in src/port/. I have been pondering about the use of
more fancy routines like GetLocaleInfoEx as mentioned by Petr
upthread. However, I think that we had better avoid any kind of
complication and just fall back to the old code path should _MSC_VER

= 1900. We could always reuse lc_codepage if it gets reintroduced in

a future version of VS.

Well I am worried that this way we might break existing installs which means
we can't backpatch this. The problem here is that the fallback code does not
support the <language>-<REGION> format which Microsoft documents everywhere
as recommended locale format. The good news is that our own initdb won't
auto-generate those when no locale was specified as it uses the setlocale()
which returns the legacy (and not recommended) locale names and our fallback
code can handle those. But manually set locales can be a problem.

I am open to more fancy solutions if it is possible to get reliably
the codepage in a different way, but I am not sure this is worth the
complication. The pre-VS2012 code has been able to live with that.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#17Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Paquier (#16)
Re: VS 2015 support in src/tools/msvc

Michael Paquier <michael.paquier@gmail.com> writes:

On Sat, Mar 5, 2016 at 1:41 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

I vote for just using sed considering we need flex and bison anyway.

OK cool, we could go with something else than sed to generate probes.h
but that seems sensible considering that this should definitely be
back-patched. Not sure what the others think about adding a new file
in the source tarball by default though.

AFAIK, sed flex and bison originate from three separate source projects;
there is no reason to suppose that the presence of flex and bison on a
particular system guarantee the presence of sed. I thought the proposal
to get rid of the psed dependence in favor of some more perl code was
pretty sane.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#18Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#17)
Re: VS 2015 support in src/tools/msvc

On 03/05/2016 12:46 AM, Tom Lane wrote:

Michael Paquier <michael.paquier@gmail.com> writes:

On Sat, Mar 5, 2016 at 1:41 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

I vote for just using sed considering we need flex and bison anyway.

OK cool, we could go with something else than sed to generate probes.h
but that seems sensible considering that this should definitely be
back-patched. Not sure what the others think about adding a new file
in the source tarball by default though.

AFAIK, sed flex and bison originate from three separate source projects;
there is no reason to suppose that the presence of flex and bison on a
particular system guarantee the presence of sed. I thought the proposal
to get rid of the psed dependence in favor of some more perl code was
pretty sane.

Here is a translation into perl of the sed script, courtesy of the s2p
incarnation of psed:
<https://gist.github.com/adunstan/d61b1261a4b91496bdc6&gt; The sed script
appears to have been stable for a long time, so I don't think we need to
be too concerned about possibly maintaining two versions.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#19Michael Paquier
michael.paquier@gmail.com
In reply to: Andrew Dunstan (#18)
Re: VS 2015 support in src/tools/msvc

On Sat, Mar 5, 2016 at 11:34 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

Here is a translation into perl of the sed script, courtesy of the s2p
incarnation of psed: <https://gist.github.com/adunstan/d61b1261a4b91496bdc6&gt;
The sed script appears to have been stable for a long time, so I don't think
we need to be too concerned about possibly maintaining two versions.

That's 95% of the work already done, nice! If I finish wrapping up a
patch for this issue at least would you backpatch? It would be saner
to get rid of this dependency everywhere I think regarding compilation
with perl 5.22.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#20Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#19)
Re: VS 2015 support in src/tools/msvc

On 03/05/2016 01:31 PM, Michael Paquier wrote:

On Sat, Mar 5, 2016 at 11:34 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

Here is a translation into perl of the sed script, courtesy of the s2p
incarnation of psed: <https://gist.github.com/adunstan/d61b1261a4b91496bdc6&gt;
The sed script appears to have been stable for a long time, so I don't think
we need to be too concerned about possibly maintaining two versions.

That's 95% of the work already done, nice! If I finish wrapping up a
patch for this issue at least would you backpatch? It would be saner
to get rid of this dependency everywhere I think regarding compilation
with perl 5.22.

Sure.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#21Michael Paquier
michael.paquier@gmail.com
In reply to: Andrew Dunstan (#20)
1 attachment(s)
Re: VS 2015 support in src/tools/msvc

On Sun, Mar 6, 2016 at 5:55 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

On 03/05/2016 01:31 PM, Michael Paquier wrote:

On Sat, Mar 5, 2016 at 11:34 PM, Andrew Dunstan <andrew@dunslane.net>
wrote:

Here is a translation into perl of the sed script, courtesy of the s2p
incarnation of psed:
<https://gist.github.com/adunstan/d61b1261a4b91496bdc6&gt;
The sed script appears to have been stable for a long time, so I don't
think
we need to be too concerned about possibly maintaining two versions.

That's 95% of the work already done, nice! If I finish wrapping up a
patch for this issue at least would you backpatch? It would be saner
to get rid of this dependency everywhere I think regarding compilation
with perl 5.22.

Sure.

OK, so after some re-lecture of the script and perltidy-ing I finish
with the attached. How does that look?
--
Michael

Attachments:

psed-remove-v1.patchapplication/x-patch; name=psed-remove-v1.patchDownload
diff --git a/src/backend/utils/Gen_dummy_probes.pl b/src/backend/utils/Gen_dummy_probes.pl
new file mode 100644
index 0000000..30c6d65
--- /dev/null
+++ b/src/backend/utils/Gen_dummy_probes.pl
@@ -0,0 +1,247 @@
+#! /usr/bin/perl -w
+#-------------------------------------------------------------------------
+#
+# Gen_dummy_probes.pl
+#    Perl script that generates probes.h file when dtrace is not available
+#
+# Portions Copyright (c) 2008-2016, PostgreSQL Global Development Group
+#
+#
+# IDENTIFICATION
+#    src/backend/utils/Gen_dummy_probes.pl
+#
+#-------------------------------------------------------------------------
+
+$0 =~ s/^.*?(\w+)[\.\w+]*$/$1/;
+
+use strict;
+use Symbol;
+use vars qw{ $isEOF $Hold %wFiles @Q $CondReg
+  $doAutoPrint $doOpenWrite $doPrint };
+$doAutoPrint = 1;
+$doOpenWrite = 1;
+
+# prototypes
+sub openARGV();
+sub getsARGV(;\$);
+sub eofARGV();
+sub printQ();
+
+# Run: the sed loop reading input and applying the script
+#
+sub Run()
+{
+	my ($h, $icnt, $s, $n);
+
+	# hack (not unbreakable :-/) to avoid // matching an empty string
+	my $z = "\000";
+	$z =~ /$z/;
+
+	# Initialize.
+	openARGV();
+	$Hold    = '';
+	$CondReg = 0;
+	$doPrint = $doAutoPrint;
+  CYCLE:
+	while (getsARGV())
+	{
+		chomp();
+		$CondReg = 0;    # cleared on t
+	  BOS:;
+
+		# /^[ 	]*probe /!d
+		unless (m /^[ \t]*probe /s)
+		{
+			$doPrint = 0;
+			goto EOS;
+		}
+
+		# s/^[ 	]*probe \([^(]*\)\(.*\);/\1\2/
+		{
+			$s = s /^[ \t]*probe ([^(]*)(.*);/${1}${2}/s;
+			$CondReg ||= $s;
+		}
+
+		# s/__/_/g
+		{
+			$s = s /__/_/sg;
+			$CondReg ||= $s;
+		}
+
+		# y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
+		{ y{abcdefghijklmnopqrstuvwxyz}{ABCDEFGHIJKLMNOPQRSTUVWXYZ}; }
+
+		# s/^/#define TRACE_POSTGRESQL_/
+		{
+			$s = s /^/#define TRACE_POSTGRESQL_/s;
+			$CondReg ||= $s;
+		}
+
+		# s/([^,)]\{1,\})/(INT1)/
+		{
+			$s = s /\([^,)]+\)/(INT1)/s;
+			$CondReg ||= $s;
+		}
+
+		# s/([^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2)/
+		{
+			$s = s /\([^,)]+, [^,)]+\)/(INT1, INT2)/s;
+			$CondReg ||= $s;
+		}
+
+		# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3)/
+		{
+			$s = s /\([^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/s;
+			$CondReg ||= $s;
+		}
+
+		# P
+		{
+			if (/^(.*)/) { print $1, "\n"; }
+		}
+
+		# s/(.*$/_ENABLED() (0)/
+		{
+			$s = s /\(.*$/_ENABLED() (0)/s;
+			$CondReg ||= $s;
+		}
+	  EOS: if ($doPrint)
+		{
+			print $_, "\n";
+		}
+		else
+		{
+			$doPrint = $doAutoPrint;
+		}
+		printQ() if @Q;
+	}
+
+	exit(0);
+}
+Run();
+
+# openARGV: open 1st input file
+#
+sub openARGV()
+{
+	unshift(@ARGV, '-') unless @ARGV;
+	my $file = shift(@ARGV);
+	open(ARG, "<$file")
+	  || die("$0: can't open $file for reading ($!)\n");
+	$isEOF = 0;
+}
+
+# getsARGV: Read another input line into argument (default: $_).
+#           Move on to next input file, and reset EOF flag $isEOF.
+sub getsARGV(;\$)
+{
+	my $argref = @_ ? shift() : \$_;
+	while ($isEOF || !defined($$argref = <ARG>))
+	{
+		close(ARG);
+		return 0 unless @ARGV;
+		my $file = shift(@ARGV);
+		open(ARG, "<$file")
+		  || die("$0: can't open $file for reading ($!)\n");
+		$isEOF = 0;
+	}
+	1;
+}
+
+# eofARGV: end-of-file test
+#
+sub eofARGV()
+{
+	return @ARGV == 0 && ($isEOF = eof(ARG));
+}
+
+# makeHandle: Generates another file handle for some file (given by its path)
+#             to be written due to a w command or an s command's w flag.
+sub makeHandle($)
+{
+	my ($path) = @_;
+	my $handle;
+	if (!exists($wFiles{$path}) || $wFiles{$path} eq '')
+	{
+		$handle = $wFiles{$path} = gensym();
+		if ($doOpenWrite)
+		{
+			if (!open($handle, ">$path"))
+			{
+				die("$0: can't open $path for writing: ($!)\n");
+			}
+		}
+	}
+	else
+	{
+		$handle = $wFiles{$path};
+	}
+	return $handle;
+}
+
+# printQ: Print queued output which is either a string or a reference
+#         to a pathname.
+sub printQ()
+{
+	for my $q (@Q)
+	{
+		if (ref($q))
+		{
+			# flush open w files so that reading this file gets it all
+			if (exists($wFiles{$$q}) && $wFiles{$$q} ne '')
+			{
+				open($wFiles{$$q}, ">>$$q");
+			}
+
+			# copy file to stdout: slow, but safe
+			if (open(RF, "<$$q"))
+			{
+				while (defined(my $line = <RF>))
+				{
+					print $line;
+				}
+				close(RF);
+			}
+		}
+		else
+		{
+			print $q;
+		}
+	}
+	undef(@Q);
+}
diff --git a/src/backend/utils/Gen_dummy_probes.sed b/src/backend/utils/Gen_dummy_probes.sed
deleted file mode 100644
index 5a79fdb..0000000
--- a/src/backend/utils/Gen_dummy_probes.sed
+++ /dev/null
@@ -1,23 +0,0 @@
-#-------------------------------------------------------------------------
-# sed script to create dummy probes.h file when dtrace is not available
-#
-# Copyright (c) 2008-2016, PostgreSQL Global Development Group
-#
-# src/backend/utils/Gen_dummy_probes.sed
-#-------------------------------------------------------------------------
-
-/^[ 	]*probe /!d
-s/^[ 	]*probe \([^(]*\)\(.*\);/\1\2/
-s/__/_/g
-y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
-s/^/#define TRACE_POSTGRESQL_/
-s/([^,)]\{1,\})/(INT1)/
-s/([^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/
-P
-s/(.*$/_ENABLED() (0)/
diff --git a/src/backend/utils/Makefile b/src/backend/utils/Makefile
index 8374533..43fa255 100644
--- a/src/backend/utils/Makefile
+++ b/src/backend/utils/Makefile
@@ -30,7 +30,7 @@ errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl
 	$(PERL) $(srcdir)/generate-errcodes.pl $< > $@
 
 ifneq ($(enable_dtrace), yes)
-probes.h: Gen_dummy_probes.sed
+probes.h: Gen_dummy_probes.pl
 endif
 
 probes.h: probes.d
@@ -39,7 +39,7 @@ ifeq ($(enable_dtrace), yes)
 	sed -e 's/POSTGRESQL_/TRACE_POSTGRESQL_/g' $@.tmp >$@
 	rm $@.tmp
 else
-	sed -f $(srcdir)/Gen_dummy_probes.sed $< >$@
+	$(PERL) $(srcdir)/Gen_dummy_probes.pl $< > $@
 endif
 
 
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index c5a43f9..60bcd7e 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -313,7 +313,7 @@ s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY
 	{
 		print "Generating probes.h...\n";
 		system(
-'psed -f src/backend/utils/Gen_dummy_probes.sed src/backend/utils/probes.d > src/include/utils/probes.h'
+'perl src/backend/utils/Gen_dummy_probes.pl src/backend/utils/probes.d > src/include/utils/probes.h'
 		);
 	}
 
#22Michael Paquier
michael.paquier@gmail.com
In reply to: Michael Paquier (#21)
4 attachment(s)
Re: VS 2015 support in src/tools/msvc

On Mon, Mar 7, 2016 at 10:40 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Sun, Mar 6, 2016 at 5:55 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

On 03/05/2016 01:31 PM, Michael Paquier wrote:

On Sat, Mar 5, 2016 at 11:34 PM, Andrew Dunstan <andrew@dunslane.net>
wrote:

Here is a translation into perl of the sed script, courtesy of the s2p
incarnation of psed:
<https://gist.github.com/adunstan/d61b1261a4b91496bdc6&gt;
The sed script appears to have been stable for a long time, so I don't
think
we need to be too concerned about possibly maintaining two versions.

That's 95% of the work already done, nice! If I finish wrapping up a
patch for this issue at least would you backpatch? It would be saner
to get rid of this dependency everywhere I think regarding compilation
with perl 5.22.

Sure.

OK, so after some re-lecture of the script and perltidy-ing I finish
with the attached. How does that look?

Attached is a new set for the support of MS 2015 + the psed issue,
please use those ones for testing:
- 0001 is the replacement of psed by a dedicated perl script to
generate probes.h
- 0002 Fix of the declaration of TIMEZONE_GLOBAL and TZNAME_GLOBAL for WIN32
- 0003 addresses the issue with lc_codepage missing from _locale_t.
- 0004 adds support for MS2015 in src/tools/scripts/
Regards,
--
Michael

Attachments:

0001-Remove-dependency-to-psed-in-MSVC-scripts.patchapplication/x-patch; name=0001-Remove-dependency-to-psed-in-MSVC-scripts.patchDownload
From d7a100dae8816ff1287ae0eee2829d2b7ce6ef47 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Tue, 8 Mar 2016 22:18:16 +0900
Subject: [PATCH 1/4] Remove dependency to psed in MSVC scripts

psed has been removed from the core distribution of perl in 5.22, causing
the build of Postgres to fail in the case of MSVC on Windows should at
least this version of perl be used. This commit replaces the dependency
with psed by an equivalent perl script, the non-MSVC build use this script
as well instead of the former sed script when dtrace is not enabled in a
build.
---
 src/backend/utils/Gen_dummy_probes.pl  | 247 +++++++++++++++++++++++++++++++++
 src/backend/utils/Gen_dummy_probes.sed |  23 ---
 src/backend/utils/Makefile             |   4 +-
 src/tools/msvc/Solution.pm             |   2 +-
 4 files changed, 250 insertions(+), 26 deletions(-)
 create mode 100644 src/backend/utils/Gen_dummy_probes.pl
 delete mode 100644 src/backend/utils/Gen_dummy_probes.sed

diff --git a/src/backend/utils/Gen_dummy_probes.pl b/src/backend/utils/Gen_dummy_probes.pl
new file mode 100644
index 0000000..30c6d65
--- /dev/null
+++ b/src/backend/utils/Gen_dummy_probes.pl
@@ -0,0 +1,247 @@
+#! /usr/bin/perl -w
+#-------------------------------------------------------------------------
+#
+# Gen_dummy_probes.pl
+#    Perl script that generates probes.h file when dtrace is not available
+#
+# Portions Copyright (c) 2008-2016, PostgreSQL Global Development Group
+#
+#
+# IDENTIFICATION
+#    src/backend/utils/Gen_dummy_probes.pl
+#
+#-------------------------------------------------------------------------
+
+$0 =~ s/^.*?(\w+)[\.\w+]*$/$1/;
+
+use strict;
+use Symbol;
+use vars qw{ $isEOF $Hold %wFiles @Q $CondReg
+  $doAutoPrint $doOpenWrite $doPrint };
+$doAutoPrint = 1;
+$doOpenWrite = 1;
+
+# prototypes
+sub openARGV();
+sub getsARGV(;\$);
+sub eofARGV();
+sub printQ();
+
+# Run: the sed loop reading input and applying the script
+#
+sub Run()
+{
+	my ($h, $icnt, $s, $n);
+
+	# hack (not unbreakable :-/) to avoid // matching an empty string
+	my $z = "\000";
+	$z =~ /$z/;
+
+	# Initialize.
+	openARGV();
+	$Hold    = '';
+	$CondReg = 0;
+	$doPrint = $doAutoPrint;
+  CYCLE:
+	while (getsARGV())
+	{
+		chomp();
+		$CondReg = 0;    # cleared on t
+	  BOS:;
+
+		# /^[ 	]*probe /!d
+		unless (m /^[ \t]*probe /s)
+		{
+			$doPrint = 0;
+			goto EOS;
+		}
+
+		# s/^[ 	]*probe \([^(]*\)\(.*\);/\1\2/
+		{
+			$s = s /^[ \t]*probe ([^(]*)(.*);/${1}${2}/s;
+			$CondReg ||= $s;
+		}
+
+		# s/__/_/g
+		{
+			$s = s /__/_/sg;
+			$CondReg ||= $s;
+		}
+
+		# y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
+		{ y{abcdefghijklmnopqrstuvwxyz}{ABCDEFGHIJKLMNOPQRSTUVWXYZ}; }
+
+		# s/^/#define TRACE_POSTGRESQL_/
+		{
+			$s = s /^/#define TRACE_POSTGRESQL_/s;
+			$CondReg ||= $s;
+		}
+
+		# s/([^,)]\{1,\})/(INT1)/
+		{
+			$s = s /\([^,)]+\)/(INT1)/s;
+			$CondReg ||= $s;
+		}
+
+		# s/([^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2)/
+		{
+			$s = s /\([^,)]+, [^,)]+\)/(INT1, INT2)/s;
+			$CondReg ||= $s;
+		}
+
+		# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3)/
+		{
+			$s = s /\([^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/s;
+			$CondReg ||= $s;
+		}
+
+		# P
+		{
+			if (/^(.*)/) { print $1, "\n"; }
+		}
+
+		# s/(.*$/_ENABLED() (0)/
+		{
+			$s = s /\(.*$/_ENABLED() (0)/s;
+			$CondReg ||= $s;
+		}
+	  EOS: if ($doPrint)
+		{
+			print $_, "\n";
+		}
+		else
+		{
+			$doPrint = $doAutoPrint;
+		}
+		printQ() if @Q;
+	}
+
+	exit(0);
+}
+Run();
+
+# openARGV: open 1st input file
+#
+sub openARGV()
+{
+	unshift(@ARGV, '-') unless @ARGV;
+	my $file = shift(@ARGV);
+	open(ARG, "<$file")
+	  || die("$0: can't open $file for reading ($!)\n");
+	$isEOF = 0;
+}
+
+# getsARGV: Read another input line into argument (default: $_).
+#           Move on to next input file, and reset EOF flag $isEOF.
+sub getsARGV(;\$)
+{
+	my $argref = @_ ? shift() : \$_;
+	while ($isEOF || !defined($$argref = <ARG>))
+	{
+		close(ARG);
+		return 0 unless @ARGV;
+		my $file = shift(@ARGV);
+		open(ARG, "<$file")
+		  || die("$0: can't open $file for reading ($!)\n");
+		$isEOF = 0;
+	}
+	1;
+}
+
+# eofARGV: end-of-file test
+#
+sub eofARGV()
+{
+	return @ARGV == 0 && ($isEOF = eof(ARG));
+}
+
+# makeHandle: Generates another file handle for some file (given by its path)
+#             to be written due to a w command or an s command's w flag.
+sub makeHandle($)
+{
+	my ($path) = @_;
+	my $handle;
+	if (!exists($wFiles{$path}) || $wFiles{$path} eq '')
+	{
+		$handle = $wFiles{$path} = gensym();
+		if ($doOpenWrite)
+		{
+			if (!open($handle, ">$path"))
+			{
+				die("$0: can't open $path for writing: ($!)\n");
+			}
+		}
+	}
+	else
+	{
+		$handle = $wFiles{$path};
+	}
+	return $handle;
+}
+
+# printQ: Print queued output which is either a string or a reference
+#         to a pathname.
+sub printQ()
+{
+	for my $q (@Q)
+	{
+		if (ref($q))
+		{
+			# flush open w files so that reading this file gets it all
+			if (exists($wFiles{$$q}) && $wFiles{$$q} ne '')
+			{
+				open($wFiles{$$q}, ">>$$q");
+			}
+
+			# copy file to stdout: slow, but safe
+			if (open(RF, "<$$q"))
+			{
+				while (defined(my $line = <RF>))
+				{
+					print $line;
+				}
+				close(RF);
+			}
+		}
+		else
+		{
+			print $q;
+		}
+	}
+	undef(@Q);
+}
diff --git a/src/backend/utils/Gen_dummy_probes.sed b/src/backend/utils/Gen_dummy_probes.sed
deleted file mode 100644
index 5a79fdb..0000000
--- a/src/backend/utils/Gen_dummy_probes.sed
+++ /dev/null
@@ -1,23 +0,0 @@
-#-------------------------------------------------------------------------
-# sed script to create dummy probes.h file when dtrace is not available
-#
-# Copyright (c) 2008-2016, PostgreSQL Global Development Group
-#
-# src/backend/utils/Gen_dummy_probes.sed
-#-------------------------------------------------------------------------
-
-/^[ 	]*probe /!d
-s/^[ 	]*probe \([^(]*\)\(.*\);/\1\2/
-s/__/_/g
-y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
-s/^/#define TRACE_POSTGRESQL_/
-s/([^,)]\{1,\})/(INT1)/
-s/([^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/
-P
-s/(.*$/_ENABLED() (0)/
diff --git a/src/backend/utils/Makefile b/src/backend/utils/Makefile
index 8374533..43fa255 100644
--- a/src/backend/utils/Makefile
+++ b/src/backend/utils/Makefile
@@ -30,7 +30,7 @@ errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl
 	$(PERL) $(srcdir)/generate-errcodes.pl $< > $@
 
 ifneq ($(enable_dtrace), yes)
-probes.h: Gen_dummy_probes.sed
+probes.h: Gen_dummy_probes.pl
 endif
 
 probes.h: probes.d
@@ -39,7 +39,7 @@ ifeq ($(enable_dtrace), yes)
 	sed -e 's/POSTGRESQL_/TRACE_POSTGRESQL_/g' $@.tmp >$@
 	rm $@.tmp
 else
-	sed -f $(srcdir)/Gen_dummy_probes.sed $< >$@
+	$(PERL) $(srcdir)/Gen_dummy_probes.pl $< > $@
 endif
 
 
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index c5a43f9..60bcd7e 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -313,7 +313,7 @@ s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY
 	{
 		print "Generating probes.h...\n";
 		system(
-'psed -f src/backend/utils/Gen_dummy_probes.sed src/backend/utils/probes.d > src/include/utils/probes.h'
+'perl src/backend/utils/Gen_dummy_probes.pl src/backend/utils/probes.d > src/include/utils/probes.h'
 		);
 	}
 
-- 
2.7.2

0002-Fix-declaration-of-TIMEZONE_GLOBAL-and-TZNAME_GLOBAL.patchapplication/x-patch; name=0002-Fix-declaration-of-TIMEZONE_GLOBAL-and-TZNAME_GLOBAL.patchDownload
From 5cc3b19e32e7d975d75b301c2b289de9a6655c78 Mon Sep 17 00:00:00 2001
From: John Doe <john@example.com>
Date: Fri, 4 Mar 2016 21:38:24 -0800
Subject: [PATCH 2/4] Fix declaration of TIMEZONE_GLOBAL and TZNAME_GLOBAL for
 WIN32

When compiling the code with WIN32, those two variables were declared
as timezone and tzname, while the objects present for MSVC are _timezone
and _tzname.
---
 src/include/port.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/include/port.h b/src/include/port.h
index cb13dd8..455f723 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -214,12 +214,12 @@ extern int	pgkill(int pid, int sig);
 extern int	pclose_check(FILE *stream);
 
 /* Global variable holding time zone information. */
-#ifndef __CYGWIN__
-#define TIMEZONE_GLOBAL timezone
-#define TZNAME_GLOBAL tzname
-#else
+#if defined(WIN32) || defined(__CYGWIN__)
 #define TIMEZONE_GLOBAL _timezone
 #define TZNAME_GLOBAL _tzname
+#else
+#define TIMEZONE_GLOBAL timezone
+#define TZNAME_GLOBAL tzname
 #endif
 
 #if defined(WIN32) || defined(__CYGWIN__)
-- 
2.7.2

0003-Fix-use-of-locales-for-VS-2015.patchapplication/x-patch; name=0003-Fix-use-of-locales-for-VS-2015.patchDownload
From 73c39b3ab63bead87b77a02eed3f01194a95bb50 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Fri, 4 Mar 2016 23:10:04 +0900
Subject: [PATCH 3/4] Fix use of locales for VS 2015

lc_codepage is a flag missing from locale.h, causing this code path
introduced in VS 2012 to fail. Perhaps there is a reason for this field
to have been clobbered, but let's fall back to the pre-VS-2012 code
parsing directly LC_TYPE to get the codepage wanted.
---
 src/port/chklocale.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..a7d88fb 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -203,7 +203,16 @@ win32_langinfo(const char *ctype)
 {
 	char	   *r = NULL;
 
-#if (_MSC_VER >= 1700)
+	/*
+	 * lc_codepage is correctly declared in Visual Studio 2012 and 2013.
+	 * However in VS 2015 this flag is missing from locale.h, visibly this
+	 * is an error of refactoring from Microsoft that is at the origin of
+	 * this missing field, causing a compilation failure in this code path.
+	 * Hence, it is more reliable to fall back to other code path grabbing
+	 * the codepage from the ctype name itself. If VS gets back this field
+	 * in the future, we may want to relax the use of _create_locale here.
+	 */
+#if (_MSC_VER >= 1700) && (_MSC_VER <= 1800)
 	_locale_t	loct = NULL;
 
 	loct = _create_locale(LC_CTYPE, ctype);
-- 
2.7.2

0004-Add-support-for-VS-2015-in-MSVC-scripts.patchapplication/x-patch; name=0004-Add-support-for-VS-2015-in-MSVC-scripts.patchDownload
From 5a0d172b0679b426230174fc8452dd775fd0f226 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Fri, 4 Mar 2016 15:25:55 +0900
Subject: [PATCH 4/4] Add support for VS 2015 in MSVC scripts

One can use that to compile with the latest version of Visual Studio
on Windows.
---
 doc/src/sgml/install-windows.sgml |  8 ++++----
 src/tools/msvc/MSBuildProject.pm  | 23 +++++++++++++++++++++++
 src/tools/msvc/Solution.pm        | 26 ++++++++++++++++++++++++++
 src/tools/msvc/VSObjectFactory.pm | 12 ++++++++++--
 4 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index f08cca7..148180b 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -19,10 +19,10 @@
  <para>
   There are several different ways of building PostgreSQL on
   <productname>Windows</productname>. The simplest way to build with
-  Microsoft tools is to install <productname>Visual Studio Express 2013
+  Microsoft tools is to install <productname>Visual Studio Express 2015
   for Windows Desktop</productname> and use the included
   compiler. It is also possible to build with the full
-  <productname>Microsoft Visual C++ 2005 to 2013</productname>.
+  <productname>Microsoft Visual C++ 2005 to 2015</productname>.
   In some cases that requires the installation of the
   <productname>Windows SDK</productname> in addition to the compiler.
  </para>
@@ -77,7 +77,7 @@
   <productname>Visual Studio Express</productname> or some versions of the
   <productname>Microsoft Windows SDK</productname>. If you do not already have a
   <productname>Visual Studio</productname> environment set up, the easiest
-  ways are to use the compilers from <productname>Visual Studio Express 2013
+  ways are to use the compilers from <productname>Visual Studio Express 2015
   for Windows Desktop</productname> or those in the <productname>Windows SDK
   7.1</productname>, which are both free downloads from Microsoft.
  </para>
@@ -85,7 +85,7 @@
  <para>
   PostgreSQL is known to support compilation using the compilers shipped with
   <productname>Visual Studio 2005</productname> to
-  <productname>Visual Studio 2013</productname> (including Express editions),
+  <productname>Visual Studio 2015</productname> (including Express editions),
   as well as standalone Windows SDK releases 6.0 to 7.1.
   64-bit PostgreSQL builds are only supported with
   <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 3d60b64..d7638b4 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -465,4 +465,27 @@ sub new
 	return $self;
 }
 
+package VC2015Project;
+
+#
+# Package that encapsulates a Visual C++ 2015 project file
+#
+
+use strict;
+use warnings;
+use base qw(VC2012Project);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{vcver}           = '14.00';
+	$self->{PlatformToolset} = 'v140';
+	$self->{ToolsVersion}    = '14.0';
+
+	return $self;
+}
+
 1;
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 60bcd7e..1181a03 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -779,6 +779,32 @@ sub new
 	return $self;
 }
 
+package VS2015Solution;
+
+#
+# Package that encapsulates a Visual Studio 2015 solution file
+#
+
+use Carp;
+use strict;
+use warnings;
+use base qw(Solution);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{solutionFileVersion}        = '14.00';
+	$self->{vcver}                      = '14.00';
+	$self->{visualStudioName}           = 'Visual Studio 2015';
+	$self->{VisualStudioVersion}        = '14.0.24730.2';
+	$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
+
+	return $self;
+}
+
 sub GetAdditionalHeaders
 {
 	my ($self, $f) = @_;
diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm
index fee4684..4190ada 100644
--- a/src/tools/msvc/VSObjectFactory.pm
+++ b/src/tools/msvc/VSObjectFactory.pm
@@ -49,6 +49,10 @@ sub CreateSolution
 	{
 		return new VS2013Solution(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VS2015Solution(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -84,6 +88,10 @@ sub CreateProject
 	{
 		return new VC2013Project(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VC2015Project(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion
 sub _GetVisualStudioVersion
 {
 	my ($major, $minor) = @_;
-	if ($major > 12)
+	if ($major > 14)
 	{
 		carp
 "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
-		return '12.00';
+		return '14.00';
 	}
 	elsif ($major < 6)
 	{
-- 
2.7.2

#23Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#22)
Re: VS 2015 support in src/tools/msvc

On 03/08/2016 08:32 AM, Michael Paquier wrote:

On Mon, Mar 7, 2016 at 10:40 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Sun, Mar 6, 2016 at 5:55 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

On 03/05/2016 01:31 PM, Michael Paquier wrote:

On Sat, Mar 5, 2016 at 11:34 PM, Andrew Dunstan <andrew@dunslane.net>
wrote:

Here is a translation into perl of the sed script, courtesy of the s2p
incarnation of psed:
<https://gist.github.com/adunstan/d61b1261a4b91496bdc6&gt;
The sed script appears to have been stable for a long time, so I don't
think
we need to be too concerned about possibly maintaining two versions.

That's 95% of the work already done, nice! If I finish wrapping up a
patch for this issue at least would you backpatch? It would be saner
to get rid of this dependency everywhere I think regarding compilation
with perl 5.22.

Sure.

OK, so after some re-lecture of the script and perltidy-ing I finish
with the attached. How does that look?

Attached is a new set for the support of MS 2015 + the psed issue,
please use those ones for testing:
- 0001 is the replacement of psed by a dedicated perl script to
generate probes.h
- 0002 Fix of the declaration of TIMEZONE_GLOBAL and TZNAME_GLOBAL for WIN32
- 0003 addresses the issue with lc_codepage missing from _locale_t.
- 0004 adds support for MS2015 in src/tools/scripts/

Thanks for doing this work.

Do we already have a hard dependency on perl for all non-Windows builds?
I know it's been discussed but I don't recall. If so, back to what version?

The comment in the codepage patch is a bit unclear. Can you reword it a bit?

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#24Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#23)
Re: VS 2015 support in src/tools/msvc

Andrew Dunstan <andrew@dunslane.net> writes:

Do we already have a hard dependency on perl for all non-Windows builds?
I know it's been discussed but I don't recall. If so, back to what version?

I think the policy is we require perl for building from a git pull,
but not for building from a tarball. Thus, any files that perl is used
to produce have to be shipped in tarballs.

However, there definitely *is* a hard requirement on perl for Windows
builds, even from tarballs, and I thought this patch was only about
the Windows build?

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#25Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#24)
Re: VS 2015 support in src/tools/msvc

On 03/08/2016 10:43 AM, Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

Do we already have a hard dependency on perl for all non-Windows builds?
I know it's been discussed but I don't recall. If so, back to what version?

I think the policy is we require perl for building from a git pull,
but not for building from a tarball. Thus, any files that perl is used
to produce have to be shipped in tarballs.

However, there definitely *is* a hard requirement on perl for Windows
builds, even from tarballs, and I thought this patch was only about
the Windows build?

Michael's patch proposes to replace the use of sed to generate probes.h
with the perl equivalent everywhere. That has the advantage that we keep
to one script to generate probes.h, but it does impose a perl dependency.

We could get around that by shipping probes.h in tarballs, which seems
like a perfectly reasonable thing to do. If we don't like that we can
fall back to using the perl script just for MSVC builds.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#26Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#25)
Re: VS 2015 support in src/tools/msvc

Andrew Dunstan <andrew@dunslane.net> writes:

On 03/08/2016 10:43 AM, Tom Lane wrote:

However, there definitely *is* a hard requirement on perl for Windows
builds, even from tarballs, and I thought this patch was only about
the Windows build?

Michael's patch proposes to replace the use of sed to generate probes.h
with the perl equivalent everywhere. That has the advantage that we keep
to one script to generate probes.h, but it does impose a perl dependency.

Meh.

We could get around that by shipping probes.h in tarballs, which seems
like a perfectly reasonable thing to do.

Well, it'd be messier than you think, because you could not just ship
a dummy probes.h, or make would think it was up to date and not replace
it even in a dtrace-using build. You'd have to ship it as something
like "probes.dummy.h" and cp it into place at build time.

On the whole, I'd rather that this patch left the non-Windows side alone.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#27Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#26)
Re: VS 2015 support in src/tools/msvc

On 03/08/2016 11:17 AM, Tom Lane wrote:

On the whole, I'd rather that this patch left the non-Windows side alone.

OK, that's why I raised the issue. We'll do it that way.

As I noted upthread, the sed script has been very stable so the overhead
of having to maintain two scripts is pretty minimal.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#28Michael Paquier
michael.paquier@gmail.com
In reply to: Andrew Dunstan (#25)
4 attachment(s)
Re: VS 2015 support in src/tools/msvc

On Wed, Mar 9, 2016 at 1:07 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

Michael's patch proposes to replace the use of sed to generate probes.h with
the perl equivalent everywhere. That has the advantage that we keep to one
script to generate probes.h, but it does impose a perl dependency.

Good point. It did not occur to me that this would bring a hard
dependency for non-Windows builds. Let's keep both scripts then. The
attached is changed to do so.
--
Michael

Attachments:

0001-Remove-dependency-to-psed-in-MSVC-scripts.patchapplication/x-patch; name=0001-Remove-dependency-to-psed-in-MSVC-scripts.patchDownload
From d7a100dae8816ff1287ae0eee2829d2b7ce6ef47 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Tue, 8 Mar 2016 22:18:16 +0900
Subject: [PATCH 1/4] Remove dependency to psed in MSVC scripts

psed has been removed from the core distribution of perl in 5.22, causing
the build of Postgres to fail in the case of MSVC on Windows should at
least this version of perl be used. This commit replaces the dependency
with psed by an equivalent perl script, the non-MSVC build use this script
as well instead of the former sed script when dtrace is not enabled in a
build.
---
 src/backend/utils/Gen_dummy_probes.pl  | 247 +++++++++++++++++++++++++++++++++
 src/backend/utils/Gen_dummy_probes.sed |  23 ---
 src/backend/utils/Makefile             |   4 +-
 src/tools/msvc/Solution.pm             |   2 +-
 4 files changed, 250 insertions(+), 26 deletions(-)
 create mode 100644 src/backend/utils/Gen_dummy_probes.pl
 delete mode 100644 src/backend/utils/Gen_dummy_probes.sed

diff --git a/src/backend/utils/Gen_dummy_probes.pl b/src/backend/utils/Gen_dummy_probes.pl
new file mode 100644
index 0000000..30c6d65
--- /dev/null
+++ b/src/backend/utils/Gen_dummy_probes.pl
@@ -0,0 +1,247 @@
+#! /usr/bin/perl -w
+#-------------------------------------------------------------------------
+#
+# Gen_dummy_probes.pl
+#    Perl script that generates probes.h file when dtrace is not available
+#
+# Portions Copyright (c) 2008-2016, PostgreSQL Global Development Group
+#
+#
+# IDENTIFICATION
+#    src/backend/utils/Gen_dummy_probes.pl
+#
+#-------------------------------------------------------------------------
+
+$0 =~ s/^.*?(\w+)[\.\w+]*$/$1/;
+
+use strict;
+use Symbol;
+use vars qw{ $isEOF $Hold %wFiles @Q $CondReg
+  $doAutoPrint $doOpenWrite $doPrint };
+$doAutoPrint = 1;
+$doOpenWrite = 1;
+
+# prototypes
+sub openARGV();
+sub getsARGV(;\$);
+sub eofARGV();
+sub printQ();
+
+# Run: the sed loop reading input and applying the script
+#
+sub Run()
+{
+	my ($h, $icnt, $s, $n);
+
+	# hack (not unbreakable :-/) to avoid // matching an empty string
+	my $z = "\000";
+	$z =~ /$z/;
+
+	# Initialize.
+	openARGV();
+	$Hold    = '';
+	$CondReg = 0;
+	$doPrint = $doAutoPrint;
+  CYCLE:
+	while (getsARGV())
+	{
+		chomp();
+		$CondReg = 0;    # cleared on t
+	  BOS:;
+
+		# /^[ 	]*probe /!d
+		unless (m /^[ \t]*probe /s)
+		{
+			$doPrint = 0;
+			goto EOS;
+		}
+
+		# s/^[ 	]*probe \([^(]*\)\(.*\);/\1\2/
+		{
+			$s = s /^[ \t]*probe ([^(]*)(.*);/${1}${2}/s;
+			$CondReg ||= $s;
+		}
+
+		# s/__/_/g
+		{
+			$s = s /__/_/sg;
+			$CondReg ||= $s;
+		}
+
+		# y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
+		{ y{abcdefghijklmnopqrstuvwxyz}{ABCDEFGHIJKLMNOPQRSTUVWXYZ}; }
+
+		# s/^/#define TRACE_POSTGRESQL_/
+		{
+			$s = s /^/#define TRACE_POSTGRESQL_/s;
+			$CondReg ||= $s;
+		}
+
+		# s/([^,)]\{1,\})/(INT1)/
+		{
+			$s = s /\([^,)]+\)/(INT1)/s;
+			$CondReg ||= $s;
+		}
+
+		# s/([^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2)/
+		{
+			$s = s /\([^,)]+, [^,)]+\)/(INT1, INT2)/s;
+			$CondReg ||= $s;
+		}
+
+		# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3)/
+		{
+			$s = s /\([^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/s;
+			$CondReg ||= $s;
+		}
+
+# s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/
+		{
+			$s =
+s /\([^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+, [^,)]+\)/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/s;
+			$CondReg ||= $s;
+		}
+
+		# P
+		{
+			if (/^(.*)/) { print $1, "\n"; }
+		}
+
+		# s/(.*$/_ENABLED() (0)/
+		{
+			$s = s /\(.*$/_ENABLED() (0)/s;
+			$CondReg ||= $s;
+		}
+	  EOS: if ($doPrint)
+		{
+			print $_, "\n";
+		}
+		else
+		{
+			$doPrint = $doAutoPrint;
+		}
+		printQ() if @Q;
+	}
+
+	exit(0);
+}
+Run();
+
+# openARGV: open 1st input file
+#
+sub openARGV()
+{
+	unshift(@ARGV, '-') unless @ARGV;
+	my $file = shift(@ARGV);
+	open(ARG, "<$file")
+	  || die("$0: can't open $file for reading ($!)\n");
+	$isEOF = 0;
+}
+
+# getsARGV: Read another input line into argument (default: $_).
+#           Move on to next input file, and reset EOF flag $isEOF.
+sub getsARGV(;\$)
+{
+	my $argref = @_ ? shift() : \$_;
+	while ($isEOF || !defined($$argref = <ARG>))
+	{
+		close(ARG);
+		return 0 unless @ARGV;
+		my $file = shift(@ARGV);
+		open(ARG, "<$file")
+		  || die("$0: can't open $file for reading ($!)\n");
+		$isEOF = 0;
+	}
+	1;
+}
+
+# eofARGV: end-of-file test
+#
+sub eofARGV()
+{
+	return @ARGV == 0 && ($isEOF = eof(ARG));
+}
+
+# makeHandle: Generates another file handle for some file (given by its path)
+#             to be written due to a w command or an s command's w flag.
+sub makeHandle($)
+{
+	my ($path) = @_;
+	my $handle;
+	if (!exists($wFiles{$path}) || $wFiles{$path} eq '')
+	{
+		$handle = $wFiles{$path} = gensym();
+		if ($doOpenWrite)
+		{
+			if (!open($handle, ">$path"))
+			{
+				die("$0: can't open $path for writing: ($!)\n");
+			}
+		}
+	}
+	else
+	{
+		$handle = $wFiles{$path};
+	}
+	return $handle;
+}
+
+# printQ: Print queued output which is either a string or a reference
+#         to a pathname.
+sub printQ()
+{
+	for my $q (@Q)
+	{
+		if (ref($q))
+		{
+			# flush open w files so that reading this file gets it all
+			if (exists($wFiles{$$q}) && $wFiles{$$q} ne '')
+			{
+				open($wFiles{$$q}, ">>$$q");
+			}
+
+			# copy file to stdout: slow, but safe
+			if (open(RF, "<$$q"))
+			{
+				while (defined(my $line = <RF>))
+				{
+					print $line;
+				}
+				close(RF);
+			}
+		}
+		else
+		{
+			print $q;
+		}
+	}
+	undef(@Q);
+}
diff --git a/src/backend/utils/Gen_dummy_probes.sed b/src/backend/utils/Gen_dummy_probes.sed
deleted file mode 100644
index 5a79fdb..0000000
--- a/src/backend/utils/Gen_dummy_probes.sed
+++ /dev/null
@@ -1,23 +0,0 @@
-#-------------------------------------------------------------------------
-# sed script to create dummy probes.h file when dtrace is not available
-#
-# Copyright (c) 2008-2016, PostgreSQL Global Development Group
-#
-# src/backend/utils/Gen_dummy_probes.sed
-#-------------------------------------------------------------------------
-
-/^[ 	]*probe /!d
-s/^[ 	]*probe \([^(]*\)\(.*\);/\1\2/
-s/__/_/g
-y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
-s/^/#define TRACE_POSTGRESQL_/
-s/([^,)]\{1,\})/(INT1)/
-s/([^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7)/
-s/([^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\}, [^,)]\{1,\})/(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8)/
-P
-s/(.*$/_ENABLED() (0)/
diff --git a/src/backend/utils/Makefile b/src/backend/utils/Makefile
index 8374533..43fa255 100644
--- a/src/backend/utils/Makefile
+++ b/src/backend/utils/Makefile
@@ -30,7 +30,7 @@ errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl
 	$(PERL) $(srcdir)/generate-errcodes.pl $< > $@
 
 ifneq ($(enable_dtrace), yes)
-probes.h: Gen_dummy_probes.sed
+probes.h: Gen_dummy_probes.pl
 endif
 
 probes.h: probes.d
@@ -39,7 +39,7 @@ ifeq ($(enable_dtrace), yes)
 	sed -e 's/POSTGRESQL_/TRACE_POSTGRESQL_/g' $@.tmp >$@
 	rm $@.tmp
 else
-	sed -f $(srcdir)/Gen_dummy_probes.sed $< >$@
+	$(PERL) $(srcdir)/Gen_dummy_probes.pl $< > $@
 endif
 
 
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index c5a43f9..60bcd7e 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -313,7 +313,7 @@ s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY
 	{
 		print "Generating probes.h...\n";
 		system(
-'psed -f src/backend/utils/Gen_dummy_probes.sed src/backend/utils/probes.d > src/include/utils/probes.h'
+'perl src/backend/utils/Gen_dummy_probes.pl src/backend/utils/probes.d > src/include/utils/probes.h'
 		);
 	}
 
-- 
2.7.2

0002-Fix-declaration-of-TIMEZONE_GLOBAL-and-TZNAME_GLOBAL.patchapplication/x-patch; name=0002-Fix-declaration-of-TIMEZONE_GLOBAL-and-TZNAME_GLOBAL.patchDownload
From 5cc3b19e32e7d975d75b301c2b289de9a6655c78 Mon Sep 17 00:00:00 2001
From: John Doe <john@example.com>
Date: Fri, 4 Mar 2016 21:38:24 -0800
Subject: [PATCH 2/4] Fix declaration of TIMEZONE_GLOBAL and TZNAME_GLOBAL for
 WIN32

When compiling the code with WIN32, those two variables were declared
as timezone and tzname, while the objects present for MSVC are _timezone
and _tzname.
---
 src/include/port.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/include/port.h b/src/include/port.h
index cb13dd8..455f723 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -214,12 +214,12 @@ extern int	pgkill(int pid, int sig);
 extern int	pclose_check(FILE *stream);
 
 /* Global variable holding time zone information. */
-#ifndef __CYGWIN__
-#define TIMEZONE_GLOBAL timezone
-#define TZNAME_GLOBAL tzname
-#else
+#if defined(WIN32) || defined(__CYGWIN__)
 #define TIMEZONE_GLOBAL _timezone
 #define TZNAME_GLOBAL _tzname
+#else
+#define TIMEZONE_GLOBAL timezone
+#define TZNAME_GLOBAL tzname
 #endif
 
 #if defined(WIN32) || defined(__CYGWIN__)
-- 
2.7.2

0003-Fix-use-of-locales-for-VS-2015.patchapplication/x-patch; name=0003-Fix-use-of-locales-for-VS-2015.patchDownload
From 73c39b3ab63bead87b77a02eed3f01194a95bb50 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Fri, 4 Mar 2016 23:10:04 +0900
Subject: [PATCH 3/4] Fix use of locales for VS 2015

lc_codepage is a flag missing from locale.h, causing this code path
introduced in VS 2012 to fail. Perhaps there is a reason for this field
to have been clobbered, but let's fall back to the pre-VS-2012 code
parsing directly LC_TYPE to get the codepage wanted.
---
 src/port/chklocale.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..a7d88fb 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -203,7 +203,16 @@ win32_langinfo(const char *ctype)
 {
 	char	   *r = NULL;
 
-#if (_MSC_VER >= 1700)
+	/*
+	 * lc_codepage is correctly declared in Visual Studio 2012 and 2013.
+	 * However in VS 2015 this flag is missing from locale.h, visibly this
+	 * is an error of refactoring from Microsoft that is at the origin of
+	 * this missing field, causing a compilation failure in this code path.
+	 * Hence, it is more reliable to fall back to other code path grabbing
+	 * the codepage from the ctype name itself. If VS gets back this field
+	 * in the future, we may want to relax the use of _create_locale here.
+	 */
+#if (_MSC_VER >= 1700) && (_MSC_VER <= 1800)
 	_locale_t	loct = NULL;
 
 	loct = _create_locale(LC_CTYPE, ctype);
-- 
2.7.2

0004-Add-support-for-VS-2015-in-MSVC-scripts.patchapplication/x-patch; name=0004-Add-support-for-VS-2015-in-MSVC-scripts.patchDownload
From 5a0d172b0679b426230174fc8452dd775fd0f226 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Fri, 4 Mar 2016 15:25:55 +0900
Subject: [PATCH 4/4] Add support for VS 2015 in MSVC scripts

One can use that to compile with the latest version of Visual Studio
on Windows.
---
 doc/src/sgml/install-windows.sgml |  8 ++++----
 src/tools/msvc/MSBuildProject.pm  | 23 +++++++++++++++++++++++
 src/tools/msvc/Solution.pm        | 26 ++++++++++++++++++++++++++
 src/tools/msvc/VSObjectFactory.pm | 12 ++++++++++--
 4 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index f08cca7..148180b 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -19,10 +19,10 @@
  <para>
   There are several different ways of building PostgreSQL on
   <productname>Windows</productname>. The simplest way to build with
-  Microsoft tools is to install <productname>Visual Studio Express 2013
+  Microsoft tools is to install <productname>Visual Studio Express 2015
   for Windows Desktop</productname> and use the included
   compiler. It is also possible to build with the full
-  <productname>Microsoft Visual C++ 2005 to 2013</productname>.
+  <productname>Microsoft Visual C++ 2005 to 2015</productname>.
   In some cases that requires the installation of the
   <productname>Windows SDK</productname> in addition to the compiler.
  </para>
@@ -77,7 +77,7 @@
   <productname>Visual Studio Express</productname> or some versions of the
   <productname>Microsoft Windows SDK</productname>. If you do not already have a
   <productname>Visual Studio</productname> environment set up, the easiest
-  ways are to use the compilers from <productname>Visual Studio Express 2013
+  ways are to use the compilers from <productname>Visual Studio Express 2015
   for Windows Desktop</productname> or those in the <productname>Windows SDK
   7.1</productname>, which are both free downloads from Microsoft.
  </para>
@@ -85,7 +85,7 @@
  <para>
   PostgreSQL is known to support compilation using the compilers shipped with
   <productname>Visual Studio 2005</productname> to
-  <productname>Visual Studio 2013</productname> (including Express editions),
+  <productname>Visual Studio 2015</productname> (including Express editions),
   as well as standalone Windows SDK releases 6.0 to 7.1.
   64-bit PostgreSQL builds are only supported with
   <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 3d60b64..d7638b4 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -465,4 +465,27 @@ sub new
 	return $self;
 }
 
+package VC2015Project;
+
+#
+# Package that encapsulates a Visual C++ 2015 project file
+#
+
+use strict;
+use warnings;
+use base qw(VC2012Project);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{vcver}           = '14.00';
+	$self->{PlatformToolset} = 'v140';
+	$self->{ToolsVersion}    = '14.0';
+
+	return $self;
+}
+
 1;
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 60bcd7e..1181a03 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -779,6 +779,32 @@ sub new
 	return $self;
 }
 
+package VS2015Solution;
+
+#
+# Package that encapsulates a Visual Studio 2015 solution file
+#
+
+use Carp;
+use strict;
+use warnings;
+use base qw(Solution);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{solutionFileVersion}        = '14.00';
+	$self->{vcver}                      = '14.00';
+	$self->{visualStudioName}           = 'Visual Studio 2015';
+	$self->{VisualStudioVersion}        = '14.0.24730.2';
+	$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
+
+	return $self;
+}
+
 sub GetAdditionalHeaders
 {
 	my ($self, $f) = @_;
diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm
index fee4684..4190ada 100644
--- a/src/tools/msvc/VSObjectFactory.pm
+++ b/src/tools/msvc/VSObjectFactory.pm
@@ -49,6 +49,10 @@ sub CreateSolution
 	{
 		return new VS2013Solution(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VS2015Solution(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -84,6 +88,10 @@ sub CreateProject
 	{
 		return new VC2013Project(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VC2015Project(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion
 sub _GetVisualStudioVersion
 {
 	my ($major, $minor) = @_;
-	if ($major > 12)
+	if ($major > 14)
 	{
 		carp
 "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
-		return '12.00';
+		return '14.00';
 	}
 	elsif ($major < 6)
 	{
-- 
2.7.2

#29Noah Misch
noah@leadboat.com
In reply to: Michael Paquier (#22)
Re: VS 2015 support in src/tools/msvc

On Tue, Mar 08, 2016 at 10:32:28PM +0900, Michael Paquier wrote:

Subject: [PATCH 3/4] Fix use of locales for VS 2015

lc_codepage is a flag missing from locale.h, causing this code path
introduced in VS 2012 to fail. Perhaps there is a reason for this field
to have been clobbered, but let's fall back to the pre-VS-2012 code
parsing directly LC_TYPE to get the codepage wanted.
---
src/port/chklocale.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..a7d88fb 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -203,7 +203,16 @@ win32_langinfo(const char *ctype)
{
char	   *r = NULL;
-#if (_MSC_VER >= 1700)
+	/*
+	 * lc_codepage is correctly declared in Visual Studio 2012 and 2013.
+	 * However in VS 2015 this flag is missing from locale.h, visibly this
+	 * is an error of refactoring from Microsoft that is at the origin of
+	 * this missing field, causing a compilation failure in this code path.
+	 * Hence, it is more reliable to fall back to other code path grabbing

No, the other path can't handle a "locale name" like "initdb --locale=th-TH".
That makes the other code path inadequate for VS2012 and later. See the
IsoLocaleName() header comment.

+	 * the codepage from the ctype name itself. If VS gets back this field
+	 * in the future, we may want to relax the use of _create_locale here.
+	 */
+#if (_MSC_VER >= 1700) && (_MSC_VER <= 1800)
_locale_t	loct = NULL;

loct = _create_locale(LC_CTYPE, ctype);

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#30Yury Zhuravlev
u.zhuravlev@postgrespro.ru
In reply to: Michael Paquier (#28)
Re: VS 2015 support in src/tools/msvc

Good point. It did not occur to me that this would bring a hard
dependency for non-Windows builds. Let's keep both scripts then. The
attached is changed to do so.

Hello.
What about putenv problem? We can't write:
#define putenv(x) pgwin32_putenv(x)
because in new CRT putenv have different signature.

Thanks.
--
Yury Zhuravlev
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#31Petr Jelinek
petr@2ndquadrant.com
In reply to: Yury Zhuravlev (#30)
Re: VS 2015 support in src/tools/msvc

On 09/03/16 12:09, Yury Zhuravlev wrote:

Good point. It did not occur to me that this would bring a hard
dependency for non-Windows builds. Let's keep both scripts then. The
attached is changed to do so.

Hello.
What about putenv problem? We can't write:
#define putenv(x) pgwin32_putenv(x)
because in new CRT putenv have different signature.

Hmm, I don't see any problem there.

We should however add the msvc 2015 module to rtmodules in the
pgwin32_putenv so that we can run just with that runtime.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#32Petr Jelinek
petr@2ndquadrant.com
In reply to: Noah Misch (#29)
1 attachment(s)
Re: VS 2015 support in src/tools/msvc

On 09/03/16 05:31, Noah Misch wrote:

On Tue, Mar 08, 2016 at 10:32:28PM +0900, Michael Paquier wrote:

Subject: [PATCH 3/4] Fix use of locales for VS 2015

lc_codepage is a flag missing from locale.h, causing this code path
introduced in VS 2012 to fail. Perhaps there is a reason for this field
to have been clobbered, but let's fall back to the pre-VS-2012 code
parsing directly LC_TYPE to get the codepage wanted.
---
src/port/chklocale.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..a7d88fb 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -203,7 +203,16 @@ win32_langinfo(const char *ctype)
{
char	   *r = NULL;
-#if (_MSC_VER >= 1700)
+	/*
+	 * lc_codepage is correctly declared in Visual Studio 2012 and 2013.
+	 * However in VS 2015 this flag is missing from locale.h, visibly this
+	 * is an error of refactoring from Microsoft that is at the origin of
+	 * this missing field, causing a compilation failure in this code path.
+	 * Hence, it is more reliable to fall back to other code path grabbing

No, the other path can't handle a "locale name" like "initdb --locale=th-TH".
That makes the other code path inadequate for VS2012 and later. See the
IsoLocaleName() header comment.

Agreed, that's what I was saying as well.

Something like attached is simplest way this would work correctly (note
that I didn't really test it and it's missing comments). Note that we
are falling back to the old parsing in case the GetLocaleInfoEx didn't
work, that's important because GetLocaleInfoEx does not support the
<Language>_<Country>.<CodePage> format but supports all the rest of
them. The problem with this is the binaries would need to be compiled
with target of vista/windows server 2008+. That would be of course only
the case with builds made with VS2015, so I am not sure if we care all
that much (especially given the fact that older windows are not
supported by MS anyway).

I don't currently know of any way of doing this in VS2015 that would
work with older versions of windows with the exception of having our own
definition of the locale_t struct so that the VS2013 code would still
work...

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

chklocale.difftext/x-patch; name=chklocale.diffDownload
diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..11177f6 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -203,7 +203,7 @@ win32_langinfo(const char *ctype)
 {
 	char	   *r = NULL;
 
-#if (_MSC_VER >= 1700)
+#if (_MSC_VER >= 1700) && (_MSC_VER < 1900)
 	_locale_t	loct = NULL;
 
 	loct = _create_locale(LC_CTYPE, ctype);
@@ -215,8 +215,23 @@ win32_langinfo(const char *ctype)
 		_free_locale(loct);
 	}
 #else
+
 	char	   *codepage;
 
+#if (_MSC_VER >= 1900)
+	uint32	cp;
+
+	if (GetLocaleInfoEx(ctype, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER, (LPWSTR)&cp, sizeof(cp)/sizoef(WCHAR)) > 0)
+	{
+		r = malloc(16);			/* excess */
+		if (r != NULL)
+			sprintf(r, "CP%u", cp);
+	}
+	else
+	{
+#endif
+
+
 	/*
 	 * Locale format on Win32 is <Language>_<Country>.<CodePage> . For
 	 * example, English_United States.1252.
@@ -232,6 +247,10 @@ win32_langinfo(const char *ctype)
 		if (r != NULL)
 			sprintf(r, "CP%s", codepage);
 	}
+
+#if (_MSC_VER >= 1900)
+	}
+#endif
 #endif
 
 	return r;
#33Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#28)
Re: VS 2015 support in src/tools/msvc

On 03/08/2016 07:40 PM, Michael Paquier wrote:

On Wed, Mar 9, 2016 at 1:07 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

Michael's patch proposes to replace the use of sed to generate probes.h with
the perl equivalent everywhere. That has the advantage that we keep to one
script to generate probes.h, but it does impose a perl dependency.

Good point. It did not occur to me that this would bring a hard
dependency for non-Windows builds. Let's keep both scripts then. The
attached is changed to do so.

Actually, it wasn't, but I fixed it and committed it.

Still to do: the non-perl pieces.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#34Michael Paquier
michael.paquier@gmail.com
In reply to: Andrew Dunstan (#33)
Re: VS 2015 support in src/tools/msvc

On Sun, Mar 20, 2016 at 8:06 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

On 03/08/2016 07:40 PM, Michael Paquier wrote:

On Wed, Mar 9, 2016 at 1:07 AM, Andrew Dunstan <andrew@dunslane.net>
wrote:

Michael's patch proposes to replace the use of sed to generate probes.h
with
the perl equivalent everywhere. That has the advantage that we keep to
one
script to generate probes.h, but it does impose a perl dependency.

Good point. It did not occur to me that this would bring a hard
dependency for non-Windows builds. Let's keep both scripts then. The
attached is changed to do so.

Actually, it wasn't, but I fixed it and committed it.

Ah, indeed, thanks. It looks like I have been bitten by an incorrect
rebase/cherry-pick.

Still to do: the non-perl pieces.

The patch to address locales is the sensitive part. The patch from
Petr is taking the correct approach though I think that we had better
simplify it a bit and if possible we had better not rely on the else
block it introduces.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#35Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#34)
Re: VS 2015 support in src/tools/msvc

On 03/20/2016 12:02 AM, Michael Paquier wrote:

On Sun, Mar 20, 2016 at 8:06 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

Still to do: the non-perl pieces.

The patch to address locales is the sensitive part. The patch from
Petr is taking the correct approach though I think that we had better
simplify it a bit and if possible we had better not rely on the else
block it introduces.

OK, the please send an updated set of patches for what remains.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#36Petr Jelinek
petr@2ndquadrant.com
In reply to: Michael Paquier (#34)
Re: VS 2015 support in src/tools/msvc

On 20/03/16 05:02, Michael Paquier wrote:

On Sun, Mar 20, 2016 at 8:06 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

Still to do: the non-perl pieces.

The patch to address locales is the sensitive part. The patch from
Petr is taking the correct approach though I think that we had better
simplify it a bit and if possible we had better not rely on the else
block it introduces.

That would be ideal, not particularly sure that both are possible at the
same time. We can definitely remove the else block but it involves
enumerating system locales which makes the patch orders of magnitude
bigger and uglier. Do you have any better approaches in you mind?

As a side note, I have to say the current locale API in Windows is one
huge mess and if it was on me I'd just redefine the locale_t struct
correctly as that is simplest solution and the APIs involved are not
deprecated or anything, it's just that the public headers are botched in
current version and apparently nobody important is using them to force
MS to fix them.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#37Michael Paquier
michael.paquier@gmail.com
In reply to: Petr Jelinek (#32)
Re: VS 2015 support in src/tools/msvc

On Wed, Mar 9, 2016 at 11:10 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

Something like attached is simplest way this would work correctly (note that
I didn't really test it and it's missing comments). Note that we are falling
back to the old parsing in case the GetLocaleInfoEx didn't work, that's
important because GetLocaleInfoEx does not support the
<Language>_<Country>.<CodePage> format but supports all the rest of them.
The problem with this is the binaries would need to be compiled with target
of vista/windows server 2008+. That would be of course only the case with
builds made with VS2015, so I am not sure if we care all that much
(especially given the fact that older windows are not supported by MS
anyway).

Ah, OK. Of course.

I don't currently know of any way of doing this in VS2015 that would work
with older versions of windows with the exception of having our own
definition of the locale_t struct so that the VS2013 code would still
work...

There is no actual way to be sure if this is an intentional change or
not, if we see it back in the next version of VS, why not... I would
like to think like you that this is actually a merge mistake from
Redmond-side, but I think we had better be careful here, this could
lead to undetected errors in the future.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#38Petr Jelinek
petr@2ndquadrant.com
In reply to: Michael Paquier (#37)
Re: VS 2015 support in src/tools/msvc

On 22/03/16 14:40, Michael Paquier wrote:

On Wed, Mar 9, 2016 at 11:10 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

Something like attached is simplest way this would work correctly (note that
I didn't really test it and it's missing comments). Note that we are falling
back to the old parsing in case the GetLocaleInfoEx didn't work, that's
important because GetLocaleInfoEx does not support the
<Language>_<Country>.<CodePage> format but supports all the rest of them.
The problem with this is the binaries would need to be compiled with target
of vista/windows server 2008+. That would be of course only the case with
builds made with VS2015, so I am not sure if we care all that much
(especially given the fact that older windows are not supported by MS
anyway).

Ah, OK. Of course.

I don't currently know of any way of doing this in VS2015 that would work
with older versions of windows with the exception of having our own
definition of the locale_t struct so that the VS2013 code would still
work...

There is no actual way to be sure if this is an intentional change or
not, if we see it back in the next version of VS, why not... I would
like to think like you that this is actually a merge mistake from
Redmond-side, but I think we had better be careful here, this could
lead to undetected errors in the future.

Sure, I am looking at it from the perspective that they didn't even
deprecate the function and changes to the struct it returns would break
binary compatibility for existing apps.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#39Michael Paquier
michael.paquier@gmail.com
In reply to: Andrew Dunstan (#35)
4 attachment(s)
Re: VS 2015 support in src/tools/msvc

On Mon, Mar 21, 2016 at 3:43 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

On 03/20/2016 12:02 AM, Michael Paquier wrote:

On Sun, Mar 20, 2016 at 8:06 AM, Andrew Dunstan <andrew@dunslane.net>
wrote:

Still to do: the non-perl pieces.

The patch to address locales is the sensitive part. The patch from
Petr is taking the correct approach though I think that we had better
simplify it a bit and if possible we had better not rely on the else
block it introduces.

OK, the please send an updated set of patches for what remains.

Here you go:
- 0001 fixes the global declarations of TIMEZONE_GLOBAL and
TZNAME_GLOBAL to be WIN32-compliant. I got bitten by that in the ECPG
compilation.
- 0002, support of VS2015 in the scripts of src/tools/msvc
- 0003, this is necessary in order to run the regression tests,
details are here:
/messages/by-id/CAB7nPqTDiXxS8CdL8mOiVh6qFQ-1qV9mKN0AyjzYBvzv6WC0dA@mail.gmail.com
- 0004 is the fix for locales. This is actually Petr's work upthread,
I have updated comments in the code though and did a bit more
polishing. This still looks like the cleanest solution we have. Other
solutions are mentioned upthread: redeclaration of struct _locale_t in
backend code is one.
--
Michael

Attachments:

0001-Fix-declaration-of-TIMEZONE_GLOBAL-and-TZNAME_GLOBAL.patchbinary/octet-stream; name=0001-Fix-declaration-of-TIMEZONE_GLOBAL-and-TZNAME_GLOBAL.patchDownload
From 9f9eab98baabfb9d3e6826e916ce4e56eb98732a Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Wed, 23 Mar 2016 15:04:48 +0900
Subject: [PATCH 1/4] Fix declaration of TIMEZONE_GLOBAL and TZNAME_GLOBAL for
 WIN32

When compiling the code with WIN32, those two variables were declared
as timezone and tzname, while the objects present for MSVC are _timezone
and _tzname.
---
 src/include/port.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/include/port.h b/src/include/port.h
index cb13dd8..455f723 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -214,12 +214,12 @@ extern int	pgkill(int pid, int sig);
 extern int	pclose_check(FILE *stream);
 
 /* Global variable holding time zone information. */
-#ifndef __CYGWIN__
-#define TIMEZONE_GLOBAL timezone
-#define TZNAME_GLOBAL tzname
-#else
+#if defined(WIN32) || defined(__CYGWIN__)
 #define TIMEZONE_GLOBAL _timezone
 #define TZNAME_GLOBAL _tzname
+#else
+#define TIMEZONE_GLOBAL timezone
+#define TZNAME_GLOBAL tzname
 #endif
 
 #if defined(WIN32) || defined(__CYGWIN__)
-- 
2.7.3

0002-Add-support-for-VS-2015-in-MSVC-scripts.patchbinary/octet-stream; name=0002-Add-support-for-VS-2015-in-MSVC-scripts.patchDownload
From d73bdb7bfc8f1bd00a1fc9b6a0097471eeb46d15 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Wed, 23 Mar 2016 15:05:22 +0900
Subject: [PATCH 2/4] Add support for VS 2015 in MSVC scripts

One can use that to compile with the latest version of Visual Studio
on Windows.
---
 doc/src/sgml/install-windows.sgml |  8 ++++----
 src/tools/msvc/MSBuildProject.pm  | 23 +++++++++++++++++++++++
 src/tools/msvc/Solution.pm        | 26 ++++++++++++++++++++++++++
 src/tools/msvc/VSObjectFactory.pm | 12 ++++++++++--
 4 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index f08cca7..148180b 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -19,10 +19,10 @@
  <para>
   There are several different ways of building PostgreSQL on
   <productname>Windows</productname>. The simplest way to build with
-  Microsoft tools is to install <productname>Visual Studio Express 2013
+  Microsoft tools is to install <productname>Visual Studio Express 2015
   for Windows Desktop</productname> and use the included
   compiler. It is also possible to build with the full
-  <productname>Microsoft Visual C++ 2005 to 2013</productname>.
+  <productname>Microsoft Visual C++ 2005 to 2015</productname>.
   In some cases that requires the installation of the
   <productname>Windows SDK</productname> in addition to the compiler.
  </para>
@@ -77,7 +77,7 @@
   <productname>Visual Studio Express</productname> or some versions of the
   <productname>Microsoft Windows SDK</productname>. If you do not already have a
   <productname>Visual Studio</productname> environment set up, the easiest
-  ways are to use the compilers from <productname>Visual Studio Express 2013
+  ways are to use the compilers from <productname>Visual Studio Express 2015
   for Windows Desktop</productname> or those in the <productname>Windows SDK
   7.1</productname>, which are both free downloads from Microsoft.
  </para>
@@ -85,7 +85,7 @@
  <para>
   PostgreSQL is known to support compilation using the compilers shipped with
   <productname>Visual Studio 2005</productname> to
-  <productname>Visual Studio 2013</productname> (including Express editions),
+  <productname>Visual Studio 2015</productname> (including Express editions),
   as well as standalone Windows SDK releases 6.0 to 7.1.
   64-bit PostgreSQL builds are only supported with
   <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 3d60b64..d7638b4 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -465,4 +465,27 @@ sub new
 	return $self;
 }
 
+package VC2015Project;
+
+#
+# Package that encapsulates a Visual C++ 2015 project file
+#
+
+use strict;
+use warnings;
+use base qw(VC2012Project);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{vcver}           = '14.00';
+	$self->{PlatformToolset} = 'v140';
+	$self->{ToolsVersion}    = '14.0';
+
+	return $self;
+}
+
 1;
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 60bcd7e..1181a03 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -779,6 +779,32 @@ sub new
 	return $self;
 }
 
+package VS2015Solution;
+
+#
+# Package that encapsulates a Visual Studio 2015 solution file
+#
+
+use Carp;
+use strict;
+use warnings;
+use base qw(Solution);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{solutionFileVersion}        = '14.00';
+	$self->{vcver}                      = '14.00';
+	$self->{visualStudioName}           = 'Visual Studio 2015';
+	$self->{VisualStudioVersion}        = '14.0.24730.2';
+	$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
+
+	return $self;
+}
+
 sub GetAdditionalHeaders
 {
 	my ($self, $f) = @_;
diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm
index fee4684..4190ada 100644
--- a/src/tools/msvc/VSObjectFactory.pm
+++ b/src/tools/msvc/VSObjectFactory.pm
@@ -49,6 +49,10 @@ sub CreateSolution
 	{
 		return new VS2013Solution(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VS2015Solution(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -84,6 +88,10 @@ sub CreateProject
 	{
 		return new VC2013Project(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VC2015Project(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion
 sub _GetVisualStudioVersion
 {
 	my ($major, $minor) = @_;
-	if ($major > 12)
+	if ($major > 14)
 	{
 		carp
 "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
-		return '12.00';
+		return '14.00';
 	}
 	elsif ($major < 6)
 	{
-- 
2.7.3

0003-Fix-non-compliant-boolean-declarations-with-stdbool.patchbinary/octet-stream; name=0003-Fix-non-compliant-boolean-declarations-with-stdbool.patchDownload
From ebc29e3288191d008c05cde1330a6ae57b69e251 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Wed, 23 Mar 2016 15:11:37 +0900
Subject: [PATCH 3/4] Fix non-compliant boolean declarations with stdbool

Some of the backend-side macros performing bitwise comparator operations
designed to return boolean results, actually return integer-related results,
causing failures on platforms where stdbool.h is indirectly included in
the code compiled, one platform at least impacted is Windows with VS 2015,
causing regression tests related to gin to fail.
---
 src/backend/access/transam/xact.c               |  3 ++-
 src/backend/replication/logical/reorderbuffer.c |  2 +-
 src/backend/storage/lmgr/lwlock.c               | 12 ++++++------
 src/include/access/gin_private.h                | 16 ++++++++--------
 src/include/access/gist.h                       | 10 +++++-----
 src/include/access/htup_details.h               |  8 ++++----
 src/include/access/itup.h                       |  4 ++--
 src/include/access/nbtree.h                     | 14 +++++++-------
 src/include/access/spgist_private.h             | 10 +++++-----
 src/include/access/xact.h                       |  4 ++--
 src/include/catalog/pg_trigger.h                | 10 +++++-----
 src/include/commands/trigger.h                  |  2 +-
 src/include/regex/regguts.h                     |  2 +-
 src/include/storage/bufpage.h                   |  6 +++---
 src/include/utils/jsonb.h                       |  6 +++---
 15 files changed, 55 insertions(+), 54 deletions(-)

diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 89a14b4..59cc065 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -5335,7 +5335,8 @@ xact_redo_commit(xl_xact_parsed_commit *parsed,
 		LWLockRelease(XidGenLock);
 	}
 
-	Assert(!!(parsed->xinfo & XACT_XINFO_HAS_ORIGIN) == (origin_id != InvalidRepOriginId));
+	Assert(((parsed->xinfo & XACT_XINFO_HAS_ORIGIN) != 0) ==
+		   (origin_id != InvalidRepOriginId));
 
 	if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
 		commit_time = parsed->origin_timestamp;
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index f2b8f4b..9d78c8c 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -603,7 +603,7 @@ ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create,
 	if (is_new)
 		*is_new = !found;
 
-	Assert(!create || !!txn);
+	Assert(!create || txn != NULL);
 	return txn;
 }
 
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 11e4a51..31626cb 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -209,11 +209,11 @@ PRINT_LWDEBUG(const char *where, LWLock *lock, LWLockMode mode)
 					 errmsg_internal("%d: %s(%s): excl %u shared %u haswaiters %u waiters %u rOK %d",
 							MyProcPid,
 							where, MainLWLockNames[id],
-							!!(state & LW_VAL_EXCLUSIVE),
+							(state & LW_VAL_EXCLUSIVE) != 0,
 							state & LW_SHARED_MASK,
-							!!(state & LW_FLAG_HAS_WAITERS),
+							(state & LW_FLAG_HAS_WAITERS) != 0,
 							pg_atomic_read_u32(&lock->nwaiters),
-							!!(state & LW_FLAG_RELEASE_OK))));
+							(state & LW_FLAG_RELEASE_OK) != 0)));
 		else
 			ereport(LOG,
 					(errhidestmt(true),
@@ -221,11 +221,11 @@ PRINT_LWDEBUG(const char *where, LWLock *lock, LWLockMode mode)
 					 errmsg_internal("%d: %s(%s %d): excl %u shared %u haswaiters %u waiters %u rOK %d",
 							MyProcPid,
 							where, T_NAME(lock), id,
-							!!(state & LW_VAL_EXCLUSIVE),
+							(state & LW_VAL_EXCLUSIVE) != 0,
 							state & LW_SHARED_MASK,
-							!!(state & LW_FLAG_HAS_WAITERS),
+							(state & LW_FLAG_HAS_WAITERS) != 0,
 							pg_atomic_read_u32(&lock->nwaiters),
-							!!(state & LW_FLAG_RELEASE_OK))));
+							(state & LW_FLAG_RELEASE_OK) != 0)));
 	}
 }
 
diff --git a/src/include/access/gin_private.h b/src/include/access/gin_private.h
index d2ea588..e212c9f 100644
--- a/src/include/access/gin_private.h
+++ b/src/include/access/gin_private.h
@@ -112,22 +112,22 @@ typedef struct GinMetaPageData
  */
 #define GinPageGetOpaque(page) ( (GinPageOpaque) PageGetSpecialPointer(page) )
 
-#define GinPageIsLeaf(page)    ( GinPageGetOpaque(page)->flags & GIN_LEAF )
+#define GinPageIsLeaf(page)    ( (GinPageGetOpaque(page)->flags & GIN_LEAF) != 0 )
 #define GinPageSetLeaf(page)   ( GinPageGetOpaque(page)->flags |= GIN_LEAF )
 #define GinPageSetNonLeaf(page)    ( GinPageGetOpaque(page)->flags &= ~GIN_LEAF )
-#define GinPageIsData(page)    ( GinPageGetOpaque(page)->flags & GIN_DATA )
+#define GinPageIsData(page)    ( (GinPageGetOpaque(page)->flags & GIN_DATA) != 0 )
 #define GinPageSetData(page)   ( GinPageGetOpaque(page)->flags |= GIN_DATA )
-#define GinPageIsList(page)    ( GinPageGetOpaque(page)->flags & GIN_LIST )
+#define GinPageIsList(page)    ( (GinPageGetOpaque(page)->flags & GIN_LIST) != 0 )
 #define GinPageSetList(page)   ( GinPageGetOpaque(page)->flags |= GIN_LIST )
-#define GinPageHasFullRow(page)    ( GinPageGetOpaque(page)->flags & GIN_LIST_FULLROW )
+#define GinPageHasFullRow(page)    ( (GinPageGetOpaque(page)->flags & GIN_LIST_FULLROW) != 0 )
 #define GinPageSetFullRow(page)   ( GinPageGetOpaque(page)->flags |= GIN_LIST_FULLROW )
-#define GinPageIsCompressed(page)	 ( GinPageGetOpaque(page)->flags & GIN_COMPRESSED )
+#define GinPageIsCompressed(page)	 ( (GinPageGetOpaque(page)->flags & GIN_COMPRESSED) != 0 )
 #define GinPageSetCompressed(page)	 ( GinPageGetOpaque(page)->flags |= GIN_COMPRESSED )
 
-#define GinPageIsDeleted(page) ( GinPageGetOpaque(page)->flags & GIN_DELETED)
+#define GinPageIsDeleted(page) ( (GinPageGetOpaque(page)->flags & GIN_DELETED) != 0 )
 #define GinPageSetDeleted(page)    ( GinPageGetOpaque(page)->flags |= GIN_DELETED)
 #define GinPageSetNonDeleted(page) ( GinPageGetOpaque(page)->flags &= ~GIN_DELETED)
-#define GinPageIsIncompleteSplit(page) ( GinPageGetOpaque(page)->flags & GIN_INCOMPLETE_SPLIT)
+#define GinPageIsIncompleteSplit(page) ( (GinPageGetOpaque(page)->flags & GIN_INCOMPLETE_SPLIT) != 0 )
 
 #define GinPageRightMost(page) ( GinPageGetOpaque(page)->rightlink == InvalidBlockNumber)
 
@@ -224,7 +224,7 @@ typedef signed char GinNullCategory;
 #define GinGetPostingOffset(itup)	(GinItemPointerGetBlockNumber(&(itup)->t_tid) & (~GIN_ITUP_COMPRESSED))
 #define GinSetPostingOffset(itup,n) ItemPointerSetBlockNumber(&(itup)->t_tid,(n)|GIN_ITUP_COMPRESSED)
 #define GinGetPosting(itup)			((Pointer) ((char*)(itup) + GinGetPostingOffset(itup)))
-#define GinItupIsCompressed(itup)	(GinItemPointerGetBlockNumber(&(itup)->t_tid) & GIN_ITUP_COMPRESSED)
+#define GinItupIsCompressed(itup)	((GinItemPointerGetBlockNumber(&(itup)->t_tid) & GIN_ITUP_COMPRESSED) != 0)
 
 /*
  * Maximum size of an item on entry tree page. Make sure that we fit at least
diff --git a/src/include/access/gist.h b/src/include/access/gist.h
index 4343d6f..f40e81b 100644
--- a/src/include/access/gist.h
+++ b/src/include/access/gist.h
@@ -129,22 +129,22 @@ typedef struct GISTENTRY
 
 #define GistPageGetOpaque(page) ( (GISTPageOpaque) PageGetSpecialPointer(page) )
 
-#define GistPageIsLeaf(page)	( GistPageGetOpaque(page)->flags & F_LEAF)
+#define GistPageIsLeaf(page)	( (GistPageGetOpaque(page)->flags & F_LEAF) != 0)
 #define GIST_LEAF(entry) (GistPageIsLeaf((entry)->page))
 
-#define GistPageIsDeleted(page) ( GistPageGetOpaque(page)->flags & F_DELETED)
+#define GistPageIsDeleted(page) ( (GistPageGetOpaque(page)->flags & F_DELETED) != 0)
 #define GistPageSetDeleted(page)	( GistPageGetOpaque(page)->flags |= F_DELETED)
 #define GistPageSetNonDeleted(page) ( GistPageGetOpaque(page)->flags &= ~F_DELETED)
 
-#define GistTuplesDeleted(page) ( GistPageGetOpaque(page)->flags & F_TUPLES_DELETED)
+#define GistTuplesDeleted(page) ( (GistPageGetOpaque(page)->flags & F_TUPLES_DELETED) != 0)
 #define GistMarkTuplesDeleted(page) ( GistPageGetOpaque(page)->flags |= F_TUPLES_DELETED)
 #define GistClearTuplesDeleted(page)	( GistPageGetOpaque(page)->flags &= ~F_TUPLES_DELETED)
 
-#define GistPageHasGarbage(page) ( GistPageGetOpaque(page)->flags & F_HAS_GARBAGE)
+#define GistPageHasGarbage(page) ( (GistPageGetOpaque(page)->flags & F_HAS_GARBAGE) != 0)
 #define GistMarkPageHasGarbage(page) ( GistPageGetOpaque(page)->flags |= F_HAS_GARBAGE)
 #define GistClearPageHasGarbage(page)	( GistPageGetOpaque(page)->flags &= ~F_HAS_GARBAGE)
 
-#define GistFollowRight(page) ( GistPageGetOpaque(page)->flags & F_FOLLOW_RIGHT)
+#define GistFollowRight(page) ((GistPageGetOpaque(page)->flags & F_FOLLOW_RIGHT) != 0)
 #define GistMarkFollowRight(page) ( GistPageGetOpaque(page)->flags |= F_FOLLOW_RIGHT)
 #define GistClearFollowRight(page)	( GistPageGetOpaque(page)->flags &= ~F_FOLLOW_RIGHT)
 
diff --git a/src/include/access/htup_details.h b/src/include/access/htup_details.h
index 9f9cf2a..16fd4c6 100644
--- a/src/include/access/htup_details.h
+++ b/src/include/access/htup_details.h
@@ -214,7 +214,7 @@ struct HeapTupleHeaderData
  * Beware of multiple evaluations of the argument.
  */
 #define HEAP_XMAX_IS_LOCKED_ONLY(infomask) \
-	(((infomask) & HEAP_XMAX_LOCK_ONLY) || \
+	(((infomask) & HEAP_XMAX_LOCK_ONLY) != 0 || \
 	 (((infomask) & (HEAP_XMAX_IS_MULTI | HEAP_LOCK_MASK)) == HEAP_XMAX_EXCL_LOCK))
 
 /*
@@ -292,7 +292,7 @@ struct HeapTupleHeaderData
 
 #define HeapTupleHeaderXminCommitted(tup) \
 ( \
-	(tup)->t_infomask & HEAP_XMIN_COMMITTED \
+	((tup)->t_infomask & HEAP_XMIN_COMMITTED) != 0 \
 )
 
 #define HeapTupleHeaderXminInvalid(tup) \
@@ -476,7 +476,7 @@ do { \
 
 #define HeapTupleHeaderIsHeapOnly(tup) \
 ( \
-  (tup)->t_infomask2 & HEAP_ONLY_TUPLE \
+  ((tup)->t_infomask2 & HEAP_ONLY_TUPLE) != 0 \
 )
 
 #define HeapTupleHeaderSetHeapOnly(tup) \
@@ -491,7 +491,7 @@ do { \
 
 #define HeapTupleHeaderHasMatch(tup) \
 ( \
-  (tup)->t_infomask2 & HEAP_TUPLE_HAS_MATCH \
+  ((tup)->t_infomask2 & HEAP_TUPLE_HAS_MATCH) != 0 \
 )
 
 #define HeapTupleHeaderSetMatch(tup) \
diff --git a/src/include/access/itup.h b/src/include/access/itup.h
index 8350fa0..18427d7 100644
--- a/src/include/access/itup.h
+++ b/src/include/access/itup.h
@@ -69,8 +69,8 @@ typedef IndexAttributeBitMapData *IndexAttributeBitMap;
 
 #define IndexTupleSize(itup)		((Size) (((IndexTuple) (itup))->t_info & INDEX_SIZE_MASK))
 #define IndexTupleDSize(itup)		((Size) ((itup).t_info & INDEX_SIZE_MASK))
-#define IndexTupleHasNulls(itup)	((((IndexTuple) (itup))->t_info & INDEX_NULL_MASK))
-#define IndexTupleHasVarwidths(itup) ((((IndexTuple) (itup))->t_info & INDEX_VAR_MASK))
+#define IndexTupleHasNulls(itup)	((((IndexTuple) (itup))->t_info & INDEX_NULL_MASK) != 0)
+#define IndexTupleHasVarwidths(itup) ((((IndexTuple) (itup))->t_info & INDEX_VAR_MASK) != 0)
 
 
 /*
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 9046b16..0ab6f7c 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -174,13 +174,13 @@ typedef struct BTMetaPageData
  */
 #define P_LEFTMOST(opaque)		((opaque)->btpo_prev == P_NONE)
 #define P_RIGHTMOST(opaque)		((opaque)->btpo_next == P_NONE)
-#define P_ISLEAF(opaque)		((opaque)->btpo_flags & BTP_LEAF)
-#define P_ISROOT(opaque)		((opaque)->btpo_flags & BTP_ROOT)
-#define P_ISDELETED(opaque)		((opaque)->btpo_flags & BTP_DELETED)
-#define P_ISHALFDEAD(opaque)	((opaque)->btpo_flags & BTP_HALF_DEAD)
-#define P_IGNORE(opaque)		((opaque)->btpo_flags & (BTP_DELETED|BTP_HALF_DEAD))
-#define P_HAS_GARBAGE(opaque)	((opaque)->btpo_flags & BTP_HAS_GARBAGE)
-#define P_INCOMPLETE_SPLIT(opaque)	((opaque)->btpo_flags & BTP_INCOMPLETE_SPLIT)
+#define P_ISLEAF(opaque)		(((opaque)->btpo_flags & BTP_LEAF) != 0)
+#define P_ISROOT(opaque)		(((opaque)->btpo_flags & BTP_ROOT) != 0)
+#define P_ISDELETED(opaque)		(((opaque)->btpo_flags & BTP_DELETED) != 0)
+#define P_ISHALFDEAD(opaque)	(((opaque)->btpo_flags & BTP_HALF_DEAD) != 0)
+#define P_IGNORE(opaque)		(((opaque)->btpo_flags & (BTP_DELETED|BTP_HALF_DEAD)) != 0)
+#define P_HAS_GARBAGE(opaque)	(((opaque)->btpo_flags & BTP_HAS_GARBAGE) != 0)
+#define P_INCOMPLETE_SPLIT(opaque)	(((opaque)->btpo_flags & BTP_INCOMPLETE_SPLIT) != 0)
 
 /*
  *	Lehman and Yao's algorithm requires a ``high key'' on every non-rightmost
diff --git a/src/include/access/spgist_private.h b/src/include/access/spgist_private.h
index cb8fa9c..097fd95 100644
--- a/src/include/access/spgist_private.h
+++ b/src/include/access/spgist_private.h
@@ -54,10 +54,10 @@ typedef SpGistPageOpaqueData *SpGistPageOpaque;
 #define SPGIST_NULLS		(1<<3)
 
 #define SpGistPageGetOpaque(page) ((SpGistPageOpaque) PageGetSpecialPointer(page))
-#define SpGistPageIsMeta(page) (SpGistPageGetOpaque(page)->flags & SPGIST_META)
-#define SpGistPageIsDeleted(page) (SpGistPageGetOpaque(page)->flags & SPGIST_DELETED)
-#define SpGistPageIsLeaf(page) (SpGistPageGetOpaque(page)->flags & SPGIST_LEAF)
-#define SpGistPageStoresNulls(page) (SpGistPageGetOpaque(page)->flags & SPGIST_NULLS)
+#define SpGistPageIsMeta(page) ((SpGistPageGetOpaque(page)->flags & SPGIST_META) != 0)
+#define SpGistPageIsDeleted(page) ((SpGistPageGetOpaque(page)->flags & SPGIST_DELETED) != 0)
+#define SpGistPageIsLeaf(page) ((SpGistPageGetOpaque(page)->flags & SPGIST_LEAF) != 0)
+#define SpGistPageStoresNulls(page) ((SpGistPageGetOpaque(page)->flags & SPGIST_NULLS) != 0)
 
 /*
  * The page ID is for the convenience of pg_filedump and similar utilities,
@@ -607,7 +607,7 @@ typedef struct spgxlogVacuumRedirect
 
 #define GBUF_PARITY_MASK		0x03
 #define GBUF_REQ_LEAF(flags)	(((flags) & GBUF_PARITY_MASK) == GBUF_LEAF)
-#define GBUF_REQ_NULLS(flags)	((flags) & GBUF_NULLS)
+#define GBUF_REQ_NULLS(flags)	(((flags) & GBUF_NULLS) != 0)
 
 /* spgutils.c */
 extern SpGistCache *spgGetCache(Relation index);
diff --git a/src/include/access/xact.h b/src/include/access/xact.h
index ebeb582..3ba23f5 100644
--- a/src/include/access/xact.h
+++ b/src/include/access/xact.h
@@ -149,9 +149,9 @@ typedef void (*SubXactCallback) (SubXactEvent event, SubTransactionId mySubid,
 
 /* Access macros for above flags */
 #define XactCompletionRelcacheInitFileInval(xinfo) \
-	(!!(xinfo & XACT_COMPLETION_UPDATE_RELCACHE_FILE))
+	((xinfo & XACT_COMPLETION_UPDATE_RELCACHE_FILE) != 0)
 #define XactCompletionForceSyncCommit(xinfo) \
-	(!!(xinfo & XACT_COMPLETION_FORCE_SYNC_COMMIT))
+	((xinfo & XACT_COMPLETION_FORCE_SYNC_COMMIT) != 0)
 
 typedef struct xl_xact_assignment
 {
diff --git a/src/include/catalog/pg_trigger.h b/src/include/catalog/pg_trigger.h
index eb39c50..0f7c6b4 100644
--- a/src/include/catalog/pg_trigger.h
+++ b/src/include/catalog/pg_trigger.h
@@ -123,14 +123,14 @@ typedef FormData_pg_trigger *Form_pg_trigger;
 #define TRIGGER_SETT_UPDATE(type)		((type) |= TRIGGER_TYPE_UPDATE)
 #define TRIGGER_SETT_TRUNCATE(type)		((type) |= TRIGGER_TYPE_TRUNCATE)
 
-#define TRIGGER_FOR_ROW(type)			((type) & TRIGGER_TYPE_ROW)
+#define TRIGGER_FOR_ROW(type)			(((type) & TRIGGER_TYPE_ROW) != 0)
 #define TRIGGER_FOR_BEFORE(type)		(((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_BEFORE)
 #define TRIGGER_FOR_AFTER(type)			(((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_AFTER)
 #define TRIGGER_FOR_INSTEAD(type)		(((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_INSTEAD)
-#define TRIGGER_FOR_INSERT(type)		((type) & TRIGGER_TYPE_INSERT)
-#define TRIGGER_FOR_DELETE(type)		((type) & TRIGGER_TYPE_DELETE)
-#define TRIGGER_FOR_UPDATE(type)		((type) & TRIGGER_TYPE_UPDATE)
-#define TRIGGER_FOR_TRUNCATE(type)		((type) & TRIGGER_TYPE_TRUNCATE)
+#define TRIGGER_FOR_INSERT(type)		(((type) & TRIGGER_TYPE_INSERT) != 0)
+#define TRIGGER_FOR_DELETE(type)		(((type) & TRIGGER_TYPE_DELETE) != 0)
+#define TRIGGER_FOR_UPDATE(type)		(((type) & TRIGGER_TYPE_UPDATE) != 0)
+#define TRIGGER_FOR_TRUNCATE(type)		(((type) & TRIGGER_TYPE_TRUNCATE) != 0)
 
 /*
  * Efficient macro for checking if tgtype matches a particular level
diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h
index 0ed7c86..79fe489 100644
--- a/src/include/commands/trigger.h
+++ b/src/include/commands/trigger.h
@@ -78,7 +78,7 @@ typedef struct TriggerData
 	(((event) & TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_TRUNCATE)
 
 #define TRIGGER_FIRED_FOR_ROW(event) \
-	((event) & TRIGGER_EVENT_ROW)
+	(((event) & TRIGGER_EVENT_ROW) == TRIGGER_EVENT_ROW)
 
 #define TRIGGER_FIRED_FOR_STATEMENT(event) \
 	(!TRIGGER_FIRED_FOR_ROW(event))
diff --git a/src/include/regex/regguts.h b/src/include/regex/regguts.h
index 2ceffa6..6c8d950 100644
--- a/src/include/regex/regguts.h
+++ b/src/include/regex/regguts.h
@@ -212,7 +212,7 @@ struct colordesc
 	int			flags;			/* bit values defined next */
 #define  FREECOL 01				/* currently free */
 #define  PSEUDO  02				/* pseudocolor, no real chars */
-#define  UNUSEDCOLOR(cd) ((cd)->flags & FREECOL)
+#define  UNUSEDCOLOR(cd) (((cd)->flags & FREECOL) != 0)
 	union tree *block;			/* block of solid color, if any */
 };
 
diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h
index 2ce3be7..23e9da7 100644
--- a/src/include/storage/bufpage.h
+++ b/src/include/storage/bufpage.h
@@ -349,21 +349,21 @@ typedef PageHeaderData *PageHeader;
 	PageXLogRecPtrSet(((PageHeader) (page))->pd_lsn, lsn)
 
 #define PageHasFreeLinePointers(page) \
-	(((PageHeader) (page))->pd_flags & PD_HAS_FREE_LINES)
+	((((PageHeader) (page))->pd_flags & PD_HAS_FREE_LINES) != 0)
 #define PageSetHasFreeLinePointers(page) \
 	(((PageHeader) (page))->pd_flags |= PD_HAS_FREE_LINES)
 #define PageClearHasFreeLinePointers(page) \
 	(((PageHeader) (page))->pd_flags &= ~PD_HAS_FREE_LINES)
 
 #define PageIsFull(page) \
-	(((PageHeader) (page))->pd_flags & PD_PAGE_FULL)
+	((((PageHeader) (page))->pd_flags & PD_PAGE_FULL) != 0)
 #define PageSetFull(page) \
 	(((PageHeader) (page))->pd_flags |= PD_PAGE_FULL)
 #define PageClearFull(page) \
 	(((PageHeader) (page))->pd_flags &= ~PD_PAGE_FULL)
 
 #define PageIsAllVisible(page) \
-	(((PageHeader) (page))->pd_flags & PD_ALL_VISIBLE)
+	((((PageHeader) (page))->pd_flags & PD_ALL_VISIBLE) != 0)
 #define PageSetAllVisible(page) \
 	(((PageHeader) (page))->pd_flags |= PD_ALL_VISIBLE)
 #define PageClearAllVisible(page) \
diff --git a/src/include/utils/jsonb.h b/src/include/utils/jsonb.h
index 5f49d8d..2a860dd 100644
--- a/src/include/utils/jsonb.h
+++ b/src/include/utils/jsonb.h
@@ -214,9 +214,9 @@ typedef struct
 
 /* convenience macros for accessing the root container in a Jsonb datum */
 #define JB_ROOT_COUNT(jbp_)		( *(uint32*) VARDATA(jbp_) & JB_CMASK)
-#define JB_ROOT_IS_SCALAR(jbp_) ( *(uint32*) VARDATA(jbp_) & JB_FSCALAR)
-#define JB_ROOT_IS_OBJECT(jbp_) ( *(uint32*) VARDATA(jbp_) & JB_FOBJECT)
-#define JB_ROOT_IS_ARRAY(jbp_)	( *(uint32*) VARDATA(jbp_) & JB_FARRAY)
+#define JB_ROOT_IS_SCALAR(jbp_) ( (*(uint32*) VARDATA(jbp_) & JB_FSCALAR) != 0)
+#define JB_ROOT_IS_OBJECT(jbp_) ( (*(uint32*) VARDATA(jbp_) & JB_FOBJECT) != 0)
+#define JB_ROOT_IS_ARRAY(jbp_)	( (*(uint32*) VARDATA(jbp_) & JB_FARRAY) != 0)
 
 
 /*
-- 
2.7.3

0004-Fix-code-page-calculation-for-Visual-Studio-2015.patchbinary/octet-stream; name=0004-Fix-code-page-calculation-for-Visual-Studio-2015.patchDownload
From 131d85ed01db156cd4f9d42a8a3b810832a52123 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Wed, 23 Mar 2016 16:15:58 +0900
Subject: [PATCH 4/4] Fix code page calculation for Visual Studio 2015

Visual Studio 2015 is missing the declaration of field lc_codepage in
_locale_t, causing the existing code, introduced with VS 2012 to become
incompatible and causing compilation failures. This patch changes the
code path a bit so as GetLocaleInfoEx is used to fetch a code page
where available when compiling the code with VS2015, note that this
is compatible only with Windows 2k8/Vista and newer versions but it is
unlikely that a version of Postgres compiled with VS2015 would run on
platforms older than that, Windows XP being already out of support.
---
 src/port/chklocale.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..9bd18c6 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -196,6 +196,12 @@ static const struct encoding_match encoding_match_list[] = {
  * locale machinery determine the code page.  See comments at IsoLocaleName().
  * For other compilers, follow the locale's predictable format.
  *
+ * Visual Studio 2015 should still be able to do the same, but the declaration
+ * of lc_codepage is missing in _locale_t, causing this code compilation to
+ * fail, hence this falls back instead on GetLocaleInfoEx. VS 2015 may be an
+ * exception and post-VS2015 versions should be able to handle properly the
+ * codepage number using _create_locale().
+ *
  * Returns a malloc()'d string for the caller to free.
  */
 static char *
@@ -203,7 +209,7 @@ win32_langinfo(const char *ctype)
 {
 	char	   *r = NULL;
 
-#if (_MSC_VER >= 1700)
+#if (_MSC_VER >= 1700) && (_MSC_VER < 1900)
 	_locale_t	loct = NULL;
 
 	loct = _create_locale(LC_CTYPE, ctype);
@@ -215,8 +221,24 @@ win32_langinfo(const char *ctype)
 		_free_locale(loct);
 	}
 #else
+
 	char	   *codepage;
 
+#if (_MSC_VER >= 1900)
+	uint32	cp;
+
+	if (GetLocaleInfoEx(ctype,
+			LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
+			(LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0)
+	{
+		r = malloc(16);			/* excess */
+		if (r != NULL)
+			sprintf(r, "CP%u", cp);
+	}
+	else
+	{
+#endif
+
 	/*
 	 * Locale format on Win32 is <Language>_<Country>.<CodePage> . For
 	 * example, English_United States.1252.
@@ -232,6 +254,10 @@ win32_langinfo(const char *ctype)
 		if (r != NULL)
 			sprintf(r, "CP%s", codepage);
 	}
+
+#if (_MSC_VER >= 1900)
+	}
+#endif
 #endif
 
 	return r;
-- 
2.7.3

#40Petr Jelinek
petr@2ndquadrant.com
In reply to: Michael Paquier (#39)
Re: VS 2015 support in src/tools/msvc

On 23/03/16 08:17, Michael Paquier wrote:

On Mon, Mar 21, 2016 at 3:43 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

On 03/20/2016 12:02 AM, Michael Paquier wrote:

On Sun, Mar 20, 2016 at 8:06 AM, Andrew Dunstan <andrew@dunslane.net>
wrote:

Still to do: the non-perl pieces.

The patch to address locales is the sensitive part. The patch from
Petr is taking the correct approach though I think that we had better
simplify it a bit and if possible we had better not rely on the else
block it introduces.

OK, the please send an updated set of patches for what remains.

Here you go:
- 0001 fixes the global declarations of TIMEZONE_GLOBAL and
TZNAME_GLOBAL to be WIN32-compliant. I got bitten by that in the ECPG
compilation.
- 0002, support of VS2015 in the scripts of src/tools/msvc
- 0003, this is necessary in order to run the regression tests,
details are here:
/messages/by-id/CAB7nPqTDiXxS8CdL8mOiVh6qFQ-1qV9mKN0AyjzYBvzv6WC0dA@mail.gmail.com

So that's basically what Andres did? Interesting that we now actually
really need it. I was in favor of doing those changes in any case.

- 0004 is the fix for locales. This is actually Petr's work upthread,
I have updated comments in the code though and did a bit more
polishing. This still looks like the cleanest solution we have. Other
solutions are mentioned upthread: redeclaration of struct _locale_t in
backend code is one.

Thanks for polishing this.

I think this is ready to be committed, but the 0003 might be somewhat
controversial based on the original thread.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#41Michael Paquier
michael.paquier@gmail.com
In reply to: Petr Jelinek (#40)
Re: VS 2015 support in src/tools/msvc

On Wed, Mar 23, 2016 at 8:45 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

On 23/03/16 08:17, Michael Paquier wrote:

On Mon, Mar 21, 2016 at 3:43 AM, Andrew Dunstan <andrew@dunslane.net>
wrote:

On 03/20/2016 12:02 AM, Michael Paquier wrote:

On Sun, Mar 20, 2016 at 8:06 AM, Andrew Dunstan <andrew@dunslane.net>
wrote:

Still to do: the non-perl pieces.

The patch to address locales is the sensitive part. The patch from
Petr is taking the correct approach though I think that we had better
simplify it a bit and if possible we had better not rely on the else
block it introduces.

OK, the please send an updated set of patches for what remains.

Here you go:
- 0001 fixes the global declarations of TIMEZONE_GLOBAL and
TZNAME_GLOBAL to be WIN32-compliant. I got bitten by that in the ECPG
compilation.
- 0002, support of VS2015 in the scripts of src/tools/msvc
- 0003, this is necessary in order to run the regression tests,
details are here:

/messages/by-id/CAB7nPqTDiXxS8CdL8mOiVh6qFQ-1qV9mKN0AyjzYBvzv6WC0dA@mail.gmail.com

So that's basically what Andres did? Interesting that we now actually really
need it. I was in favor of doing those changes in any case.

Yes, that's what Andres did. I am just attaching it here to allow
Andrew to test this patch set appropriately.

- 0004 is the fix for locales. This is actually Petr's work upthread,
I have updated comments in the code though and did a bit more
polishing. This still looks like the cleanest solution we have. Other
solutions are mentioned upthread: redeclaration of struct _locale_t in
backend code is one.

Thanks for polishing this.

I think this is ready to be committed, but the 0003 might be somewhat
controversial based on the original thread.

I thought that the end consensus regarding 0003 was to apply it, but
we could as well wait for the final verdict (committer push) on the
other thread. And well, if this is not applied, some of the gin tests
will complain about "right sibling of GIN page is of different type" a
couple of times.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#42Petr Jelinek
petr@2ndquadrant.com
In reply to: Michael Paquier (#41)
Re: VS 2015 support in src/tools/msvc

On 23/03/16 13:05, Michael Paquier wrote:

OK, the please send an updated set of patches for what remains.

Here you go:
- 0001 fixes the global declarations of TIMEZONE_GLOBAL and
TZNAME_GLOBAL to be WIN32-compliant. I got bitten by that in the ECPG
compilation.
- 0002, support of VS2015 in the scripts of src/tools/msvc
- 0003, this is necessary in order to run the regression tests,
details are here:

/messages/by-id/CAB7nPqTDiXxS8CdL8mOiVh6qFQ-1qV9mKN0AyjzYBvzv6WC0dA@mail.gmail.com

So that's basically what Andres did? Interesting that we now actually really
need it. I was in favor of doing those changes in any case.

Yes, that's what Andres did. I am just attaching it here to allow
Andrew to test this patch set appropriately.

- 0004 is the fix for locales. This is actually Petr's work upthread,
I have updated comments in the code though and did a bit more
polishing. This still looks like the cleanest solution we have. Other
solutions are mentioned upthread: redeclaration of struct _locale_t in
backend code is one.

Thanks for polishing this.

I think this is ready to be committed, but the 0003 might be somewhat
controversial based on the original thread.

I thought that the end consensus regarding 0003 was to apply it, but
we could as well wait for the final verdict (committer push) on the
other thread. And well, if this is not applied, some of the gin tests
will complain about "right sibling of GIN page is of different type" a
couple of times.

Hmm I see you are right, I missed the last couple emails. Ok I'll mark
it ready for committer - it does work fine on my vs2015 machine and I am
happy with the code too. Well, as happy as I can be given the locale mess.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#43Michael Paquier
michael.paquier@gmail.com
In reply to: Petr Jelinek (#42)
Re: VS 2015 support in src/tools/msvc

On Thu, Mar 24, 2016 at 5:18 AM, Petr Jelinek <petr@2ndquadrant.com> wrote:

Hmm I see you are right, I missed the last couple emails. Ok I'll mark it
ready for committer - it does work fine on my vs2015 machine and I am happy
with the code too.

Thanks, let's see what others have to say.

Well, as happy as I can be given the locale mess.

We are responsible for that, that's the frustrating part :)
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#44Robert Haas
robertmhaas@gmail.com
In reply to: Michael Paquier (#39)
Re: VS 2015 support in src/tools/msvc

On Wed, Mar 23, 2016 at 3:17 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

- 0001 fixes the global declarations of TIMEZONE_GLOBAL and
TZNAME_GLOBAL to be WIN32-compliant. I got bitten by that in the ECPG
compilation.

So this isn't going to break other Windows builds? I mean, if we've
got the names for those symbols wrong, how is this working right now?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#45Petr Jelinek
petr@2ndquadrant.com
In reply to: Robert Haas (#44)
Re: VS 2015 support in src/tools/msvc

On 24/03/16 17:28, Robert Haas wrote:

On Wed, Mar 23, 2016 at 3:17 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

- 0001 fixes the global declarations of TIMEZONE_GLOBAL and
TZNAME_GLOBAL to be WIN32-compliant. I got bitten by that in the ECPG
compilation.

So this isn't going to break other Windows builds? I mean, if we've
got the names for those symbols wrong, how is this working right now?

We didn't older versions just defined the other variants as well, but
the _timezone and _tzname have been around since at least VS2003.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#46Robert Haas
robertmhaas@gmail.com
In reply to: Petr Jelinek (#45)
Re: VS 2015 support in src/tools/msvc

On Thu, Mar 24, 2016 at 1:07 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

On 24/03/16 17:28, Robert Haas wrote:

On Wed, Mar 23, 2016 at 3:17 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

- 0001 fixes the global declarations of TIMEZONE_GLOBAL and
TZNAME_GLOBAL to be WIN32-compliant. I got bitten by that in the ECPG
compilation.

So this isn't going to break other Windows builds? I mean, if we've
got the names for those symbols wrong, how is this working right now?

We didn't older versions just defined the other variants as well, but the
_timezone and _tzname have been around since at least VS2003.

I am unable to parse this sentence. Sorry.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#47Michael Paquier
michael.paquier@gmail.com
In reply to: Robert Haas (#46)
Re: VS 2015 support in src/tools/msvc

On Fri, Mar 25, 2016 at 9:09 PM, Robert Haas <robertmhaas@gmail.com> wrote:

On Thu, Mar 24, 2016 at 1:07 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

On 24/03/16 17:28, Robert Haas wrote:

On Wed, Mar 23, 2016 at 3:17 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

- 0001 fixes the global declarations of TIMEZONE_GLOBAL and
TZNAME_GLOBAL to be WIN32-compliant. I got bitten by that in the ECPG
compilation.

So this isn't going to break other Windows builds? I mean, if we've
got the names for those symbols wrong, how is this working right now?

We didn't older versions just defined the other variants as well, but the
_timezone and _tzname have been around since at least VS2003.

I am unable to parse this sentence. Sorry.

Petr means that both _timezone and _tzname are objects defined in
Visual Studio since more or less its 2003 release
(https://msdn.microsoft.com/en-us/library/htb3tdkc%28v=vs.71%29.aspx).
The oldest version on the buildfarm is Visual Studio 2005, and I agree
with him that there is no need to worry about older versions than
VS2003. The issue is that VS2015 does *not* define timezone and tzname
(please note the prefix underscore missing in those variable names),
causing compilation failures. That's why I am suggesting such a change
in this patch: this will allow the code to compile on VS2015, and
that's compatible with VS2003~.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#48Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#47)
Re: VS 2015 support in src/tools/msvc

On 03/25/2016 08:31 AM, Michael Paquier wrote:

On Fri, Mar 25, 2016 at 9:09 PM, Robert Haas <robertmhaas@gmail.com> wrote:

On Thu, Mar 24, 2016 at 1:07 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

On 24/03/16 17:28, Robert Haas wrote:

On Wed, Mar 23, 2016 at 3:17 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

- 0001 fixes the global declarations of TIMEZONE_GLOBAL and
TZNAME_GLOBAL to be WIN32-compliant. I got bitten by that in the ECPG
compilation.

So this isn't going to break other Windows builds? I mean, if we've
got the names for those symbols wrong, how is this working right now?

We didn't older versions just defined the other variants as well, but the
_timezone and _tzname have been around since at least VS2003.

I am unable to parse this sentence. Sorry.

Petr means that both _timezone and _tzname are objects defined in
Visual Studio since more or less its 2003 release
(https://msdn.microsoft.com/en-us/library/htb3tdkc%28v=vs.71%29.aspx).
The oldest version on the buildfarm is Visual Studio 2005, and I agree
with him that there is no need to worry about older versions than
VS2003. The issue is that VS2015 does *not* define timezone and tzname
(please note the prefix underscore missing in those variable names),
causing compilation failures. That's why I am suggesting such a change
in this patch: this will allow the code to compile on VS2015, and
that's compatible with VS2003~.

OK, sounds good. I don't have a spare machine on which to install
VS2015, nor time to set one up, so I'm going to have to trust the two of
you (Michael and Petr) that this works. Will either of you be setting up
a buildfarm animal with VS2015?

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#49Robert Haas
robertmhaas@gmail.com
In reply to: Michael Paquier (#47)
Re: VS 2015 support in src/tools/msvc

On Fri, Mar 25, 2016 at 8:31 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Fri, Mar 25, 2016 at 9:09 PM, Robert Haas <robertmhaas@gmail.com> wrote:

On Thu, Mar 24, 2016 at 1:07 PM, Petr Jelinek <petr@2ndquadrant.com> wrote:

On 24/03/16 17:28, Robert Haas wrote:

On Wed, Mar 23, 2016 at 3:17 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

- 0001 fixes the global declarations of TIMEZONE_GLOBAL and
TZNAME_GLOBAL to be WIN32-compliant. I got bitten by that in the ECPG
compilation.

So this isn't going to break other Windows builds? I mean, if we've
got the names for those symbols wrong, how is this working right now?

We didn't older versions just defined the other variants as well, but the
_timezone and _tzname have been around since at least VS2003.

I am unable to parse this sentence. Sorry.

Petr means that both _timezone and _tzname are objects defined in
Visual Studio since more or less its 2003 release
(https://msdn.microsoft.com/en-us/library/htb3tdkc%28v=vs.71%29.aspx).
The oldest version on the buildfarm is Visual Studio 2005, and I agree
with him that there is no need to worry about older versions than
VS2003. The issue is that VS2015 does *not* define timezone and tzname
(please note the prefix underscore missing in those variable names),
causing compilation failures. That's why I am suggesting such a change
in this patch: this will allow the code to compile on VS2015, and
that's compatible with VS2003~.

OK, that makes sense. The documentation says: "There are several
different ways of building PostgreSQL on Windows. The simplest way to
build with Microsoft tools is to install Visual Studio Express 2013
for Windows Desktop and use the included compiler. It is also possible
to build with the full Microsoft Visual C++ 2005 to 2013. In some
cases that requires the installation of the Windows SDK in addition to
the compiler." So the fact that pre-2003 is out is, I think, covered
by that.

The relationship between doc/src/sgml/install-windows.sgml, the
section of doc/src/sgml/installation.sgml entitled "MinGW/Native
Windows", and src/tools/msvc/README is not altogether clear to me.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#50Michael Paquier
michael.paquier@gmail.com
In reply to: Robert Haas (#49)
Re: VS 2015 support in src/tools/msvc

On Fri, Mar 25, 2016 at 9:55 PM, Robert Haas <robertmhaas@gmail.com> wrote:

On Fri, Mar 25, 2016 at 8:31 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:
The relationship between doc/src/sgml/install-windows.sgml, the
section of doc/src/sgml/installation.sgml entitled "MinGW/Native
Windows", and src/tools/msvc/README is not altogether clear to me.

This README still mentions that:
"Microsoft Visual Studio 2005 - 2011. This builds the whole backend,
not just [...]"
The bump to 2013 has missed an update here, now I guess that we had
better just change it to 2015 and move on.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#51Michael Paquier
michael.paquier@gmail.com
In reply to: Andrew Dunstan (#48)
Re: VS 2015 support in src/tools/msvc

On Fri, Mar 25, 2016 at 9:48 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

OK, sounds good. I don't have a spare machine on which to install VS2015,
nor time to set one up, so I'm going to have to trust the two of you
(Michael and Petr) that this works.

With Virtual Box, you could set up an environment for development on
WinX. They expire after 90 days but setting up the environment is a
matter of 1~2 hours, then by taking a snapshot of the VM you can
rollback to the basic setup easily. That's what I am doing.

Will either of you be setting up a buildfarm animal with VS2015?

We are definitely going to need one... I have a machine at home that
could be used with it, an intel NUC of a couple of years back that's
still waiting to be useful with 16GB of RAM in it, but I have no
license at hand, be it either Win7, Win8 or Win10.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#52Michael Paquier
michael.paquier@gmail.com
In reply to: Andrew Dunstan (#48)
Re: VS 2015 support in src/tools/msvc

On Fri, Mar 25, 2016 at 9:48 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

OK, sounds good.

Just a side-note. Andres has pushed the fix for the GinIs* macros as
af4472bc, making patch 0003 from the last series useless now.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#53Robert Haas
robertmhaas@gmail.com
In reply to: Michael Paquier (#52)
Re: VS 2015 support in src/tools/msvc

On Sun, Mar 27, 2016 at 10:35 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Fri, Mar 25, 2016 at 9:48 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

OK, sounds good.

Just a side-note. Andres has pushed the fix for the GinIs* macros as
af4472bc, making patch 0003 from the last series useless now.

I'm not prepared to get very involved in this patch series since I am
not a Windows guy, but I went ahead and pushed 0001 anyway. I'm not
sure that we want to commit 0002 without a BF machine. Can anybody
help with that?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#54Michael Paquier
michael.paquier@gmail.com
In reply to: Robert Haas (#53)
Re: VS 2015 support in src/tools/msvc

On Tue, Mar 29, 2016 at 10:06 AM, Robert Haas <robertmhaas@gmail.com> wrote:

On Sun, Mar 27, 2016 at 10:35 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Fri, Mar 25, 2016 at 9:48 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

OK, sounds good.

Just a side-note. Andres has pushed the fix for the GinIs* macros as
af4472bc, making patch 0003 from the last series useless now.

I'm not prepared to get very involved in this patch series since I am
not a Windows guy, but I went ahead and pushed 0001 anyway. I'm not
sure that we want to commit 0002 without a BF machine. Can anybody
help with that?

I'll try to get a machine up and running, I guess Win7 with VS2015 at
this stage.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#55Petr Jelinek
petr@2ndquadrant.com
In reply to: Robert Haas (#53)
Re: VS 2015 support in src/tools/msvc

On 29/03/16 03:06, Robert Haas wrote:

On Sun, Mar 27, 2016 at 10:35 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Fri, Mar 25, 2016 at 9:48 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

OK, sounds good.

Just a side-note. Andres has pushed the fix for the GinIs* macros as
af4472bc, making patch 0003 from the last series useless now.

I'm not prepared to get very involved in this patch series since I am
not a Windows guy, but I went ahead and pushed 0001 anyway. I'm not
sure that we want to commit 0002 without a BF machine. Can anybody
help with that?

I have machine ready, waiting for animal name and secret. It will
obviously fail until we push the 0002 and 0004 though.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#56Robert Haas
robertmhaas@gmail.com
In reply to: Petr Jelinek (#55)
Re: VS 2015 support in src/tools/msvc

On Tue, Mar 29, 2016 at 11:31 AM, Petr Jelinek <petr@2ndquadrant.com> wrote:

I have machine ready, waiting for animal name and secret.

Great!

It will obviously
fail until we push the 0002 and 0004 though.

I think it would be a shame if we shipped 9.6 without MSVC 2015
support, but it'd be nice if Andrew or Magnus could do the actual
committing, 'cuz I really don't want to be responsible for breaking
the Windows build.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#57Michael Paquier
michael.paquier@gmail.com
In reply to: Robert Haas (#56)
Re: VS 2015 support in src/tools/msvc

On Wed, Mar 30, 2016 at 12:45 AM, Robert Haas <robertmhaas@gmail.com> wrote:

On Tue, Mar 29, 2016 at 11:31 AM, Petr Jelinek <petr@2ndquadrant.com> wrote:

I have machine ready, waiting for animal name and secret.

Great!

Nice. Thanks.

It will obviously
fail until we push the 0002 and 0004 though.

I think it would be a shame if we shipped 9.6 without MSVC 2015
support, but it'd be nice if Andrew or Magnus could do the actual
committing, 'cuz I really don't want to be responsible for breaking
the Windows build.

I'm fine to back you up as needed. That's not a committer guarantee,
still better than nothing I guess. And I make a specialty of looking
at VS-related bugs lately :)
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#58Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#57)
Re: VS 2015 support in src/tools/msvc

On 03/29/2016 08:48 PM, Michael Paquier wrote:

On Wed, Mar 30, 2016 at 12:45 AM, Robert Haas <robertmhaas@gmail.com> wrote:

On Tue, Mar 29, 2016 at 11:31 AM, Petr Jelinek <petr@2ndquadrant.com> wrote:

I have machine ready, waiting for animal name and secret.

Great!

Nice. Thanks.

It will obviously
fail until we push the 0002 and 0004 though.

I think it would be a shame if we shipped 9.6 without MSVC 2015
support, but it'd be nice if Andrew or Magnus could do the actual
committing, 'cuz I really don't want to be responsible for breaking
the Windows build.

I'm fine to back you up as needed. That's not a committer guarantee,
still better than nothing I guess. And I make a specialty of looking
at VS-related bugs lately :)

I am currently travelling, but my intention is to deal with the
remaining patches when I'm back home this weekend, unless someone beats
me to it.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#59Robert Haas
robertmhaas@gmail.com
In reply to: Andrew Dunstan (#58)
Re: VS 2015 support in src/tools/msvc

On Tue, Mar 29, 2016 at 9:29 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

I am currently travelling, but my intention is to deal with the remaining
patches when I'm back home this weekend, unless someone beats me to it.

Cool.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#60Andrew Dunstan
andrew@dunslane.net
In reply to: Robert Haas (#59)
Re: VS 2015 support in src/tools/msvc

On 03/29/2016 09:38 PM, Robert Haas wrote:

On Tue, Mar 29, 2016 at 9:29 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

I am currently travelling, but my intention is to deal with the remaining
patches when I'm back home this weekend, unless someone beats me to it.

Cool.

Progress report:

I have spent way too much time on this and don't have it working yet.
I'm setting up a sacrificial VM from scratch in a last ditch attempt to
get it working.

Things to note so far:

* VS2015 appears to create version 12 solution files, not version 14,
and the tools complained about version 14.
* Windows git (the successor to msysGit) apparently no longer ships
with bison and flex. So if you need those (i.e. to built from git,
not tarball) you're probably going to need to install the MsysDTK
even if you're not using its compiler.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#61Petr Jelinek
petr@2ndquadrant.com
In reply to: Andrew Dunstan (#60)
Re: VS 2015 support in src/tools/msvc

On 06/04/16 22:50, Andrew Dunstan wrote:

On 03/29/2016 09:38 PM, Robert Haas wrote:

On Tue, Mar 29, 2016 at 9:29 PM, Andrew Dunstan <andrew@dunslane.net>
wrote:

I am currently travelling, but my intention is to deal with the
remaining
patches when I'm back home this weekend, unless someone beats me to it.

Cool.

Progress report:

I have spent way too much time on this and don't have it working yet.
I'm setting up a sacrificial VM from scratch in a last ditch attempt to
get it working.

Things to note so far:

* VS2015 appears to create version 12 solution files, not version 14,
and the tools complained about version 14.
* Windows git (the successor to msysGit) apparently no longer ships
with bison and flex. So if you need those (i.e. to built from git,
not tarball) you're probably going to need to install the MsysDTK
even if you're not using its compiler.

It's fun to set it up yes. I do have the machine with buildfarm client
ready still (although now also traveling so slightly complicated to get
to it) but I didn't activate it yet as I don't want it to just report
failures forever.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#62Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Petr Jelinek (#61)
Re: VS 2015 support in src/tools/msvc

Petr Jelinek wrote:

It's fun to set it up yes. I do have the machine with buildfarm client ready
still (although now also traveling so slightly complicated to get to it) but
I didn't activate it yet as I don't want it to just report failures forever.

Maybe you should just activate it regardless, and we'll see it go from
red to green once things are good.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#63Michael Paquier
michael.paquier@gmail.com
In reply to: Petr Jelinek (#61)
Re: VS 2015 support in src/tools/msvc

On Thu, Apr 7, 2016 at 6:11 AM, Petr Jelinek <petr@2ndquadrant.com> wrote:

On 06/04/16 22:50, Andrew Dunstan wrote:

I have spent way too much time on this and don't have it working yet.
I'm setting up a sacrificial VM from scratch in a last ditch attempt to
get it working.

Things to note so far:

* VS2015 appears to create version 12 solution files, not version 14,
and the tools complained about version 14.
* Windows git (the successor to msysGit) apparently no longer ships
with bison and flex. So if you need those (i.e. to built from git,
not tarball) you're probably going to need to install the MsysDTK
even if you're not using its compiler.

It's fun to set it up yes. I do have the machine with buildfarm client ready
still (although now also traveling so slightly complicated to get to it) but
I didn't activate it yet as I don't want it to just report failures forever.

Petr, did you actually try the patches I sent? I did my tests using
the community version of Visual Studio 2015 and a full install of it.
If I am the only able to make those working, well we surely have a
problem captain.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#64Michael Paquier
michael.paquier@gmail.com
In reply to: Michael Paquier (#63)
Re: VS 2015 support in src/tools/msvc

On Thu, Apr 7, 2016 at 7:44 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Thu, Apr 7, 2016 at 6:11 AM, Petr Jelinek <petr@2ndquadrant.com> wrote:

On 06/04/16 22:50, Andrew Dunstan wrote:

I have spent way too much time on this and don't have it working yet.
I'm setting up a sacrificial VM from scratch in a last ditch attempt to
get it working.

Things to note so far:

* VS2015 appears to create version 12 solution files, not version 14,
and the tools complained about version 14.
* Windows git (the successor to msysGit) apparently no longer ships
with bison and flex. So if you need those (i.e. to built from git,
not tarball) you're probably going to need to install the MsysDTK
even if you're not using its compiler.

It's fun to set it up yes. I do have the machine with buildfarm client ready
still (although now also traveling so slightly complicated to get to it) but
I didn't activate it yet as I don't want it to just report failures forever.

Petr, did you actually try the patches I sent? I did my tests using
the community version of Visual Studio 2015 and a full install of it.
If I am the only able to make those working, well we surely have a
problem captain.

By the way, if I look at the vcxproj files generated in my case, those
are correctly with Tools=14.0 or PlatformToolSet=v140.. Perhaps not
using Win10 differs in the way things are generated.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#65Petr Jelinek
petr@2ndquadrant.com
In reply to: Michael Paquier (#64)
Re: VS 2015 support in src/tools/msvc

On 07/04/16 00:50, Michael Paquier wrote:

On Thu, Apr 7, 2016 at 7:44 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Thu, Apr 7, 2016 at 6:11 AM, Petr Jelinek <petr@2ndquadrant.com> wrote:

On 06/04/16 22:50, Andrew Dunstan wrote:

I have spent way too much time on this and don't have it working yet.
I'm setting up a sacrificial VM from scratch in a last ditch attempt to
get it working.

Things to note so far:

* VS2015 appears to create version 12 solution files, not version 14,
and the tools complained about version 14.
* Windows git (the successor to msysGit) apparently no longer ships
with bison and flex. So if you need those (i.e. to built from git,
not tarball) you're probably going to need to install the MsysDTK
even if you're not using its compiler.

It's fun to set it up yes. I do have the machine with buildfarm client ready
still (although now also traveling so slightly complicated to get to it) but
I didn't activate it yet as I don't want it to just report failures forever.

Petr, did you actually try the patches I sent? I did my tests using
the community version of Visual Studio 2015 and a full install of it.
If I am the only able to make those working, well we surely have a
problem captain.

By the way, if I look at the vcxproj files generated in my case, those
are correctly with Tools=14.0 or PlatformToolSet=v140.. Perhaps not
using Win10 differs in the way things are generated.

I have community edition on win10 as well, worked fine there yes, I used
just the command-line tools from it.

VS2015 creates version 12 solution only before the patches are applied
for me, once they are applied it works fine.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#66Christian Ullrich
chris@chrullrich.net
In reply to: Petr Jelinek (#65)
Re: VS 2015 support in src/tools/msvc

* Petr Jelinek wrote:

On 07/04/16 00:50, Michael Paquier wrote:

On Thu, Apr 7, 2016 at 7:44 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Thu, Apr 7, 2016 at 6:11 AM, Petr Jelinek <petr@2ndquadrant.com>
wrote:

On 06/04/16 22:50, Andrew Dunstan wrote:

* VS2015 appears to create version 12 solution files, not
version 14, and the tools complained about version 14.

The "14" is the toolset version, i.e. the Visual Studio 2015 C/C++
compiler; this number appears in the .vcxproj files. The "12" is the
file format version of the solution (.sln) files.

There are quite a few version numbers involved. Creating and building a
C project in VS 2015 involves a solution file of version 12 referencing
a project file whose only version number is the 2003 in the XML
namespace URL, feeding it to MSBuild version 14, which then invokes the
compiler (in version 19). And then there is the <PlatformToolset>
element, where the 14 is repeated as "v140", at least, I think it is the
same number.

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#67Andrew Dunstan
andrew@dunslane.net
In reply to: Andrew Dunstan (#60)
1 attachment(s)
Re: VS 2015 support in src/tools/msvc

On 04/06/2016 04:50 PM, Andrew Dunstan wrote:

On 03/29/2016 09:38 PM, Robert Haas wrote:

On Tue, Mar 29, 2016 at 9:29 PM, Andrew Dunstan <andrew@dunslane.net>
wrote:

I am currently travelling, but my intention is to deal with the
remaining
patches when I'm back home this weekend, unless someone beats me to it.

Cool.

Progress report:

I have spent way too much time on this and don't have it working yet.
I'm setting up a sacrificial VM from scratch in a last ditch attempt
to get it working.

Things to note so far:

* VS2015 appears to create version 12 solution files, not version 14,
and the tools complained about version 14.
* Windows git (the successor to msysGit) apparently no longer ships
with bison and flex. So if you need those (i.e. to built from git,
not tarball) you're probably going to need to install the MsysDTK
even if you're not using its compiler.

Not out of the woods yet. Attached is what I got from VS2015 on a fresh
W10 VM, with Michael's patch 0002 and 0004 applied.

cheers

andrew

Attachments:

vs2015.error_logtext/plain; charset=UTF-8; name=vs2015.error_logDownload
#68Michael Paquier
michael.paquier@gmail.com
In reply to: Andrew Dunstan (#67)
Re: VS 2015 support in src/tools/msvc

On Fri, Apr 8, 2016 at 9:29 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

Not out of the woods yet. Attached is what I got from VS2015 on a fresh W10
VM, with Michael's patch 0002 and 0004 applied.

Interesting, I have no idea what we are doing differently, and seeing
those errors it seems to me that Petr and I are actually getting it
wrong for some reason, because GetLocaleInfoEx should need a direct
declaration of windows.h. And similarly to some of the other files in
src/port I think that we should have it. Do you still get failures if
you add the following thing at the top of chklocale.c?

#if defined(WIN32) && (_MSC_VER >= 1900)
#include "windows.h"
#endif

Looking at the docs
(https://msdn.microsoft.com/en-us/library/windows/desktop/dd318103%28v=vs.85%29.aspx),
winnls.h would be enough, but I'd rather be consistent with the
approach taken by the other files.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#69Christian Ullrich
chris@chrullrich.net
In reply to: Michael Paquier (#68)
Re: VS 2015 support in src/tools/msvc

* Michael Paquier wrote:

On Fri, Apr 8, 2016 at 9:29 AM, Andrew Dunstan <andrew@dunslane.net>
wrote:

Not out of the woods yet. Attached is what I got from VS2015 on a fresh W10
VM, with Michael's patch 0002 and 0004 applied.

Interesting, I have no idea what we are doing differently, and seeing
those errors it seems to me that Petr and I are actually getting it
wrong for some reason, because GetLocaleInfoEx should need a direct
declaration of windows.h. And similarly to some of the other files in
src/port I think that we should have it. Do you still get failures if
you add the following thing at the top of chklocale.c?

#if defined(WIN32) && (_MSC_VER >= 1900)
#include "windows.h"
#endif

Looking at the docs
(https://msdn.microsoft.com/en-us/library/windows/desktop/dd318103%28v=vs.85%29.aspx),
winnls.h would be enough, but I'd rather be consistent with the
approach taken by the other files.

GetLocaleInfoEx() is covered by #if (WINVER >= 0x0600), we define
_WIN32_WINNT as 0x0501 (src/include/port/win32.h) and WINVER inherits
that value.

Michael, none of your patches change this, so how does it ever build on
your system?

MSDN also says this about the function: "Header: winnls.h (include
windows.h)"; so there's probably something else needed to make it work
that is not in <winnls.h> alone.

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#70Andrew Dunstan
andrew@dunslane.net
In reply to: Christian Ullrich (#69)
Re: VS 2015 support in src/tools/msvc

On 04/08/2016 07:15 AM, Christian Ullrich wrote:

* Michael Paquier wrote:

On Fri, Apr 8, 2016 at 9:29 AM, Andrew Dunstan <andrew@dunslane.net>
wrote:

Not out of the woods yet. Attached is what I got from VS2015 on a
fresh W10
VM, with Michael's patch 0002 and 0004 applied.

Interesting, I have no idea what we are doing differently, and seeing
those errors it seems to me that Petr and I are actually getting it
wrong for some reason, because GetLocaleInfoEx should need a direct
declaration of windows.h. And similarly to some of the other files in
src/port I think that we should have it. Do you still get failures if
you add the following thing at the top of chklocale.c?

#if defined(WIN32) && (_MSC_VER >= 1900)
#include "windows.h"
#endif

Looking at the docs
(https://msdn.microsoft.com/en-us/library/windows/desktop/dd318103%28v=vs.85%29.aspx),

winnls.h would be enough, but I'd rather be consistent with the
approach taken by the other files.

GetLocaleInfoEx() is covered by #if (WINVER >= 0x0600), we define
_WIN32_WINNT as 0x0501 (src/include/port/win32.h) and WINVER inherits
that value.

Michael, none of your patches change this, so how does it ever build
on your system?

MSDN also says this about the function: "Header: winnls.h (include
windows.h)"; so there's probably something else needed to make it work
that is not in <winnls.h> alone.

OK, at this stage it appears to me that if today is the deadline for
getting this in for 9.6 then it's going to be missed.

And no, Michael's suggested inclusion didn't help, probably for the
reasons Christian suggests.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#71Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#70)
Re: VS 2015 support in src/tools/msvc

Andrew Dunstan <andrew@dunslane.net> writes:

OK, at this stage it appears to me that if today is the deadline for
getting this in for 9.6 then it's going to be missed.

It would be unfortunate to go another year without support for that
toolchain. My suggestion is that you continue to work away on the
problem, and when you have something that passes your testing, you
present it to -hackers and we can decide then whether it's too invasive
for a post-feature-freeze patch.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#72Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#71)
Re: VS 2015 support in src/tools/msvc

On 04/08/2016 09:52 AM, Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

OK, at this stage it appears to me that if today is the deadline for
getting this in for 9.6 then it's going to be missed.

It would be unfortunate to go another year without support for that
toolchain. My suggestion is that you continue to work away on the
problem, and when you have something that passes your testing, you
present it to -hackers and we can decide then whether it's too invasive
for a post-feature-freeze patch.

OK. Michael just told me in IM that he thinks he has a fix, so we'll see.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#73Michael Paquier
michael.paquier@gmail.com
In reply to: Andrew Dunstan (#70)
2 attachment(s)
Re: VS 2015 support in src/tools/msvc

On Fri, Apr 8, 2016 at 10:05 PM, Andrew Dunstan <andrew@dunslane.net> wrote:
¥> On 04/08/2016 07:15 AM, Christian Ullrich wrote:

GetLocaleInfoEx() is covered by #if (WINVER >= 0x0600), we define
_WIN32_WINNT as 0x0501 (src/include/port/win32.h) and WINVER inherits that
value.

Yes, I had a look at winnls.h and that's true.

Michael, none of your patches change this, so how does it ever build on
your system?

Luck. I am getting a warning but the code is able to somewhat compile:
src/port/chklocale.c(230): warning C4013: 'GetLocaleInfoEx'
undefined; assuming extern returning int
[C:\Users\IEUser\git\postgres\libpgport.vcxproj]
But that's clearly incorrect to get that. As you are saying, what we
actually just need to do is bumping _WIN32_WINNT to 0x0600 when
compiling with VS2015, meaning that the minimum build requirement for
Postgres with VS2015 would be Windows Vista, and it would not be
possible to compile it on XP or Windows server 2k3. As XP is already
out of support, I think that this is an acceptable tradeoff, and it
would still be possible to build Postgres on XP with older versions of
Visual. Thoughts?

OK, at this stage it appears to me that if today is the deadline for getting
this in for 9.6 then it's going to be missed.

Really? I thought that new VS support were done on HEAD and the last
stable version, aka 9.5 here. This was what was done previously for
VS2012 and VS2013.

And no, Michael's suggested inclusion didn't help, probably for the reasons
Christian suggests.

Yes.

List of _WIN32_WINNT is here:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745%28v=vs.85%29.aspx
And here is the compatibility grid of VS2015 with existing Windows OSes:
https://www.visualstudio.com/en-us/products/visual-studio-2015-compatibility-vs.aspx

Anyway, attached are updated patches. This makes the warning go away
from my side, so I guess that it should allow Andrew to compile the
code.
--
Michael

Attachments:

0001-Add-support-for-VS-2015-in-MSVC-scripts.patchinvalid/octet-stream; name=0001-Add-support-for-VS-2015-in-MSVC-scripts.patchDownload
From 37846b5825affe680cce2632deedb473a75d3435 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Wed, 23 Mar 2016 15:05:22 +0900
Subject: [PATCH 1/2] Add support for VS 2015 in MSVC scripts

One can use that to compile with the latest version of Visual Studio
on Windows.
---
 doc/src/sgml/install-windows.sgml |  8 ++++----
 src/tools/msvc/MSBuildProject.pm  | 23 +++++++++++++++++++++++
 src/tools/msvc/Solution.pm        | 26 ++++++++++++++++++++++++++
 src/tools/msvc/VSObjectFactory.pm | 12 ++++++++++--
 4 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index 9360383..a62aa49 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -19,10 +19,10 @@
  <para>
   There are several different ways of building PostgreSQL on
   <productname>Windows</productname>. The simplest way to build with
-  Microsoft tools is to install <productname>Visual Studio Express 2013
+  Microsoft tools is to install <productname>Visual Studio Express 2015
   for Windows Desktop</productname> and use the included
   compiler. It is also possible to build with the full
-  <productname>Microsoft Visual C++ 2005 to 2013</productname>.
+  <productname>Microsoft Visual C++ 2005 to 2015</productname>.
   In some cases that requires the installation of the
   <productname>Windows SDK</productname> in addition to the compiler.
  </para>
@@ -77,7 +77,7 @@
   <productname>Visual Studio Express</productname> or some versions of the
   <productname>Microsoft Windows SDK</productname>. If you do not already have a
   <productname>Visual Studio</productname> environment set up, the easiest
-  ways are to use the compilers from <productname>Visual Studio Express 2013
+  ways are to use the compilers from <productname>Visual Studio Express 2015
   for Windows Desktop</productname> or those in the <productname>Windows SDK
   7.1</productname>, which are both free downloads from Microsoft.
  </para>
@@ -85,7 +85,7 @@
  <para>
   PostgreSQL is known to support compilation using the compilers shipped with
   <productname>Visual Studio 2005</productname> to
-  <productname>Visual Studio 2013</productname> (including Express editions),
+  <productname>Visual Studio 2015</productname> (including Express editions),
   as well as standalone Windows SDK releases 6.0 to 7.1.
   64-bit PostgreSQL builds are only supported with
   <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 3d60b64..d7638b4 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -465,4 +465,27 @@ sub new
 	return $self;
 }
 
+package VC2015Project;
+
+#
+# Package that encapsulates a Visual C++ 2015 project file
+#
+
+use strict;
+use warnings;
+use base qw(VC2012Project);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{vcver}           = '14.00';
+	$self->{PlatformToolset} = 'v140';
+	$self->{ToolsVersion}    = '14.0';
+
+	return $self;
+}
+
 1;
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index ac1ba0a..2b21bf0 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -790,6 +790,32 @@ sub new
 	return $self;
 }
 
+package VS2015Solution;
+
+#
+# Package that encapsulates a Visual Studio 2015 solution file
+#
+
+use Carp;
+use strict;
+use warnings;
+use base qw(Solution);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{solutionFileVersion}        = '14.00';
+	$self->{vcver}                      = '14.00';
+	$self->{visualStudioName}           = 'Visual Studio 2015';
+	$self->{VisualStudioVersion}        = '14.0.24730.2';
+	$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
+
+	return $self;
+}
+
 sub GetAdditionalHeaders
 {
 	my ($self, $f) = @_;
diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm
index fee4684..4190ada 100644
--- a/src/tools/msvc/VSObjectFactory.pm
+++ b/src/tools/msvc/VSObjectFactory.pm
@@ -49,6 +49,10 @@ sub CreateSolution
 	{
 		return new VS2013Solution(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VS2015Solution(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -84,6 +88,10 @@ sub CreateProject
 	{
 		return new VC2013Project(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VC2015Project(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion
 sub _GetVisualStudioVersion
 {
 	my ($major, $minor) = @_;
-	if ($major > 12)
+	if ($major > 14)
 	{
 		carp
 "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
-		return '12.00';
+		return '14.00';
 	}
 	elsif ($major < 6)
 	{
-- 
2.8.1

0002-Fix-code-page-calculation-for-Visual-Studio-2015.patchinvalid/octet-stream; name=0002-Fix-code-page-calculation-for-Visual-Studio-2015.patchDownload
From f734cf3139e79ffcbbe0553ea291b58ec4fee967 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Fri, 8 Apr 2016 23:08:56 +0900
Subject: [PATCH 2/2] Fix code page calculation for Visual Studio 2015

Visual Studio 2015 is missing the declaration of field lc_codepage in
_locale_t, causing the existing code, introduced with VS 2012 to become
incompatible and causing compilation failures. This patch changes the
code path a bit so as GetLocaleInfoEx is used to fetch a code page
where available when compiling the code with VS2015, note that this
is compatible only with Windows 2k8/Vista and newer versions but it is
unlikely that a version of Postgres compiled with VS2015 would run on
platforms older than that, Windows XP being already out of support.

_WIN32_WINNT needs to be bumped so as the minimum version of Windows
supported when compiling the code with Visual Studio is Vista, which
should be fine knowing that XP is already out of support.
---
 src/include/port/win32.h | 11 +++++++++--
 src/port/chklocale.c     | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/src/include/port/win32.h b/src/include/port/win32.h
index 69cd1c4..d939206 100644
--- a/src/include/port/win32.h
+++ b/src/include/port/win32.h
@@ -6,14 +6,21 @@
 
 /*
  * Make sure _WIN32_WINNT has the minimum required value.
- * Leave a higher value in place.
-*/
+ * Leave a higher value in place. When building with at least Visual
+ * Studio 2015 the minimum requirement is Windows Vista (0x0600) to
+ * get support for GetLocaleInfoEx() with locales.
+ */
 #if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0501
 #undef _WIN32_WINNT
 #endif
 #ifndef _WIN32_WINNT
+#if defined (_MSC_VER >= 1900)
+#define _WIN32_WINNT 0x0600
+#else
 #define _WIN32_WINNT 0x0501
 #endif
+#endif /* _WIN32_WINNT */
+
 /*
  * Always build with SSPI support. Keep it as a #define in case
  * we want a switch to disable it sometime in the future.
diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..4a7a265 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -19,6 +19,10 @@
 #include "postgres_fe.h"
 #endif
 
+#if defined(WIN32) && (_MSC_VER >= 1900)
+#include <windows.h>
+#endif
+
 #include <locale.h>
 #ifdef HAVE_LANGINFO_H
 #include <langinfo.h>
@@ -196,6 +200,12 @@ static const struct encoding_match encoding_match_list[] = {
  * locale machinery determine the code page.  See comments at IsoLocaleName().
  * For other compilers, follow the locale's predictable format.
  *
+ * Visual Studio 2015 should still be able to do the same, but the declaration
+ * of lc_codepage is missing in _locale_t, causing this code compilation to
+ * fail, hence this falls back instead on GetLocaleInfoEx. VS 2015 may be an
+ * exception and post-VS2015 versions should be able to handle properly the
+ * codepage number using _create_locale().
+ *
  * Returns a malloc()'d string for the caller to free.
  */
 static char *
@@ -203,7 +213,7 @@ win32_langinfo(const char *ctype)
 {
 	char	   *r = NULL;
 
-#if (_MSC_VER >= 1700)
+#if (_MSC_VER >= 1700) && (_MSC_VER < 1900)
 	_locale_t	loct = NULL;
 
 	loct = _create_locale(LC_CTYPE, ctype);
@@ -215,8 +225,24 @@ win32_langinfo(const char *ctype)
 		_free_locale(loct);
 	}
 #else
+
 	char	   *codepage;
 
+#if (_MSC_VER >= 1900)
+	uint32	cp;
+
+	if (GetLocaleInfoEx(ctype,
+			LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
+			(LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0)
+	{
+		r = malloc(16);			/* excess */
+		if (r != NULL)
+			sprintf(r, "CP%u", cp);
+	}
+	else
+	{
+#endif
+
 	/*
 	 * Locale format on Win32 is <Language>_<Country>.<CodePage> . For
 	 * example, English_United States.1252.
@@ -232,6 +258,10 @@ win32_langinfo(const char *ctype)
 		if (r != NULL)
 			sprintf(r, "CP%s", codepage);
 	}
+
+#if (_MSC_VER >= 1900)
+	}
+#endif
 #endif
 
 	return r;
-- 
2.8.1

#74Magnus Hagander
magnus@hagander.net
In reply to: Michael Paquier (#73)
Re: VS 2015 support in src/tools/msvc

On Fri, Apr 8, 2016 at 4:12 PM, Michael Paquier <michael.paquier@gmail.com>
wrote:

On Fri, Apr 8, 2016 at 10:05 PM, Andrew Dunstan <andrew@dunslane.net>
wrote:
¥> On 04/08/2016 07:15 AM, Christian Ullrich wrote:

GetLocaleInfoEx() is covered by #if (WINVER >= 0x0600), we define
_WIN32_WINNT as 0x0501 (src/include/port/win32.h) and WINVER inherits

that

value.

Yes, I had a look at winnls.h and that's true.

Michael, none of your patches change this, so how does it ever build on
your system?

Luck. I am getting a warning but the code is able to somewhat compile:
src/port/chklocale.c(230): warning C4013: 'GetLocaleInfoEx'
undefined; assuming extern returning int
[C:\Users\IEUser\git\postgres\libpgport.vcxproj]
But that's clearly incorrect to get that. As you are saying, what we
actually just need to do is bumping _WIN32_WINNT to 0x0600 when
compiling with VS2015, meaning that the minimum build requirement for
Postgres with VS2015 would be Windows Vista, and it would not be
possible to compile it on XP or Windows server 2k3. As XP is already
out of support, I think that this is an acceptable tradeoff, and it
would still be possible to build Postgres on XP with older versions of
Visual. Thoughts?

I think that's easily acceptable for the build system, as long as we
document it clearly.

I think it would probalby be a bad idea to use those binaries in our binary
installers though, but that's a different discussion really. We have other
compiler flags that we don't recommend for that :)

//Magnus

#75Christian Ullrich
chris@chrullrich.net
In reply to: Michael Paquier (#73)
Re: VS 2015 support in src/tools/msvc

* Michael Paquier wrote:

On Fri, Apr 8, 2016 at 10:05 PM, Andrew Dunstan <andrew@dunslane.net> wrote:
¥> On 04/08/2016 07:15 AM, Christian Ullrich wrote:

Michael, none of your patches change this, so how does it ever build on
your system?

Luck. I am getting a warning but the code is able to somewhat compile:
src/port/chklocale.c(230): warning C4013: 'GetLocaleInfoEx'
undefined; assuming extern returning int
[C:\Users\IEUser\git\postgres\libpgport.vcxproj]

Weird. This assumed declaration is __cdecl, the actual function is
__stdcall, and I think this should be guaranteed to crash.

But that's clearly incorrect to get that. As you are saying, what we
actually just need to do is bumping _WIN32_WINNT to 0x0600 when
compiling with VS2015, meaning that the minimum build requirement for
Postgres with VS2015 would be Windows Vista, and it would not be
possible to compile it on XP or Windows server 2k3. As XP is already
out of support, I think that this is an acceptable tradeoff, and it
would still be possible to build Postgres on XP with older versions of
Visual. Thoughts?

I think you confuse two things here, let's call them "build environment"
and "build platform". The build environment is whichever Windows SDK
(among other things) is installed; if it is a version for Vista or
later, that just means it has the declaration in the first place, and
has the import in kernel32.lib. The build platform is the OS the
compiler is run on; as long as you find a compiler that understands the
headers from your chosen SDK version, you can run it on Windows 95 if
both of you want.

Changing _WIN32_WINNT also affects, indirectly, on which platforms the
resulting binaries can run. Assume a macro that has an alternative
definition, conditioned on _WIN32_WINNT >= _WIN32_WINNT_VISTA, that uses
a function added in Vista. A binary built using this declaration, no
matter where and when, will not run on anything older.

Anyway, attached are updated patches. This makes the warning go away
from my side, so I guess that it should allow Andrew to compile the
code.

Which brings us to the next problem:

src/port/chklocale.c(233): warning C4133: 'function': incompatible
types - from 'const char *' to 'LPCWSTR' [...\postgres.vcxproj]

I have no idea why I get this warning; I would have expected something
more like this:

localetest.cpp(26): error C2664: 'int
GetLocaleInfoEx(LPCWSTR,LCTYPE,LPWSTR,int)': cannot convert
argument 1 from 'const char *' to 'LPCWSTR'

Apparently the warning is triggered by type mismatches in pointer
arithmetic, although I can't see any here. Anyway, it concerns the first
argument in this call to GetLocaleInfoEx(), which here is a const char*.

According to the documentation and the prototype, however, it should be
an LPCWSTR, because this function is Unicode-only (has no A/W variants).
Unless LOCALE_IDEFAULTANSICODEPAGE also changes the interpretation of
this first argument to a single-byte string, which is not mentioned
anywhere in the documentation and makes no sense to begin with, I don't
think this has ever worked either.

I just tested it, and, of course, if I pass '(LPCWSTR)"de-DE"' (narrow
string cast to LPCWSTR), the call fails with ERROR_INVALID_PARAMETER.
With a wide string, I get the correct code page for the locale.

Also, while you're at it, could you improve the comments a bit? I have
not yet tried following the code to see which locale formats it uses
where ("German_Germany", "de-DE", etc.), but GetLocaleInfoEx() takes the
short form and there is a comment about the long form right below that
call once patched (in the old code that gets turned into an else branch).

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#76Andrew Dunstan
andrew@dunslane.net
In reply to: Christian Ullrich (#75)
Re: VS 2015 support in src/tools/msvc

On 04/08/2016 11:02 AM, Christian Ullrich wrote:

* Michael Paquier wrote:

On Fri, Apr 8, 2016 at 10:05 PM, Andrew Dunstan <andrew@dunslane.net>
wrote:
¥> On 04/08/2016 07:15 AM, Christian Ullrich wrote:

Michael, none of your patches change this, so how does it ever
build on
your system?

Luck. I am getting a warning but the code is able to somewhat compile:
src/port/chklocale.c(230): warning C4013: 'GetLocaleInfoEx'
undefined; assuming extern returning int
[C:\Users\IEUser\git\postgres\libpgport.vcxproj]

Weird. This assumed declaration is __cdecl, the actual function is
__stdcall, and I think this should be guaranteed to crash.

But that's clearly incorrect to get that. As you are saying, what we
actually just need to do is bumping _WIN32_WINNT to 0x0600 when
compiling with VS2015, meaning that the minimum build requirement for
Postgres with VS2015 would be Windows Vista, and it would not be
possible to compile it on XP or Windows server 2k3. As XP is already
out of support, I think that this is an acceptable tradeoff, and it
would still be possible to build Postgres on XP with older versions of
Visual. Thoughts?

I think you confuse two things here, let's call them "build
environment" and "build platform". The build environment is whichever
Windows SDK (among other things) is installed; if it is a version for
Vista or later, that just means it has the declaration in the first
place, and has the import in kernel32.lib. The build platform is the
OS the compiler is run on; as long as you find a compiler that
understands the headers from your chosen SDK version, you can run it
on Windows 95 if both of you want.

Changing _WIN32_WINNT also affects, indirectly, on which platforms the
resulting binaries can run. Assume a macro that has an alternative
definition, conditioned on _WIN32_WINNT >= _WIN32_WINNT_VISTA, that
uses a function added in Vista. A binary built using this declaration,
no matter where and when, will not run on anything older.

Anyway, attached are updated patches. This makes the warning go away
from my side, so I guess that it should allow Andrew to compile the
code.

Which brings us to the next problem:

src/port/chklocale.c(233): warning C4133: 'function': incompatible
types - from 'const char *' to 'LPCWSTR' [...\postgres.vcxproj]

I have no idea why I get this warning; I would have expected something
more like this:

localetest.cpp(26): error C2664: 'int
GetLocaleInfoEx(LPCWSTR,LCTYPE,LPWSTR,int)': cannot convert
argument 1 from 'const char *' to 'LPCWSTR'

Apparently the warning is triggered by type mismatches in pointer
arithmetic, although I can't see any here. Anyway, it concerns the
first argument in this call to GetLocaleInfoEx(), which here is a
const char*.

According to the documentation and the prototype, however, it should
be an LPCWSTR, because this function is Unicode-only (has no A/W
variants). Unless LOCALE_IDEFAULTANSICODEPAGE also changes the
interpretation of this first argument to a single-byte string, which
is not mentioned anywhere in the documentation and makes no sense to
begin with, I don't think this has ever worked either.

I just tested it, and, of course, if I pass '(LPCWSTR)"de-DE"' (narrow
string cast to LPCWSTR), the call fails with ERROR_INVALID_PARAMETER.
With a wide string, I get the correct code page for the locale.

Also, while you're at it, could you improve the comments a bit? I have
not yet tried following the code to see which locale formats it uses
where ("German_Germany", "de-DE", etc.), but GetLocaleInfoEx() takes
the short form and there is a comment about the long form right below
that call once patched (in the old code that gets turned into an else
branch).

OK, well, we're making progress. I can confirm that using _WIN32_WINNT =
0x0600 fixes my problems - I can build and run the regression tests. I'm
inclined to define _WINSOCK_DEPRECATED_NO_WARNINGS to silence a few
compiler bleatings.

Do you have a fix for the LPCWSTR parameter issue?

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#77Christian Ullrich
chris@chrullrich.net
In reply to: Andrew Dunstan (#76)
Re: VS 2015 support in src/tools/msvc

* Andrew Dunstan wrote:

On 04/08/2016 11:02 AM, Christian Ullrich wrote:

src/port/chklocale.c(233): warning C4133: 'function': incompatible
types - from 'const char *' to 'LPCWSTR' [...\postgres.vcxproj]

Do you have a fix for the LPCWSTR parameter issue?

As long as the locale short name cannot contain characters outside of
ASCII, and I don't see how it could, just the typical
measure-allocate-convert dance, add error handling to taste:

int res = MultiByteToWideChar(CP_ACP, 0, ctype, -1, NULL, 0);
WCHAR *wctype = malloc(res * sizeof(WCHAR));
memset(wctype, 0, res * sizeof(WCHAR));
res = MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, wctypelen);

If it is somehow guaranteed that ctype is only the most basic short name
("xx-YY") with no code pages or anything, it becomes much simpler, of
course, and I would just use a loop.

If the locale name can contain characters above 0x7f, we'd have to know
the code page of the string we use to get the code page.

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#78Michael Paquier
michael.paquier@gmail.com
In reply to: Christian Ullrich (#77)
Re: VS 2015 support in src/tools/msvc

On Sat, Apr 9, 2016 at 1:46 AM, Christian Ullrich <chris@chrullrich.net> wrote:

* Andrew Dunstan wrote:

On 04/08/2016 11:02 AM, Christian Ullrich wrote:

src/port/chklocale.c(233): warning C4133: 'function': incompatible
types - from 'const char *' to 'LPCWSTR' [...\postgres.vcxproj]

Do you have a fix for the LPCWSTR parameter issue?

As long as the locale short name cannot contain characters outside of ASCII,
and I don't see how it could, just the typical measure-allocate-convert
dance, add error handling to taste:

int res = MultiByteToWideChar(CP_ACP, 0, ctype, -1, NULL, 0);
WCHAR *wctype = malloc(res * sizeof(WCHAR));
memset(wctype, 0, res * sizeof(WCHAR));
res = MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, wctypelen);

If it is somehow guaranteed that ctype is only the most basic short name
("xx-YY") with no code pages or anything, it becomes much simpler, of
course, and I would just use a loop.

If the locale name can contain characters above 0x7f, we'd have to know the
code page of the string we use to get the code page.

Could somebody give a try instead of me? I could take a look on it,
but just in 12 hours or so, aka after the deadline if that matters for
this patch.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#79Petr Jelinek
petr@2ndquadrant.com
In reply to: Michael Paquier (#78)
Re: VS 2015 support in src/tools/msvc

On 09/04/16 00:41, Michael Paquier wrote:

On Sat, Apr 9, 2016 at 1:46 AM, Christian Ullrich <chris@chrullrich.net> wrote:

* Andrew Dunstan wrote:

On 04/08/2016 11:02 AM, Christian Ullrich wrote:

src/port/chklocale.c(233): warning C4133: 'function': incompatible
types - from 'const char *' to 'LPCWSTR' [...\postgres.vcxproj]

Do you have a fix for the LPCWSTR parameter issue?

As long as the locale short name cannot contain characters outside of ASCII,
and I don't see how it could, just the typical measure-allocate-convert
dance, add error handling to taste:

int res = MultiByteToWideChar(CP_ACP, 0, ctype, -1, NULL, 0);
WCHAR *wctype = malloc(res * sizeof(WCHAR));
memset(wctype, 0, res * sizeof(WCHAR));
res = MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, wctypelen);

If it is somehow guaranteed that ctype is only the most basic short name
("xx-YY") with no code pages or anything, it becomes much simpler, of
course, and I would just use a loop.

If the locale name can contain characters above 0x7f, we'd have to know the
code page of the string we use to get the code page.

Could somebody give a try instead of me? I could take a look on it,
but just in 12 hours or so, aka after the deadline if that matters for
this patch.

I won't be able to get back to it (well mainly to windows environment)
till Thursday due to travel, sorry.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#80Michael Paquier
michael.paquier@gmail.com
In reply to: Michael Paquier (#78)
Re: VS 2015 support in src/tools/msvc

On Sat, Apr 9, 2016 at 7:41 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Sat, Apr 9, 2016 at 1:46 AM, Christian Ullrich <chris@chrullrich.net> wrote:

* Andrew Dunstan wrote:

On 04/08/2016 11:02 AM, Christian Ullrich wrote:

src/port/chklocale.c(233): warning C4133: 'function': incompatible
types - from 'const char *' to 'LPCWSTR' [...\postgres.vcxproj]

Do you have a fix for the LPCWSTR parameter issue?

As long as the locale short name cannot contain characters outside of ASCII,
and I don't see how it could, just the typical measure-allocate-convert
dance, add error handling to taste:

int res = MultiByteToWideChar(CP_ACP, 0, ctype, -1, NULL, 0);
WCHAR *wctype = malloc(res * sizeof(WCHAR));
memset(wctype, 0, res * sizeof(WCHAR));
res = MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, wctypelen);

I don't think that's good to use malloc in those code paths, and I
think that we cannot use palloc as well for a buffer passed directly
into this function, so it looks that we had better use a fix-sized
buffer and allocate the output into that. What would be a a correct
estimation of the maximum size we should allow? 80 (similar to
pg_locale.c)?
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#81Christian Ullrich
chris@chrullrich.net
In reply to: Michael Paquier (#80)
Re: VS 2015 support in src/tools/msvc

Michael Paquier wrote:

On Sat, Apr 9, 2016 at 7:41 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Sat, Apr 9, 2016 at 1:46 AM, Christian Ullrich <chris@chrullrich.net> wrote:

* Andrew Dunstan wrote:

On 04/08/2016 11:02 AM, Christian Ullrich wrote:
src/port/chklocale.c(233): warning C4133: 'function': incompatible
types - from 'const char *' to 'LPCWSTR' [...\postgres.vcxproj]

Do you have a fix for the LPCWSTR parameter issue?

As long as the locale short name cannot contain characters outside of ASCII,
and I don't see how it could, just the typical measure-allocate-convert
dance, add error handling to taste:

int res = MultiByteToWideChar(CP_ACP, 0, ctype, -1, NULL, 0);
WCHAR *wctype = malloc(res * sizeof(WCHAR));
memset(wctype, 0, res * sizeof(WCHAR));
res = MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, wctypelen);

I don't think that's good to use malloc in those code paths, and I
think that we cannot use palloc as well for a buffer passed directly
into this function, so it looks that we had better use a fix-sized
buffer and allocate the output into that. What would be a a correct
estimation of the maximum size we should allow? 80 (similar to
pg_locale.c)?

I think it should not take more than 16 characters, but if you want to make sure the code can deal with long names as well, MSDN gives an upper limit of 85 for those somewhere.

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#82Andrew Dunstan
andrew@dunslane.net
In reply to: Christian Ullrich (#81)
Re: VS 2015 support in src/tools/msvc

On 04/09/2016 08:43 AM, Christian Ullrich wrote:

Michael Paquier wrote:

On Sat, Apr 9, 2016 at 7:41 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Sat, Apr 9, 2016 at 1:46 AM, Christian Ullrich <chris@chrullrich.net> wrote:

* Andrew Dunstan wrote:

On 04/08/2016 11:02 AM, Christian Ullrich wrote:
src/port/chklocale.c(233): warning C4133: 'function': incompatible
types - from 'const char *' to 'LPCWSTR' [...\postgres.vcxproj]

Do you have a fix for the LPCWSTR parameter issue?

As long as the locale short name cannot contain characters outside of ASCII,
and I don't see how it could, just the typical measure-allocate-convert
dance, add error handling to taste:

int res = MultiByteToWideChar(CP_ACP, 0, ctype, -1, NULL, 0);
WCHAR *wctype = malloc(res * sizeof(WCHAR));
memset(wctype, 0, res * sizeof(WCHAR));
res = MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, wctypelen);

I don't think that's good to use malloc in those code paths, and I
think that we cannot use palloc as well for a buffer passed directly
into this function, so it looks that we had better use a fix-sized
buffer and allocate the output into that. What would be a a correct
estimation of the maximum size we should allow? 80 (similar to
pg_locale.c)?

I think it should not take more than 16 characters, but if you want to make sure the code can deal with long names as well, MSDN gives an upper limit of 85 for those somewhere.

I don't think we need to be too precious about saving a byte or two
here. Can one or other of you please prepare a replacement patch based
in this discussion?

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#83Christian Ullrich
chris@chrullrich.net
In reply to: Andrew Dunstan (#82)
Re: VS 2015 support in src/tools/msvc

* Andrew Dunstan:

On 04/09/2016 08:43 AM, Christian Ullrich wrote:

Michael Paquier wrote:

I don't think that's good to use malloc in those code paths, and I

Oh?

+#if (_MSC_VER >= 1900)
+	uint32	cp;
+
+	if (GetLocaleInfoEx(ctype,
+			LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
+			(LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0)
+	{
+		r = malloc(16);			/* excess */
+		if (r != NULL)
+			sprintf(r, "CP%u", cp);
+	}
+	else
+	{
+#endif

I don't think we need to be too precious about saving a byte or two
here. Can one or other of you please prepare a replacement patch based
in this discussion?

Sorry, I don't think I'm up to that (at least not for another week or
so). I have to read up on the issue first; right now I'm not sure what
exactly the problem is.

What I can say is that the existing patch needs more work, because
GetLocaleInfoEx() expects a locale name ("de-DE") as its first argument,
but the patched win32_langinfo() is giving it a locale identifier
("German_Germany.1252"). At least it does for me.

I have not gone through the code sufficiently closely to find out where
the argument to win32_langinfo() originates, but I will when I can.

As for missing code page information in the _locale_t type, ISTM it
isn't hidden any better in UCRT than it was before:

int main()
{
/* Set locale with nonstandard code page */
_locale_t loc = _create_locale(LC_ALL, "German_Germany.850");

__crt_locale_data_public* pub =
(__crt_locale_data_public*)(loc->locinfo);
printf("CP: %d\n", pub->_locale_lc_codepage); // "CP: 850"
return 0;
}

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#84Petr Jelinek
petr@2ndquadrant.com
In reply to: Christian Ullrich (#83)
Re: VS 2015 support in src/tools/msvc

On 10/04/16 20:47, Christian Ullrich wrote:

* Andrew Dunstan:

On 04/09/2016 08:43 AM, Christian Ullrich wrote:

Michael Paquier wrote:

I don't think that's good to use malloc in those code paths, and I

Oh?

+#if (_MSC_VER >= 1900)
+    uint32    cp;
+
+    if (GetLocaleInfoEx(ctype,
+            LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
+            (LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0)
+    {
+        r = malloc(16);            /* excess */
+        if (r != NULL)
+            sprintf(r, "CP%u", cp);
+    }
+    else
+    {
+#endif

But r is return value so it has to be allocated. The intermediate
variables are function local.

don't think we need to be too precious about saving a byte or two
here. Can one or other of you please prepare a replacement patch based
in this discussion?

Sorry, I don't think I'm up to that (at least not for another week or
so). I have to read up on the issue first; right now I'm not sure what
exactly the problem is.

What I can say is that the existing patch needs more work, because
GetLocaleInfoEx() expects a locale name ("de-DE") as its first argument,
but the patched win32_langinfo() is giving it a locale identifier
("German_Germany.1252"). At least it does for me.

That really depends on what you set in config/commandline. The current
code supports both (that's why there is the else fallback to old code
which handles the "German_Germany.1252" format).

As for missing code page information in the _locale_t type, ISTM it
isn't hidden any better in UCRT than it was before:

int main()
{
/* Set locale with nonstandard code page */
_locale_t loc = _create_locale(LC_ALL, "German_Germany.850");

__crt_locale_data_public* pub =
(__crt_locale_data_public*)(loc->locinfo);
printf("CP: %d\n", pub->_locale_lc_codepage); // "CP: 850"
return 0;
}

This is basically same as the approach of fixing _locale_t that was also
considered upthread but nobody was too happy with it. I guess the worry
is that given that the header file is obviously unfinished in the area
where this is defined and also the fact that this looks like something
that's not meant to be used outside of that header makes people worry
that it might change between point releases of the SDK.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#85Michael Paquier
michael.paquier@gmail.com
In reply to: Petr Jelinek (#84)
2 attachment(s)
Re: VS 2015 support in src/tools/msvc

On Mon, Apr 11, 2016 at 6:03 AM, Petr Jelinek <petr@2ndquadrant.com> wrote:

On 10/04/16 20:47, Christian Ullrich wrote:

don't think we need to be too precious about saving a byte or two
here. Can one or other of you please prepare a replacement patch based
in this discussion?

So, I am finally back on the battlefield.

Sorry, I don't think I'm up to that (at least not for another week or
so). I have to read up on the issue first; right now I'm not sure what
exactly the problem is.

What I can say is that the existing patch needs more work, because
GetLocaleInfoEx() expects a locale name ("de-DE") as its first argument,
but the patched win32_langinfo() is giving it a locale identifier
("German_Germany.1252"). At least it does for me.

That really depends on what you set in config/commandline. The current code
supports both (that's why there is the else fallback to old code which
handles the "German_Germany.1252" format).

Yes, that's the whole point of falling back to the old code path
should the call to GetLocaleInfoEx() fail.

As for missing code page information in the _locale_t type, ISTM it
isn't hidden any better in UCRT than it was before:

int main()
{
/* Set locale with nonstandard code page */
_locale_t loc = _create_locale(LC_ALL, "German_Germany.850");

__crt_locale_data_public* pub =
(__crt_locale_data_public*)(loc->locinfo);
printf("CP: %d\n", pub->_locale_lc_codepage); // "CP: 850"
return 0;
}

This is basically same as the approach of fixing _locale_t that was also
considered upthread but nobody was too happy with it.

I am one of them to be honest... Now if I look at that with one step
backward at this problem this requires just a ugly hack of a couple of
lines, and this does not require to bump __WIN32_WINNT... Neither does
it need an extra code hunk to handle the short locale name parsing
with GetLocaleInfoEx. We could even just handle _MSC_VER as an
exception, so as it is easy to check with future versions of VS if we
still have lc_codepage going missing:
+#if (_MSC_VER == 1900)
+               __crt_locale_data_public *pub =
+                       (__crt_locale_data_public *) loct->locinfo;
+               lc_codepage = pub->_locale_lc_codepage;
+#else
+               lc_codepage = loct->locinfo->lc_codepage;
+#endif

Another thing that I am wondering is that this would allow us to parse
even locale names that are not short, type ja-JP and not with the
COUNTRY_LANG.CODEPAGE format, though based on what I read on the docs
those do not exist.. But the world of Windows is full of surprises.

I guess the worry is
that given that the header file is obviously unfinished in the area where
this is defined and also the fact that this looks like something that's not
meant to be used outside of that header makes people worry that it might
change between point releases of the SDK.

Yep.

Now, I have produced two patches:
- 0001-Support-for-VS-2015-locale-hack.patch, which makes use of
__crt_locale_data_public in ucrt/corecrt.h. This is definitely an ugly
hack, though I am coming to think that this may be the approach that
would us the less harm, and that's closer to what is done for VS 2012
and 2013.
- 0001-Support-for-VS-2015-getlocaleinfoex.patch, which make use of
GetLocaleInfoEx, this requires us to lower a bit the support grid for
Windows, basically that's throwing support for XP if compilation is
done with VS 2015.
Based on my tests, both are working with short and long local names,
testing via initdb --locale.
--
Michael

Attachments:

0001-Support-for-VS-2015-getlocaleinfoex.patchbinary/octet-stream; name=0001-Support-for-VS-2015-getlocaleinfoex.patchDownload
0001-Support-for-VS-2015.patch
0001-Support-for-VS-2015-locale-hack.patchbinary/octet-stream; name=0001-Support-for-VS-2015-locale-hack.patchDownload
From a03649d32c9ab7bae44f4cc68042a76c07422bd9 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Mon, 11 Apr 2016 14:36:56 +0900
Subject: [PATCH] Support for VS 2015

This uses a private header in ucrt/corecrt.h to fetch correctly the
locale codepage, which is not directly available in the headers of
VS 2015.
---
 doc/src/sgml/install-windows.sgml |  8 ++++----
 src/port/chklocale.c              | 18 +++++++++++++++++-
 src/tools/msvc/MSBuildProject.pm  | 23 +++++++++++++++++++++++
 src/tools/msvc/Solution.pm        | 26 ++++++++++++++++++++++++++
 src/tools/msvc/VSObjectFactory.pm | 12 ++++++++++--
 5 files changed, 80 insertions(+), 7 deletions(-)

diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index 9360383..a62aa49 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -19,10 +19,10 @@
  <para>
   There are several different ways of building PostgreSQL on
   <productname>Windows</productname>. The simplest way to build with
-  Microsoft tools is to install <productname>Visual Studio Express 2013
+  Microsoft tools is to install <productname>Visual Studio Express 2015
   for Windows Desktop</productname> and use the included
   compiler. It is also possible to build with the full
-  <productname>Microsoft Visual C++ 2005 to 2013</productname>.
+  <productname>Microsoft Visual C++ 2005 to 2015</productname>.
   In some cases that requires the installation of the
   <productname>Windows SDK</productname> in addition to the compiler.
  </para>
@@ -77,7 +77,7 @@
   <productname>Visual Studio Express</productname> or some versions of the
   <productname>Microsoft Windows SDK</productname>. If you do not already have a
   <productname>Visual Studio</productname> environment set up, the easiest
-  ways are to use the compilers from <productname>Visual Studio Express 2013
+  ways are to use the compilers from <productname>Visual Studio Express 2015
   for Windows Desktop</productname> or those in the <productname>Windows SDK
   7.1</productname>, which are both free downloads from Microsoft.
  </para>
@@ -85,7 +85,7 @@
  <para>
   PostgreSQL is known to support compilation using the compilers shipped with
   <productname>Visual Studio 2005</productname> to
-  <productname>Visual Studio 2013</productname> (including Express editions),
+  <productname>Visual Studio 2015</productname> (including Express editions),
   as well as standalone Windows SDK releases 6.0 to 7.1.
   64-bit PostgreSQL builds are only supported with
   <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..094abd1 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -209,9 +209,25 @@ win32_langinfo(const char *ctype)
 	loct = _create_locale(LC_CTYPE, ctype);
 	if (loct != NULL)
 	{
+		unsigned int	lc_codepage;
+
+#if (_MSC_VER == 1900)
+		/*
+		 * Visual Studio 2015 does not publish directly _lc_codepage, so this
+		 * code would fail to compile but it is available via the in-core
+		 * header ucrt/corecrt.h which is proving to work similarly to the
+		 * post-Visual 2012 version equivalent of this code.
+		 */
+		__crt_locale_data_public *pub =
+			(__crt_locale_data_public *) loct->locinfo;
+		lc_codepage = pub->_locale_lc_codepage;
+#else
+		lc_codepage = loct->locinfo->lc_codepage;
+#endif
+
 		r = malloc(16);			/* excess */
 		if (r != NULL)
-			sprintf(r, "CP%u", loct->locinfo->lc_codepage);
+			sprintf(r, "CP%u", lc_codepage);
 		_free_locale(loct);
 	}
 #else
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 3d60b64..d7638b4 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -465,4 +465,27 @@ sub new
 	return $self;
 }
 
+package VC2015Project;
+
+#
+# Package that encapsulates a Visual C++ 2015 project file
+#
+
+use strict;
+use warnings;
+use base qw(VC2012Project);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{vcver}           = '14.00';
+	$self->{PlatformToolset} = 'v140';
+	$self->{ToolsVersion}    = '14.0';
+
+	return $self;
+}
+
 1;
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index ac1ba0a..2b21bf0 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -790,6 +790,32 @@ sub new
 	return $self;
 }
 
+package VS2015Solution;
+
+#
+# Package that encapsulates a Visual Studio 2015 solution file
+#
+
+use Carp;
+use strict;
+use warnings;
+use base qw(Solution);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{solutionFileVersion}        = '14.00';
+	$self->{vcver}                      = '14.00';
+	$self->{visualStudioName}           = 'Visual Studio 2015';
+	$self->{VisualStudioVersion}        = '14.0.24730.2';
+	$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
+
+	return $self;
+}
+
 sub GetAdditionalHeaders
 {
 	my ($self, $f) = @_;
diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm
index fee4684..4190ada 100644
--- a/src/tools/msvc/VSObjectFactory.pm
+++ b/src/tools/msvc/VSObjectFactory.pm
@@ -49,6 +49,10 @@ sub CreateSolution
 	{
 		return new VS2013Solution(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VS2015Solution(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -84,6 +88,10 @@ sub CreateProject
 	{
 		return new VC2013Project(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VC2015Project(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion
 sub _GetVisualStudioVersion
 {
 	my ($major, $minor) = @_;
-	if ($major > 12)
+	if ($major > 14)
 	{
 		carp
 "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
-		return '12.00';
+		return '14.00';
 	}
 	elsif ($major < 6)
 	{
-- 
2.8.1

#86Michael Paquier
michael.paquier@gmail.com
In reply to: Michael Paquier (#85)
2 attachment(s)
Re: VS 2015 support in src/tools/msvc

On Mon, Apr 11, 2016 at 3:25 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Now, I have produced two patches:
- 0001-Support-for-VS-2015-locale-hack.patch, which makes use of
__crt_locale_data_public in ucrt/corecrt.h. This is definitely an ugly
hack, though I am coming to think that this may be the approach that
would us the less harm, and that's closer to what is done for VS 2012
and 2013.
- 0001-Support-for-VS-2015-getlocaleinfoex.patch, which make use of
GetLocaleInfoEx, this requires us to lower a bit the support grid for
Windows, basically that's throwing support for XP if compilation is
done with VS 2015.
Based on my tests, both are working with short and long local names,
testing via initdb --locale.

The first patch is actually not what I wanted to send. Here are the
correct ones...
--
Michael

Attachments:

0001-Support-for-VS-2015-getlocaleinfoex.patchbinary/octet-stream; name=0001-Support-for-VS-2015-getlocaleinfoex.patchDownload
diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index 9360383..bda19a3 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -19,10 +19,10 @@
  <para>
   There are several different ways of building PostgreSQL on
   <productname>Windows</productname>. The simplest way to build with
-  Microsoft tools is to install <productname>Visual Studio Express 2013
+  Microsoft tools is to install <productname>Visual Studio Express 2015
   for Windows Desktop</productname> and use the included
   compiler. It is also possible to build with the full
-  <productname>Microsoft Visual C++ 2005 to 2013</productname>.
+  <productname>Microsoft Visual C++ 2005 to 2015</productname>.
   In some cases that requires the installation of the
   <productname>Windows SDK</productname> in addition to the compiler.
  </para>
@@ -77,7 +77,7 @@
   <productname>Visual Studio Express</productname> or some versions of the
   <productname>Microsoft Windows SDK</productname>. If you do not already have a
   <productname>Visual Studio</productname> environment set up, the easiest
-  ways are to use the compilers from <productname>Visual Studio Express 2013
+  ways are to use the compilers from <productname>Visual Studio Express 2015
   for Windows Desktop</productname> or those in the <productname>Windows SDK
   7.1</productname>, which are both free downloads from Microsoft.
  </para>
@@ -85,11 +85,17 @@
  <para>
   PostgreSQL is known to support compilation using the compilers shipped with
   <productname>Visual Studio 2005</productname> to
-  <productname>Visual Studio 2013</productname> (including Express editions),
+  <productname>Visual Studio 2015</productname> (including Express editions),
   as well as standalone Windows SDK releases 6.0 to 7.1.
   64-bit PostgreSQL builds are only supported with
   <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
-  <productname>Visual Studio 2008</productname> and above.
+  <productname>Visual Studio 2008</productname> and above. Compilation
+  is supported down to <productname>Windows XP</productname> and
+  <productname>Windows Server 2003</> when building with
+  <productname>Visual Studio 2005</> to
+  <productname>Visual Studio 2013</productname>. Building with
+  <productname>Visual Studio 2015</productname> is supported down to
+  <productname>Windows Vista</> and <productname>Windows Server 2008</>.
  </para>
 
  <para>
diff --git a/src/include/port/win32.h b/src/include/port/win32.h
index 69cd1c4..163ac5e 100644
--- a/src/include/port/win32.h
+++ b/src/include/port/win32.h
@@ -6,14 +6,21 @@
 
 /*
  * Make sure _WIN32_WINNT has the minimum required value.
- * Leave a higher value in place.
-*/
+ * Leave a higher value in place. When building with at least Visual
+ * Studio 2015 the minimum requirement is Windows Vista (0x0600) to
+ * get support for GetLocaleInfoEx() with locales.
+ */
 #if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0501
 #undef _WIN32_WINNT
 #endif
 #ifndef _WIN32_WINNT
+#if (_MSC_VER >= 1900)
+#define _WIN32_WINNT 0x0600
+#else
 #define _WIN32_WINNT 0x0501
 #endif
+#endif /* _WIN32_WINNT */
+
 /*
  * Always build with SSPI support. Keep it as a #define in case
  * we want a switch to disable it sometime in the future.
diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..59a6415 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -19,6 +19,10 @@
 #include "postgres_fe.h"
 #endif
 
+#if defined(WIN32) && (_MSC_VER >= 1900)
+#include <windows.h>
+#endif
+
 #include <locale.h>
 #ifdef HAVE_LANGINFO_H
 #include <langinfo.h>
@@ -196,6 +200,16 @@ static const struct encoding_match encoding_match_list[] = {
  * locale machinery determine the code page.  See comments at IsoLocaleName().
  * For other compilers, follow the locale's predictable format.
  *
+ * Visual Studio 2015 should still be able to do the same, but the declaration
+ * of lc_codepage is missing in _locale_t, causing this code compilation to
+ * fail, hence this falls back instead on GetLocaleInfoEx. VS 2015 may be an
+ * exception and post-VS2015 versions should be able to handle properly the
+ * codepage number using _create_locale(). So, instead of the same logic as
+ * VS 2012 and VS 2013, this routine uses GetLocaleInfoEx to parse short
+ * locale names like "de-DE", "fr-FR", etc. If those cannot be parsed correctly
+ * process falls back to the pre-VS-2010 manual parsing done with
+ * using <Language>_<Country>.<CodePage> as a base.
+ *
  * Returns a malloc()'d string for the caller to free.
  */
 static char *
@@ -203,7 +217,7 @@ win32_langinfo(const char *ctype)
 {
 	char	   *r = NULL;
 
-#if (_MSC_VER >= 1700)
+#if (_MSC_VER >= 1700) && (_MSC_VER < 1900)
 	_locale_t	loct = NULL;
 
 	loct = _create_locale(LC_CTYPE, ctype);
@@ -217,6 +231,25 @@ win32_langinfo(const char *ctype)
 #else
 	char	   *codepage;
 
+#if (_MSC_VER >= 1900)
+	uint32		cp;
+	WCHAR		wctype[80];
+
+	memset(wctype, 0, 80 * sizeof(WCHAR));
+	MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, 80);
+
+	if (GetLocaleInfoEx(wctype,
+			LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
+			(LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0)
+	{
+		r = malloc(16);			/* excess */
+		if (r != NULL)
+			sprintf(r, "CP%u", cp);
+	}
+	else
+	{
+#endif
+
 	/*
 	 * Locale format on Win32 is <Language>_<Country>.<CodePage> . For
 	 * example, English_United States.1252.
@@ -232,6 +265,10 @@ win32_langinfo(const char *ctype)
 		if (r != NULL)
 			sprintf(r, "CP%s", codepage);
 	}
+
+#if (_MSC_VER >= 1900)
+	}
+#endif
 #endif
 
 	return r;
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 3d60b64..d7638b4 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -465,4 +465,27 @@ sub new
 	return $self;
 }
 
+package VC2015Project;
+
+#
+# Package that encapsulates a Visual C++ 2015 project file
+#
+
+use strict;
+use warnings;
+use base qw(VC2012Project);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{vcver}           = '14.00';
+	$self->{PlatformToolset} = 'v140';
+	$self->{ToolsVersion}    = '14.0';
+
+	return $self;
+}
+
 1;
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index ac1ba0a..2b21bf0 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -790,6 +790,32 @@ sub new
 	return $self;
 }
 
+package VS2015Solution;
+
+#
+# Package that encapsulates a Visual Studio 2015 solution file
+#
+
+use Carp;
+use strict;
+use warnings;
+use base qw(Solution);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{solutionFileVersion}        = '14.00';
+	$self->{vcver}                      = '14.00';
+	$self->{visualStudioName}           = 'Visual Studio 2015';
+	$self->{VisualStudioVersion}        = '14.0.24730.2';
+	$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
+
+	return $self;
+}
+
 sub GetAdditionalHeaders
 {
 	my ($self, $f) = @_;
diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm
index fee4684..4190ada 100644
--- a/src/tools/msvc/VSObjectFactory.pm
+++ b/src/tools/msvc/VSObjectFactory.pm
@@ -49,6 +49,10 @@ sub CreateSolution
 	{
 		return new VS2013Solution(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VS2015Solution(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -84,6 +88,10 @@ sub CreateProject
 	{
 		return new VC2013Project(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VC2015Project(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion
 sub _GetVisualStudioVersion
 {
 	my ($major, $minor) = @_;
-	if ($major > 12)
+	if ($major > 14)
 	{
 		carp
 "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
-		return '12.00';
+		return '14.00';
 	}
 	elsif ($major < 6)
 	{
0001-Support-for-VS-2015-locale-hack.patchbinary/octet-stream; name=0001-Support-for-VS-2015-locale-hack.patchDownload
From a03649d32c9ab7bae44f4cc68042a76c07422bd9 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Mon, 11 Apr 2016 14:36:56 +0900
Subject: [PATCH] Support for VS 2015

This uses a private header in ucrt/corecrt.h to fetch correctly the
locale codepage, which is not directly available in the headers of
VS 2015.
---
 doc/src/sgml/install-windows.sgml |  8 ++++----
 src/port/chklocale.c              | 18 +++++++++++++++++-
 src/tools/msvc/MSBuildProject.pm  | 23 +++++++++++++++++++++++
 src/tools/msvc/Solution.pm        | 26 ++++++++++++++++++++++++++
 src/tools/msvc/VSObjectFactory.pm | 12 ++++++++++--
 5 files changed, 80 insertions(+), 7 deletions(-)

diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index 9360383..a62aa49 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -19,10 +19,10 @@
  <para>
   There are several different ways of building PostgreSQL on
   <productname>Windows</productname>. The simplest way to build with
-  Microsoft tools is to install <productname>Visual Studio Express 2013
+  Microsoft tools is to install <productname>Visual Studio Express 2015
   for Windows Desktop</productname> and use the included
   compiler. It is also possible to build with the full
-  <productname>Microsoft Visual C++ 2005 to 2013</productname>.
+  <productname>Microsoft Visual C++ 2005 to 2015</productname>.
   In some cases that requires the installation of the
   <productname>Windows SDK</productname> in addition to the compiler.
  </para>
@@ -77,7 +77,7 @@
   <productname>Visual Studio Express</productname> or some versions of the
   <productname>Microsoft Windows SDK</productname>. If you do not already have a
   <productname>Visual Studio</productname> environment set up, the easiest
-  ways are to use the compilers from <productname>Visual Studio Express 2013
+  ways are to use the compilers from <productname>Visual Studio Express 2015
   for Windows Desktop</productname> or those in the <productname>Windows SDK
   7.1</productname>, which are both free downloads from Microsoft.
  </para>
@@ -85,7 +85,7 @@
  <para>
   PostgreSQL is known to support compilation using the compilers shipped with
   <productname>Visual Studio 2005</productname> to
-  <productname>Visual Studio 2013</productname> (including Express editions),
+  <productname>Visual Studio 2015</productname> (including Express editions),
   as well as standalone Windows SDK releases 6.0 to 7.1.
   64-bit PostgreSQL builds are only supported with
   <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..094abd1 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -209,9 +209,25 @@ win32_langinfo(const char *ctype)
 	loct = _create_locale(LC_CTYPE, ctype);
 	if (loct != NULL)
 	{
+		unsigned int	lc_codepage;
+
+#if (_MSC_VER == 1900)
+		/*
+		 * Visual Studio 2015 does not publish directly _lc_codepage, so this
+		 * code would fail to compile but it is available via the in-core
+		 * header ucrt/corecrt.h which is proving to work similarly to the
+		 * post-Visual 2012 version equivalent of this code.
+		 */
+		__crt_locale_data_public *pub =
+			(__crt_locale_data_public *) loct->locinfo;
+		lc_codepage = pub->_locale_lc_codepage;
+#else
+		lc_codepage = loct->locinfo->lc_codepage;
+#endif
+
 		r = malloc(16);			/* excess */
 		if (r != NULL)
-			sprintf(r, "CP%u", loct->locinfo->lc_codepage);
+			sprintf(r, "CP%u", lc_codepage);
 		_free_locale(loct);
 	}
 #else
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 3d60b64..d7638b4 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -465,4 +465,27 @@ sub new
 	return $self;
 }
 
+package VC2015Project;
+
+#
+# Package that encapsulates a Visual C++ 2015 project file
+#
+
+use strict;
+use warnings;
+use base qw(VC2012Project);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{vcver}           = '14.00';
+	$self->{PlatformToolset} = 'v140';
+	$self->{ToolsVersion}    = '14.0';
+
+	return $self;
+}
+
 1;
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index ac1ba0a..2b21bf0 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -790,6 +790,32 @@ sub new
 	return $self;
 }
 
+package VS2015Solution;
+
+#
+# Package that encapsulates a Visual Studio 2015 solution file
+#
+
+use Carp;
+use strict;
+use warnings;
+use base qw(Solution);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{solutionFileVersion}        = '14.00';
+	$self->{vcver}                      = '14.00';
+	$self->{visualStudioName}           = 'Visual Studio 2015';
+	$self->{VisualStudioVersion}        = '14.0.24730.2';
+	$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
+
+	return $self;
+}
+
 sub GetAdditionalHeaders
 {
 	my ($self, $f) = @_;
diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm
index fee4684..4190ada 100644
--- a/src/tools/msvc/VSObjectFactory.pm
+++ b/src/tools/msvc/VSObjectFactory.pm
@@ -49,6 +49,10 @@ sub CreateSolution
 	{
 		return new VS2013Solution(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VS2015Solution(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -84,6 +88,10 @@ sub CreateProject
 	{
 		return new VC2013Project(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VC2015Project(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion
 sub _GetVisualStudioVersion
 {
 	my ($major, $minor) = @_;
-	if ($major > 12)
+	if ($major > 14)
 	{
 		carp
 "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
-		return '12.00';
+		return '14.00';
 	}
 	elsif ($major < 6)
 	{
-- 
2.8.1

#87Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Michael Paquier (#86)
Re: VS 2015 support in src/tools/msvc

Michael Paquier wrote:

On Mon, Apr 11, 2016 at 3:25 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Now, I have produced two patches:
- 0001-Support-for-VS-2015-locale-hack.patch, which makes use of
__crt_locale_data_public in ucrt/corecrt.h. This is definitely an ugly
hack, though I am coming to think that this may be the approach that
would us the less harm, and that's closer to what is done for VS 2012
and 2013.
- 0001-Support-for-VS-2015-getlocaleinfoex.patch, which make use of
GetLocaleInfoEx, this requires us to lower a bit the support grid for
Windows, basically that's throwing support for XP if compilation is
done with VS 2015.
Based on my tests, both are working with short and long local names,
testing via initdb --locale.

The first patch is actually not what I wanted to send. Here are the
correct ones...

This thread seems to have stalled. I thought we were going to consider
these patches for 9.6. Should we simply push them to see what the
buildfarm thinks? Has anyone other than Michael actually tested it in
VS2015?

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#88Michael Paquier
michael.paquier@gmail.com
In reply to: Alvaro Herrera (#87)
Re: VS 2015 support in src/tools/msvc

On Tue, Apr 19, 2016 at 2:42 PM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:

Michael Paquier wrote:

On Mon, Apr 11, 2016 at 3:25 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Now, I have produced two patches:
- 0001-Support-for-VS-2015-locale-hack.patch, which makes use of
__crt_locale_data_public in ucrt/corecrt.h. This is definitely an ugly
hack, though I am coming to think that this may be the approach that
would us the less harm, and that's closer to what is done for VS 2012
and 2013.
- 0001-Support-for-VS-2015-getlocaleinfoex.patch, which make use of
GetLocaleInfoEx, this requires us to lower a bit the support grid for
Windows, basically that's throwing support for XP if compilation is
done with VS 2015.
Based on my tests, both are working with short and long local names,
testing via initdb --locale.

The first patch is actually not what I wanted to send. Here are the
correct ones...

This thread seems to have stalled. I thought we were going to consider
these patches for 9.6. Should we simply push them to see what the
buildfarm thinks?

We need to choose first which one we'd like to have, it would be great
to get some input from Andrew or even Magnus here who I thought would
get the last word.

Has anyone other than Michael actually tested it in VS2015?

It doesn't seem to be the case...
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#89Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#88)
Re: VS 2015 support in src/tools/msvc

On 04/19/2016 01:47 AM, Michael Paquier wrote:

On Tue, Apr 19, 2016 at 2:42 PM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:

Michael Paquier wrote:

On Mon, Apr 11, 2016 at 3:25 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Now, I have produced two patches:
- 0001-Support-for-VS-2015-locale-hack.patch, which makes use of
__crt_locale_data_public in ucrt/corecrt.h. This is definitely an ugly
hack, though I am coming to think that this may be the approach that
would us the less harm, and that's closer to what is done for VS 2012
and 2013.
- 0001-Support-for-VS-2015-getlocaleinfoex.patch, which make use of
GetLocaleInfoEx, this requires us to lower a bit the support grid for
Windows, basically that's throwing support for XP if compilation is
done with VS 2015.
Based on my tests, both are working with short and long local names,
testing via initdb --locale.

The first patch is actually not what I wanted to send. Here are the
correct ones...

This thread seems to have stalled. I thought we were going to consider
these patches for 9.6. Should we simply push them to see what the
buildfarm thinks?

We need to choose first which one we'd like to have, it would be great
to get some input from Andrew or even Magnus here who I thought would
get the last word.

trying to make some more time to spend on this. I hope to in the next
day or two.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#90Christian Ullrich
chris@chrullrich.net
In reply to: Alvaro Herrera (#87)
Re: VS 2015 support in src/tools/msvc

* Alvaro Herrera wrote:

Michael Paquier wrote:

On Mon, Apr 11, 2016 at 3:25 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Now, I have produced two patches:
- 0001-Support-for-VS-2015-locale-hack.patch, which makes use of
__crt_locale_data_public in ucrt/corecrt.h. This is definitely an ugly
hack, though I am coming to think that this may be the approach that
would us the less harm, and that's closer to what is done for VS 2012
and 2013.
- 0001-Support-for-VS-2015-getlocaleinfoex.patch, which make use of
GetLocaleInfoEx, this requires us to lower a bit the support grid for
Windows, basically that's throwing support for XP if compilation is
done with VS 2015.
Based on my tests, both are working with short and long local names,
testing via initdb --locale.

The first patch is actually not what I wanted to send. Here are the
correct ones...

This thread seems to have stalled. I thought we were going to consider
these patches for 9.6. Should we simply push them to see what the
buildfarm thinks? Has anyone other than Michael actually tested it in
VS2015?

I built them both, and for lack of a better idea, ran initdb with all
(short) locales in the Vista list
(https://msdn.microsoft.com/en-us/goglobal/bb896001.aspx, second column)
whose ANSI codepage is not either 0 or 1252. The former probably means
"no such thing", the latter is my own default which I excluded to detect
cases where it falls back to that.

Both patches behave exactly the same in this test. Of the 102 remaining
locales, I get an unexpected codepage for just four:

- kk: Expected 1251, used 1252
- kk-KZ: Expected 1251, used 1252
- sr: Expected 1251, used 1250
- uk: Expected 1251, used 1252

I suspect that "sr" is a bug in MSDN: 1250 is Eastern European (Latin),
1251 is Cyrillic, and "sr" alone is listed as Latin. So either the
script or the codepage are likely wrong.

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#91Michael Paquier
michael.paquier@gmail.com
In reply to: Christian Ullrich (#90)
Re: VS 2015 support in src/tools/msvc

On Wed, Apr 20, 2016 at 1:48 AM, Christian Ullrich <chris@chrullrich.net> wrote:

Both patches behave exactly the same in this test. Of the 102 remaining
locales, I get an unexpected codepage for just four:

- kk: Expected 1251, used 1252
- kk-KZ: Expected 1251, used 1252
- sr: Expected 1251, used 1250
- uk: Expected 1251, used 1252

I suspect that "sr" is a bug in MSDN: 1250 is Eastern European (Latin), 1251
is Cyrillic, and "sr" alone is listed as Latin. So either the script or the
codepage are likely wrong.

Does VS2013 or older behave the same way for those locales? The patch
using __crt_locale_data_public on VS2015 should work more or less
similarly to VS2012~2013.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#92Noah Misch
noah@leadboat.com
In reply to: Alvaro Herrera (#87)
Re: VS 2015 support in src/tools/msvc

On Tue, Apr 19, 2016 at 02:42:24AM -0300, Alvaro Herrera wrote:

Michael Paquier wrote:

On Mon, Apr 11, 2016 at 3:25 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Now, I have produced two patches:
- 0001-Support-for-VS-2015-locale-hack.patch, which makes use of
__crt_locale_data_public in ucrt/corecrt.h. This is definitely an ugly
hack, though I am coming to think that this may be the approach that
would us the less harm, and that's closer to what is done for VS 2012
and 2013.
- 0001-Support-for-VS-2015-getlocaleinfoex.patch, which make use of
GetLocaleInfoEx, this requires us to lower a bit the support grid for
Windows, basically that's throwing support for XP if compilation is
done with VS 2015.
Based on my tests, both are working with short and long local names,
testing via initdb --locale.

The first patch is actually not what I wanted to send. Here are the
correct ones...

This thread seems to have stalled. I thought we were going to consider
these patches for 9.6.

Committers have given this thread's patches a generous level of consideration.
At this point, if $you wouldn't back-patch them to at least 9.5, they don't
belong in 9.6. However, a back-patch to 9.3 does seem fair, assuming the
final patch looks anything like the current proposals.

Should we simply push them to see what the
buildfarm thinks?

No. The thread has been getting suitable test reports for a few weeks now.
If it were not, better to make the enhancement wait as long as necessary than
to use the buildfarm that way. Buildfarm results wouldn't even be pertinent;
they would merely tell us whether the patch broke non-VS 2015 compilers.

nm

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#93Christian Ullrich
chris@chrullrich.net
In reply to: Michael Paquier (#91)
Re: VS 2015 support in src/tools/msvc

* Michael Paquier wrote:

On Wed, Apr 20, 2016 at 1:48 AM, Christian Ullrich <chris@chrullrich.net> wrote:

Both patches behave exactly the same in this test. Of the 102 remaining
locales, I get an unexpected codepage for just four:

- kk: Expected 1251, used 1252
- kk-KZ: Expected 1251, used 1252
- sr: Expected 1251, used 1250
- uk: Expected 1251, used 1252

I suspect that "sr" is a bug in MSDN: 1250 is Eastern European (Latin), 1251
is Cyrillic, and "sr" alone is listed as Latin. So either the script or the
codepage are likely wrong.

Does VS2013 or older behave the same way for those locales? The patch
using __crt_locale_data_public on VS2015 should work more or less
similarly to VS2012~2013.

Identical results for unmodified master built with 2013.

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#94Michael Paquier
michael.paquier@gmail.com
In reply to: Noah Misch (#92)
Re: VS 2015 support in src/tools/msvc

On Wed, Apr 20, 2016 at 1:39 PM, Noah Misch <noah@leadboat.com> wrote:

On Tue, Apr 19, 2016 at 02:42:24AM -0300, Alvaro Herrera wrote:

Michael Paquier wrote:

On Mon, Apr 11, 2016 at 3:25 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Now, I have produced two patches:
- 0001-Support-for-VS-2015-locale-hack.patch, which makes use of
__crt_locale_data_public in ucrt/corecrt.h. This is definitely an ugly
hack, though I am coming to think that this may be the approach that
would us the less harm, and that's closer to what is done for VS 2012
and 2013.
- 0001-Support-for-VS-2015-getlocaleinfoex.patch, which make use of
GetLocaleInfoEx, this requires us to lower a bit the support grid for
Windows, basically that's throwing support for XP if compilation is
done with VS 2015.
Based on my tests, both are working with short and long local names,
testing via initdb --locale.

The first patch is actually not what I wanted to send. Here are the
correct ones...

This thread seems to have stalled. I thought we were going to consider
these patches for 9.6.

Committers have given this thread's patches a generous level of consideration.
At this point, if $you wouldn't back-patch them to at least 9.5, they don't
belong in 9.6. However, a back-patch to 9.3 does seem fair, assuming the
final patch looks anything like the current proposals.

Er, the change is rather located and fully controlled by _MSC_VER >=
1900, so this represents no risk for existing compilations on Windows,
don't you agree? With HEAD, code compilation would just fail btw
knowing how locales are broken, so it would just not work. That said,
support for new VS versions have been backpatched to the last stable
version at least, now that would be 9.5. There is indeed no written
policy stating what to do precisely in this case, but it seems to me
that there is no point in being overly protective as well..

Should we simply push them to see what the
buildfarm thinks?

No. The thread has been getting suitable test reports for a few weeks now.
If it were not, better to make the enhancement wait as long as necessary than
to use the buildfarm that way. Buildfarm results wouldn't even be pertinent;
they would merely tell us whether the patch broke non-VS 2015 compilers.

Well, they could push them, the results won't really matter and
existing machines won't be impacted, as no buildfarm machine is using
_MSC_VER >= 1900 as of now. Petr has one ready though as mentioned
upthread.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#95Noah Misch
noah@leadboat.com
In reply to: Michael Paquier (#94)
Re: VS 2015 support in src/tools/msvc

On Wed, Apr 20, 2016 at 02:03:16PM +0900, Michael Paquier wrote:

On Wed, Apr 20, 2016 at 1:39 PM, Noah Misch <noah@leadboat.com> wrote:

On Tue, Apr 19, 2016 at 02:42:24AM -0300, Alvaro Herrera wrote:

This thread seems to have stalled. I thought we were going to consider
these patches for 9.6.

Committers have given this thread's patches a generous level of consideration.
At this point, if $you wouldn't back-patch them to at least 9.5, they don't
belong in 9.6. However, a back-patch to 9.3 does seem fair, assuming the
final patch looks anything like the current proposals.

Er, the change is rather located and fully controlled by _MSC_VER >=
1900, so this represents no risk for existing compilations on Windows,
don't you agree?

Yes. That is why I said a back-patch to 9.3 seems fair.

Should we simply push them to see what the
buildfarm thinks?

No. The thread has been getting suitable test reports for a few weeks now.
If it were not, better to make the enhancement wait as long as necessary than
to use the buildfarm that way. Buildfarm results wouldn't even be pertinent;
they would merely tell us whether the patch broke non-VS 2015 compilers.

Well, they could push them, the results won't really matter and
existing machines won't be impacted, as no buildfarm machine is using
_MSC_VER >= 1900 as of now. Petr has one ready though as mentioned
upthread.

Here you've presented two additional good reasons to not "simply push them to
see what the buildfarm thinks."

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#96Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#86)
1 attachment(s)
Re: VS 2015 support in src/tools/msvc

On 04/11/2016 03:47 AM, Michael Paquier wrote:

On Mon, Apr 11, 2016 at 3:25 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Now, I have produced two patches:
- 0001-Support-for-VS-2015-locale-hack.patch, which makes use of
__crt_locale_data_public in ucrt/corecrt.h. This is definitely an ugly
hack, though I am coming to think that this may be the approach that
would us the less harm, and that's closer to what is done for VS 2012
and 2013.
- 0001-Support-for-VS-2015-getlocaleinfoex.patch, which make use of
GetLocaleInfoEx, this requires us to lower a bit the support grid for
Windows, basically that's throwing support for XP if compilation is
done with VS 2015.
Based on my tests, both are working with short and long local names,
testing via initdb --locale.

The first patch is actually not what I wanted to send. Here are the
correct ones...

I think I prefer the less hacky solution.

Progress report:

1. My VS 2015 installations (I now have several) all generate solution
file with:

Microsoft Visual Studio Solution File, Format Version 12.00

so I propose to set that as the solution file version.

2. The logic in win32.h is a bit convoluted. I'm going to simplify it.

3. I'm going to define _WINSOCK_DEPRECATED_NO_WARNINGS to silence some
compiler bleatings about the way we use the Winsock API

4. The compiler complains about one of Microsoft's own header files -
essentially it dislikes the=is construct:

typedef enum { ... };

It would be nice to make it shut up about it.

5. It also complains about us casting a pid_t to a HANDLE in
pg_basebackup.c. Not sure what to do about that.

5. most importantly, on my Release/X64 build, I am getting a regression
failure on contrib/seg. regression diffs attached. Until that's fixed
this isn't going anywhere.

cheers

andrew

Attachments:

seg-regression.diffstext/plain; charset=UTF-8; name=seg-regression.diffsDownload
*** C:/prog/postgresql/contrib/seg/expected/seg.out	Wed Apr  6 12:18:10 2016
--- C:/prog/postgresql/contrib/seg/results/seg.out	Thu Apr 21 11:34:26 2016
***************
*** 444,450 ****
  SELECT '24 .. 33.20'::seg = '24 .. 33.21'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '24 .. 33.20'::seg != '24 .. 33.20'::seg AS bool;
--- 444,450 ----
  SELECT '24 .. 33.20'::seg = '24 .. 33.21'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '24 .. 33.20'::seg != '24 .. 33.20'::seg AS bool;
***************
*** 556,562 ****
  SELECT '1'::seg &< '0'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '1'::seg &< '1'::seg AS bool;
--- 556,562 ----
  SELECT '1'::seg &< '0'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '1'::seg &< '1'::seg AS bool;
***************
*** 574,580 ****
  SELECT '0 .. 1'::seg &< '0'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '0 .. 1'::seg &< '1'::seg AS bool;
--- 574,580 ----
  SELECT '0 .. 1'::seg &< '0'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '0 .. 1'::seg &< '1'::seg AS bool;
***************
*** 592,598 ****
  SELECT '0 .. 1'::seg &< '0 .. 0.5'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '0 .. 1'::seg &< '0 .. 1'::seg AS bool;
--- 592,598 ----
  SELECT '0 .. 1'::seg &< '0 .. 0.5'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '0 .. 1'::seg &< '0 .. 1'::seg AS bool;
***************
*** 624,630 ****
  SELECT '0'::seg &> '1'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '1'::seg &> '1'::seg AS bool;
--- 624,630 ----
  SELECT '0'::seg &> '1'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '1'::seg &> '1'::seg AS bool;
***************
*** 692,704 ****
  SELECT '1'::seg << '0'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '1'::seg << '1'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '1'::seg << '2'::seg AS bool;
--- 692,704 ----
  SELECT '1'::seg << '0'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '1'::seg << '1'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '1'::seg << '2'::seg AS bool;
***************
*** 710,722 ****
  SELECT '0 .. 1'::seg << '0'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '0 .. 1'::seg << '1'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '0 .. 1'::seg << '2'::seg AS bool;
--- 710,722 ----
  SELECT '0 .. 1'::seg << '0'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '0 .. 1'::seg << '1'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '0 .. 1'::seg << '2'::seg AS bool;
***************
*** 728,752 ****
  SELECT '0 .. 1'::seg << '0 .. 0.5'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '0 .. 1'::seg << '0 .. 1'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '0 .. 1'::seg << '0 .. 2'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '0 .. 1'::seg << '1 .. 2'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '0 .. 1'::seg << '2 .. 3'::seg AS bool;
--- 728,752 ----
  SELECT '0 .. 1'::seg << '0 .. 0.5'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '0 .. 1'::seg << '0 .. 1'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '0 .. 1'::seg << '0 .. 2'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '0 .. 1'::seg << '1 .. 2'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '0 .. 1'::seg << '2 .. 3'::seg AS bool;
***************
*** 760,772 ****
  SELECT '0'::seg >> '1'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '1'::seg >> '1'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '2'::seg >> '1'::seg AS bool;
--- 760,772 ----
  SELECT '0'::seg >> '1'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '1'::seg >> '1'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '2'::seg >> '1'::seg AS bool;
***************
*** 778,790 ****
  SELECT '0'::seg >> '0 .. 1'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '1'::seg >> '0 .. 1'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '2'::seg >> '0 .. 1'::seg AS bool;
--- 778,790 ----
  SELECT '0'::seg >> '0 .. 1'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '1'::seg >> '0 .. 1'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '2'::seg >> '0 .. 1'::seg AS bool;
***************
*** 796,820 ****
  SELECT '0 .. 0.5'::seg >> '0 .. 1'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '0 .. 1'::seg >> '0 .. 1'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '0 .. 2'::seg >> '0 .. 2'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '1 .. 2'::seg >> '0 .. 1'::seg AS bool;
   bool 
  ------
!  f
  (1 row)
  
  SELECT '2 .. 3'::seg >> '0 .. 1'::seg AS bool;
--- 796,820 ----
  SELECT '0 .. 0.5'::seg >> '0 .. 1'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '0 .. 1'::seg >> '0 .. 1'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '0 .. 2'::seg >> '0 .. 2'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '1 .. 2'::seg >> '0 .. 1'::seg AS bool;
   bool 
  ------
!  t
  (1 row)
  
  SELECT '2 .. 3'::seg >> '0 .. 1'::seg AS bool;
***************
*** 931,1081 ****
  -- Test sorting
  SELECT * FROM test_seg WHERE s @> '11..11.3' GROUP BY s;
          s        
! -----------------
   .. 4.0e1
!  .. >8.2e1
!  .. 9.0e1
!  <1.0 .. >13.0
!  1.3 .. 12.0
!  2.0 .. 11.5
!  2.1 .. 11.8
!  <2.3 ..
!  >2.3 ..
!  2.4 .. 11.3
!  2.5 .. 11.5
!  2.5 .. 11.8
!  2.6 ..
!  2.7 .. 12.0
!  <3.0 ..
!  3 .. 5.8e1
!  3.1 .. 11.5
!  3.5 .. 11.5
!  3.5 .. 12.2
!  <4.0 .. >1.2e1
!  <4.0 ..
!  4 .. 1.2e1
!  4.0 .. 11.7
!  4.0 .. 12.5
!  4.0 .. 13.0
!  4.0 .. 6.0e1
!  4.0 ..
!  4.2 .. 11.5
!  4.2 .. 11.7
!  <4.5 .. >1.2e1
!  4.5 .. 11.5
!  4.5 .. <1.2e1
!  4.5 .. >1.2e1
!  4.5 .. 12.5
!  4.5 .. 1.15e2
!  4.7 .. 11.8
!  4.8 .. 11.5
!  4.8 .. 11.6
!  4.8 .. 12.5
!  4.8 ..
!  4.9 .. >1.2e1
!  4.9 ..
!  5 .. 11.5
!  5 .. 1.2e1
!  5 .. 3.0e1
!  5.0 .. 11.4
!  5.0 .. 11.5
!  5.0 .. 11.6
!  5.0 .. 11.7
!  5.0 .. 12.0
!  5.0 .. >12.0
!  5.0 .. >1.2e1
!  5.2 .. 11.5
!  5.2 .. >1.2e1
!  5.25 .. >1.2e1
!  5.3 .. 11.5
!  5.3 .. 1.3e1
!  5.3 .. >9.0e1
!  5.3 ..
!  5.4 ..
!  5.5 .. 11.5
!  5.5 .. 11.7
!  5.5 .. 1.2e1
!  5.5 .. >1.2e1
!  5.5 .. 12.5
!  5.5 .. 13.5
!  5.5 ..
!  >5.5 ..
!  5.7 ..
!  5.9 ..
!  6 .. 11.5
!  6 .. >1.2e1
!  6.0 .. 11.5
!  6.0 .. 1.3e1
!  >6.0 .. <11.5
!  6.1 .. >1.2e1
!  6.1 ..
!  6.2 .. >11.5
!  6.3 ..
!  6.5 .. 11.5
!  6.5 .. 12.0
!  6.5 .. >12.0
!  6.5 ..
!  6.6 ..
!  6.7 .. 11.5
!  6.7 ..
!  6.75 ..
!  6.8 ..
!  6.9 .. 12.2
!  6.9 .. >9.0e1
!  6.9 ..
!  <7.0 .. >11.5
!  7.0 .. 11.5
!  7.0 .. >11.5
!  7.0 ..
!  >7.15 ..
!  7.2 .. 13.5
!  7.3 .. >9.0e1
!  7.3 ..
!  >7.3 ..
!  7.4 .. 12.1
!  7.4 ..
!  7.5 .. 11.5
!  7.5 .. 12.0
!  7.5 ..
!  7.7 .. 11.5
!  7.7 ..
!  7.75 ..
!  8.0 .. 11.7
!  8.0 .. 12.0
!  8.0 .. >13.0
!  8.2 ..
!  8.3 ..
!  8.5 .. >11.5
!  8.5 .. 12.5
!  8.5 ..
!  8.6 .. >9.9e1
!  8.7 .. 11.3
!  8.7 .. 11.7
!  8.9 .. 11.5
!  9 .. >1.2e1
!  9.0 .. 11.3
!  9.0 .. 11.5
!  9.0 .. 1.2e1
!  9.0 ..
!  9.2 .. 1.2e1
!  9.4 .. 12.2
!  <9.5 .. 1.2e1
!  <9.5 .. >12.2
!  9.5 ..
!  9.6 .. 11.5
!  9.7 .. 11.5
!  9.7 .. >1.2e1
!  9.8 .. >12.5
!  <1.0e1 .. >11.6
!  10.0 .. 11.5
!  10.0 .. 12.5
!  10.0 .. >12.5
!  10.2 .. 11.8
!  <10.5 .. 11.5
!  10.5 .. 11.5
!  10.5 .. <13.5
!  10.7 .. 12.3
! (143 rows)
  
  -- Test functions
  SELECT seg_lower(s), seg_center(s), seg_upper(s)
--- 931,939 ----
  -- Test sorting
  SELECT * FROM test_seg WHERE s @> '11..11.3' GROUP BY s;
      s     
! ----------
   .. 4.0e1
! (1 row)
  
  -- Test functions
  SELECT seg_lower(s), seg_center(s), seg_upper(s)

======================================================================

#97Christian Ullrich
chris@chrullrich.net
In reply to: Andrew Dunstan (#96)
Re: VS 2015 support in src/tools/msvc

* From: Andrew Dunstan [mailto:andrew@dunslane.net]

4. The compiler complains about one of Microsoft's own header files -
essentially it dislikes the=is construct:

typedef enum { ... };

It would be nice to make it shut up about it.

I doubt that's possible; the declaration *is* wrong after all. We could turn off the warning:

#pragma warning(push)
#pragma warning(disable : 1234, or whatever the number is)
#include <whatever.h>
#pragma warning(pop)

5. It also complains about us casting a pid_t to a HANDLE in
pg_basebackup.c. Not sure what to do about that.

The thing that's being cast is not a PID, but a HANDLE to a process. pid_t is a typedef for int (in port/win32.h), therefore is always 32 bits, while HANDLE is actually void*. However, Microsoft guarantees that kernel32 HANDLEs (this includes those to threads and processes) fit into 32 bits on AMD64.

Source: https://msdn.microsoft.com/en-us/library/windows/desktop/ee872017(v=vs.85).aspx, third bullet point.

So we can simply silence the warning by casting explicitly.

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#98Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#96)
Re: VS 2015 support in src/tools/msvc

Andrew Dunstan <andrew@dunslane.net> writes:

5. most importantly, on my Release/X64 build, I am getting a regression
failure on contrib/seg. regression diffs attached. Until that's fixed
this isn't going anywhere.

I'll bet a nickel that this means MSVC has broken the ABI rules that
allowed old-style (version 0) C functions to limp along without changes.
seg_same() and the other comparison functions that are misbehaving are
declared at the C level to return "bool". I think what's happening is
they are now setting only one byte in the return register, or perhaps
only the low-order word, leaving the high-order bits as trash. But
fmgr_oldstyle is coded as though V0 functions return "char *", and it's
going to be putting that whole pointer value into the result Datum, and
if the value isn't entirely zero then DatumGetBool will consider it
"true". So this theory predicts a lot of intended "false" results will
read as "true", which is what your regression diffs show.

IIRC, we had intentionally left contrib/seg using mostly V0 calling
convention as a canary to let us know when that broke. It's a bit
astonishing that it lasted this long, maybe. But it looks like we're
going to have to convert at least the bool-returning functions to V1
if we want it to work on VS 2015.

Do the other contrib modules all pass? I can't recall if seg was the
only one we'd left like this.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#99Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#98)
Re: VS 2015 support in src/tools/msvc

On 04/21/2016 05:15 PM, Tom Lane wrote:

IIRC, we had intentionally left contrib/seg using mostly V0 calling
convention as a canary to let us know when that broke. It's a bit
astonishing that it lasted this long, maybe. But it looks like we're
going to have to convert at least the bool-returning functions to V1
if we want it to work on VS 2015.

Do the other contrib modules all pass? I can't recall if seg was the
only one we'd left like this.

Only seg fails.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#100Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#99)
Re: VS 2015 support in src/tools/msvc

Andrew Dunstan <andrew@dunslane.net> writes:

On 04/21/2016 05:15 PM, Tom Lane wrote:

Do the other contrib modules all pass? I can't recall if seg was the
only one we'd left like this.

Only seg fails.

As a crosscheck, I put some code into fmgr_c_validator() to log a message
when creating a V0 function with a pass-by-val return type. (Pass-by-ref
is no problem, according to my hypothesis, since it necessarily means
the C function returns a pointer.) I get these hits in core + contrib
regression tests:

core:
LOG: version-0 function widget_in returns type widget
LOG: version-0 function oldstyle_length returns type integer

contrib:
LOG: version-0 function seg_over_left returns type boolean
LOG: version-0 function seg_over_right returns type boolean
LOG: version-0 function seg_left returns type boolean
LOG: version-0 function seg_right returns type boolean
LOG: version-0 function seg_lt returns type boolean
LOG: version-0 function seg_le returns type boolean
LOG: version-0 function seg_gt returns type boolean
LOG: version-0 function seg_ge returns type boolean
LOG: version-0 function seg_contains returns type boolean
LOG: version-0 function seg_contained returns type boolean
LOG: version-0 function seg_overlap returns type boolean
LOG: version-0 function seg_same returns type boolean
LOG: version-0 function seg_different returns type boolean
LOG: version-0 function seg_cmp returns type integer
LOG: version-0 function gseg_consistent returns type boolean
LOG: version-0 function gseg_compress returns type internal
LOG: version-0 function gseg_decompress returns type internal
LOG: version-0 function gseg_penalty returns type internal
LOG: version-0 function gseg_picksplit returns type internal
LOG: version-0 function gseg_same returns type internal

The widget_in gripe is a false positive, caused by the fact that we don't
know the properties of type widget when widget_in is declared. We also
need not worry about the functions that return "internal", since that's
defined to be pointer-sized.

If we assume that oldstyle functions returning integer are still okay,
which the success of the regression test case involving oldstyle_length()
seems to prove, then indeed seg's bool-returning functions are the only
hazard.

Note though that this test fails to cover any contrib modules that
lack regression tests, since they wouldn't have gotten loaded by
"make installcheck".

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#101Michael Paquier
michael.paquier@gmail.com
In reply to: Christian Ullrich (#97)
Re: VS 2015 support in src/tools/msvc

On Fri, Apr 22, 2016 at 4:56 AM, Christian Ullrich <chris@chrullrich.net> wrote:

* From: Andrew Dunstan [mailto:andrew@dunslane.net]

4. The compiler complains about one of Microsoft's own header files -
essentially it dislikes the=is construct:

typedef enum { ... };

It would be nice to make it shut up about it.

I doubt that's possible; the declaration *is* wrong after all. We could turn off the warning:

#pragma warning(push)
#pragma warning(disable : 1234, or whatever the number is)
#include <whatever.h>
#pragma warning(pop)

Well, yes.. Even if that's not pretty that would not be the first one
caused by a VS header bug (float.c)..

5. It also complains about us casting a pid_t to a HANDLE in
pg_basebackup.c. Not sure what to do about that.

The thing that's being cast is not a PID, but a HANDLE to a process. pid_t is a typedef for int (in port/win32.h), therefore is always 32 bits, while HANDLE is actually void*. However, Microsoft guarantees that kernel32 HANDLEs (this includes those to threads and processes) fit into 32 bits on AMD64.

Source: https://msdn.microsoft.com/en-us/library/windows/desktop/ee872017(v=vs.85).aspx, third bullet point.

So we can simply silence the warning by casting explicitly.

Yes, when casting things this way I think that a comment would be fine
in the code. We could do that as separate patches actually.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#102Michael Paquier
michael.paquier@gmail.com
In reply to: Andrew Dunstan (#96)
Re: VS 2015 support in src/tools/msvc

On Fri, Apr 22, 2016 at 4:39 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

On 04/11/2016 03:47 AM, Michael Paquier wrote:

On Mon, Apr 11, 2016 at 3:25 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Now, I have produced two patches:
- 0001-Support-for-VS-2015-locale-hack.patch, which makes use of
__crt_locale_data_public in ucrt/corecrt.h. This is definitely an ugly
hack, though I am coming to think that this may be the approach that
would us the less harm, and that's closer to what is done for VS 2012
and 2013.
- 0001-Support-for-VS-2015-getlocaleinfoex.patch, which make use of
GetLocaleInfoEx, this requires us to lower a bit the support grid for
Windows, basically that's throwing support for XP if compilation is
done with VS 2015.
Based on my tests, both are working with short and long local names,
testing via initdb --locale.

The first patch is actually not what I wanted to send. Here are the
correct ones...

I think I prefer the less hacky solution.

OK, at least we go in one direction.

Progress report:

1. My VS 2015 installations (I now have several) all generate solution file
with:
Microsoft Visual Studio Solution File, Format Version 12.00
so I propose to set that as the solution file version.

I am wondering why it happens this way for you..

2. The logic in win32.h is a bit convoluted. I'm going to simplify it.

OK. Should I wait for a patch to look at then?

3. I'm going to define _WINSOCK_DEPRECATED_NO_WARNINGS to silence some
compiler bleatings about the way we use the Winsock API

Agreed here. I saw those warnings as well.

6. most importantly, on my Release/X64 build, I am getting a regression
failure on contrib/seg. regression diffs attached. Until that's fixed this
isn't going anywhere.

Hm. I am now looking at that, and I can reproduce the failure... I
will send a patch soon.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#103Michael Paquier
michael.paquier@gmail.com
In reply to: Tom Lane (#100)
1 attachment(s)
Re: VS 2015 support in src/tools/msvc

On Fri, Apr 22, 2016 at 1:30 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

On 04/21/2016 05:15 PM, Tom Lane wrote:

Do the other contrib modules all pass? I can't recall if seg was the
only one we'd left like this.

Only seg fails.

As a crosscheck, I put some code into fmgr_c_validator() to log a message
when creating a V0 function with a pass-by-val return type. (Pass-by-ref
is no problem, according to my hypothesis, since it necessarily means
the C function returns a pointer.) I get these hits in core + contrib
regression tests:

[...]

If we assume that oldstyle functions returning integer are still okay,
which the success of the regression test case involving oldstyle_length()
seems to prove, then indeed seg's bool-returning functions are the only
hazard.

Note though that this test fails to cover any contrib modules that
lack regression tests, since they wouldn't have gotten loaded by
"make installcheck".

Your assumption is right. With the patch attached for contrib/seg/
that converts all those functions to use the V1 declaration, I am able
to make the tests pass. As the internal shape of the functions is not
changed and that there are no functional changes, I guess that it
would be fine to backpatch down to where VS2015 is intended to be
supported. Is anybody here foreseeing any problems for back-branches
if there is such a change?
--
Michael

Attachments:

vs2015-seg-fix.patchtext/x-diff; charset=US-ASCII; name=vs2015-seg-fix.patchDownload
diff --git a/contrib/seg/seg.c b/contrib/seg/seg.c
index c6c082b..c3651d4 100644
--- a/contrib/seg/seg.c
+++ b/contrib/seg/seg.c
@@ -47,52 +47,60 @@ PG_FUNCTION_INFO_V1(seg_center);
 /*
 ** GiST support methods
 */
-bool gseg_consistent(GISTENTRY *entry,
-				SEG *query,
-				StrategyNumber strategy,
-				Oid subtype,
-				bool *recheck);
-GISTENTRY  *gseg_compress(GISTENTRY *entry);
-GISTENTRY  *gseg_decompress(GISTENTRY *entry);
-float	   *gseg_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result);
-GIST_SPLITVEC *gseg_picksplit(GistEntryVector *entryvec, GIST_SPLITVEC *v);
+PG_FUNCTION_INFO_V1(gseg_consistent);
+PG_FUNCTION_INFO_V1(gseg_compress);
+PG_FUNCTION_INFO_V1(gseg_decompress);
+PG_FUNCTION_INFO_V1(gseg_penalty);
+PG_FUNCTION_INFO_V1(gseg_picksplit);
+PG_FUNCTION_INFO_V1(gseg_same);
+PG_FUNCTION_INFO_V1(gseg_union);
+
 bool		gseg_leaf_consistent(SEG *key, SEG *query, StrategyNumber strategy);
 bool		gseg_internal_consistent(SEG *key, SEG *query, StrategyNumber strategy);
-SEG		   *gseg_union(GistEntryVector *entryvec, int *sizep);
 SEG		   *gseg_binary_union(SEG *r1, SEG *r2, int *sizep);
-bool	   *gseg_same(SEG *b1, SEG *b2, bool *result);
 
 
 /*
 ** R-tree support functions
 */
-bool		seg_same(SEG *a, SEG *b);
+PG_FUNCTION_INFO_V1(seg_same);
+static inline bool seg_same_internal(SEG *a, SEG *b);
 bool		seg_contains_int(SEG *a, int *b);
 bool		seg_contains_float4(SEG *a, float4 *b);
 bool		seg_contains_float8(SEG *a, float8 *b);
-bool		seg_contains(SEG *a, SEG *b);
-bool		seg_contained(SEG *a, SEG *b);
-bool		seg_overlap(SEG *a, SEG *b);
-bool		seg_left(SEG *a, SEG *b);
-bool		seg_over_left(SEG *a, SEG *b);
-bool		seg_right(SEG *a, SEG *b);
-bool		seg_over_right(SEG *a, SEG *b);
-SEG		   *seg_union(SEG *a, SEG *b);
-SEG		   *seg_inter(SEG *a, SEG *b);
+PG_FUNCTION_INFO_V1(seg_contains);
+static inline bool seg_contains_internal(SEG *a, SEG *b);
+PG_FUNCTION_INFO_V1(seg_contained);
+static inline bool seg_contained_internal(SEG *a, SEG *b);
+PG_FUNCTION_INFO_V1(seg_overlap);
+static inline bool seg_overlap_internal(SEG *a, SEG *b);
+PG_FUNCTION_INFO_V1(seg_left);
+static inline bool seg_left_internal(SEG *a, SEG *b);
+PG_FUNCTION_INFO_V1(seg_over_left);
+static inline bool seg_over_left_internal(SEG *a, SEG *b);
+PG_FUNCTION_INFO_V1(seg_right);
+static inline bool seg_right_internal(SEG *a, SEG *b);
+PG_FUNCTION_INFO_V1(seg_over_right);
+static inline bool seg_over_right_internal(SEG *a, SEG *b);
+PG_FUNCTION_INFO_V1(seg_union);
+static inline SEG *seg_union_internal(SEG *a, SEG *b);
+PG_FUNCTION_INFO_V1(seg_inter);
 void		rt_seg_size(SEG *a, float *sz);
 
 /*
 ** Various operators
 */
-int32		seg_cmp(SEG *a, SEG *b);
-bool		seg_lt(SEG *a, SEG *b);
-bool		seg_le(SEG *a, SEG *b);
-bool		seg_gt(SEG *a, SEG *b);
-bool		seg_ge(SEG *a, SEG *b);
-bool		seg_different(SEG *a, SEG *b);
+PG_FUNCTION_INFO_V1(seg_cmp);
+static inline int32 seg_cmp_internal(SEG *a, SEG *b);
+PG_FUNCTION_INFO_V1(seg_lt);
+PG_FUNCTION_INFO_V1(seg_le);
+PG_FUNCTION_INFO_V1(seg_gt);
+PG_FUNCTION_INFO_V1(seg_ge);
+PG_FUNCTION_INFO_V1(seg_different);
+
 
 /*
-** Auxiliary funxtions
+** Auxiliary functions
 */
 static int	restore(char *s, float val, int n);
 
@@ -193,13 +201,15 @@ seg_upper(PG_FUNCTION_ARGS)
 ** the predicate x op query == FALSE, where op is the oper
 ** corresponding to strategy in the pg_amop table.
 */
-bool
-gseg_consistent(GISTENTRY *entry,
-				SEG *query,
-				StrategyNumber strategy,
-				Oid subtype,
-				bool *recheck)
+Datum
+gseg_consistent(PG_FUNCTION_ARGS)
 {
+	GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+	SEG		   *query = (SEG *) PG_GETARG_POINTER(1);
+	StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+	/* Oid		subtype = PG_GETARG_OID(3); */
+	bool	   *recheck = (bool *) PG_GETARG_POINTER(4);
+
 	/* All cases served by this function are exact */
 	*recheck = false;
 
@@ -217,9 +227,11 @@ gseg_consistent(GISTENTRY *entry,
 ** The GiST Union method for segments
 ** returns the minimal bounding seg that encloses all the entries in entryvec
 */
-SEG *
-gseg_union(GistEntryVector *entryvec, int *sizep)
+Datum
+gseg_union(PG_FUNCTION_ARGS)
 {
+	GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+	int		   *sizep = (int *) PG_GETARG_POINTER(1);
 	int			numranges,
 				i;
 	SEG		   *out = (SEG *) NULL;
@@ -241,37 +253,42 @@ gseg_union(GistEntryVector *entryvec, int *sizep)
 		tmp = out;
 	}
 
-	return (out);
+	PG_RETURN_POINTER(out);
 }
 
 /*
 ** GiST Compress and Decompress methods for segments
 ** do not do anything.
 */
-GISTENTRY *
-gseg_compress(GISTENTRY *entry)
+Datum
+gseg_compress(PG_FUNCTION_ARGS)
 {
-	return (entry);
+	GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+	PG_RETURN_POINTER(entry);
 }
 
-GISTENTRY *
-gseg_decompress(GISTENTRY *entry)
+Datum
+gseg_decompress(PG_FUNCTION_ARGS)
 {
-	return (entry);
+	GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+	PG_RETURN_POINTER(entry);
 }
 
 /*
 ** The GiST Penalty method for segments
 ** As in the R-tree paper, we use change in area as our penalty metric
 */
-float *
-gseg_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result)
+Datum
+gseg_penalty(PG_FUNCTION_ARGS)
 {
+	GISTENTRY  *origentry = (GISTENTRY *) PG_GETARG_POINTER(0);
+	GISTENTRY  *newentry = (GISTENTRY *) PG_GETARG_POINTER(0);
+	float      *result = (float *) PG_GETARG_POINTER(2);
 	SEG		   *ud;
 	float		tmp1,
 				tmp2;
 
-	ud = seg_union((SEG *) DatumGetPointer(origentry->key),
+	ud = seg_union_internal((SEG *) DatumGetPointer(origentry->key),
 				   (SEG *) DatumGetPointer(newentry->key));
 	rt_seg_size(ud, &tmp1);
 	rt_seg_size((SEG *) DatumGetPointer(origentry->key), &tmp2);
@@ -282,7 +299,7 @@ gseg_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result)
 	fprintf(stderr, "\t%g\n", *result);
 #endif
 
-	return (result);
+	PG_RETURN_POINTER(result);
 }
 
 /*
@@ -309,10 +326,11 @@ gseg_picksplit_item_cmp(const void *a, const void *b)
  * it's easier and more robust to just sort the segments by center-point and
  * split at the middle.
  */
-GIST_SPLITVEC *
-gseg_picksplit(GistEntryVector *entryvec,
-			   GIST_SPLITVEC *v)
+Datum
+gseg_picksplit(PG_FUNCTION_ARGS)
 {
+	GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+	GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
 	int			i;
 	SEG		   *datum_l,
 			   *datum_r,
@@ -365,7 +383,7 @@ gseg_picksplit(GistEntryVector *entryvec,
 	v->spl_nleft++;
 	for (i = 1; i < firstright; i++)
 	{
-		datum_l = seg_union(datum_l, sort_items[i].data);
+		datum_l = seg_union_internal(datum_l, sort_items[i].data);
 		*left++ = sort_items[i].index;
 		v->spl_nleft++;
 	}
@@ -379,7 +397,7 @@ gseg_picksplit(GistEntryVector *entryvec,
 	v->spl_nright++;
 	for (i = firstright + 1; i < maxoff; i++)
 	{
-		datum_r = seg_union(datum_r, sort_items[i].data);
+		datum_r = seg_union_internal(datum_r, sort_items[i].data);
 		*right++ = sort_items[i].index;
 		v->spl_nright++;
 	}
@@ -387,16 +405,20 @@ gseg_picksplit(GistEntryVector *entryvec,
 	v->spl_ldatum = PointerGetDatum(datum_l);
 	v->spl_rdatum = PointerGetDatum(datum_r);
 
-	return v;
+	PG_RETURN_POINTER(v);
 }
 
 /*
 ** Equality methods
 */
-bool *
-gseg_same(SEG *b1, SEG *b2, bool *result)
+Datum
+gseg_same(PG_FUNCTION_ARGS)
 {
-	if (seg_same(b1, b2))
+	SEG		*b1 = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b2 = (SEG *) PG_GETARG_POINTER(1);
+	bool	*result = (bool *) PG_GETARG_POINTER(2);
+
+	if (seg_same_internal(b1, b2))
 		*result = TRUE;
 	else
 		*result = FALSE;
@@ -405,7 +427,7 @@ gseg_same(SEG *b1, SEG *b2, bool *result)
 	fprintf(stderr, "same: %s\n", (*result ? "TRUE" : "FALSE"));
 #endif
 
-	return (result);
+	PG_RETURN_POINTER(result);
 }
 
 /*
@@ -425,30 +447,30 @@ gseg_leaf_consistent(SEG *key,
 	switch (strategy)
 	{
 		case RTLeftStrategyNumber:
-			retval = (bool) seg_left(key, query);
+			retval = (bool) seg_left_internal(key, query);
 			break;
 		case RTOverLeftStrategyNumber:
-			retval = (bool) seg_over_left(key, query);
+			retval = (bool) seg_over_left_internal(key, query);
 			break;
 		case RTOverlapStrategyNumber:
-			retval = (bool) seg_overlap(key, query);
+			retval = (bool) seg_overlap_internal(key, query);
 			break;
 		case RTOverRightStrategyNumber:
-			retval = (bool) seg_over_right(key, query);
+			retval = (bool) seg_over_right_internal(key, query);
 			break;
 		case RTRightStrategyNumber:
-			retval = (bool) seg_right(key, query);
+			retval = (bool) seg_right_internal(key, query);
 			break;
 		case RTSameStrategyNumber:
-			retval = (bool) seg_same(key, query);
+			retval = (bool) seg_same_internal(key, query);
 			break;
 		case RTContainsStrategyNumber:
 		case RTOldContainsStrategyNumber:
-			retval = (bool) seg_contains(key, query);
+			retval = (bool) seg_contains_internal(key, query);
 			break;
 		case RTContainedByStrategyNumber:
 		case RTOldContainedByStrategyNumber:
-			retval = (bool) seg_contained(key, query);
+			retval = (bool) seg_contained_internal(key, query);
 			break;
 		default:
 			retval = FALSE;
@@ -470,28 +492,28 @@ gseg_internal_consistent(SEG *key,
 	switch (strategy)
 	{
 		case RTLeftStrategyNumber:
-			retval = (bool) !seg_over_right(key, query);
+			retval = (bool) !seg_over_right_internal(key, query);
 			break;
 		case RTOverLeftStrategyNumber:
-			retval = (bool) !seg_right(key, query);
+			retval = (bool) !seg_right_internal(key, query);
 			break;
 		case RTOverlapStrategyNumber:
-			retval = (bool) seg_overlap(key, query);
+			retval = (bool) seg_overlap_internal(key, query);
 			break;
 		case RTOverRightStrategyNumber:
-			retval = (bool) !seg_left(key, query);
+			retval = (bool) !seg_left_internal(key, query);
 			break;
 		case RTRightStrategyNumber:
-			retval = (bool) !seg_over_left(key, query);
+			retval = (bool) !seg_over_left_internal(key, query);
 			break;
 		case RTSameStrategyNumber:
 		case RTContainsStrategyNumber:
 		case RTOldContainsStrategyNumber:
-			retval = (bool) seg_contains(key, query);
+			retval = (bool) seg_contains_internal(key, query);
 			break;
 		case RTContainedByStrategyNumber:
 		case RTOldContainedByStrategyNumber:
-			retval = (bool) seg_overlap(key, query);
+			retval = (bool) seg_overlap_internal(key, query);
 			break;
 		default:
 			retval = FALSE;
@@ -504,39 +526,71 @@ gseg_binary_union(SEG *r1, SEG *r2, int *sizep)
 {
 	SEG		   *retval;
 
-	retval = seg_union(r1, r2);
+	retval = seg_union_internal(r1, r2);
 	*sizep = sizeof(SEG);
 
 	return (retval);
 }
 
 
+Datum
+seg_contains(PG_FUNCTION_ARGS)
+{
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_contains_internal(a, b));
+}
 bool
-seg_contains(SEG *a, SEG *b)
+seg_contains_internal(SEG *a, SEG *b)
 {
 	return ((a->lower <= b->lower) && (a->upper >= b->upper));
 }
 
+Datum
+seg_contained(PG_FUNCTION_ARGS)
+{
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_contained_internal(a, b));
+}
 bool
-seg_contained(SEG *a, SEG *b)
+seg_contained_internal(SEG *a, SEG *b)
 {
-	return (seg_contains(b, a));
+	return (seg_contains_internal(b, a));
 }
 
 /*****************************************************************************
  * Operator class for R-tree indexing
  *****************************************************************************/
 
-bool
-seg_same(SEG *a, SEG *b)
+Datum
+seg_same(PG_FUNCTION_ARGS)
+{
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_same_internal(a, b));
+}
+static inline bool
+seg_same_internal(SEG *a, SEG *b)
 {
-	return seg_cmp(a, b) == 0;
+	return seg_cmp_internal(a, b) == 0;
 }
 
 /*	seg_overlap -- does a overlap b?
  */
-bool
-seg_overlap(SEG *a, SEG *b)
+Datum
+seg_overlap(PG_FUNCTION_ARGS)
+{
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_overlap_internal(a, b));
+}
+static inline bool
+seg_overlap_internal(SEG *a, SEG *b)
 {
 	return (
 			((a->upper >= b->upper) && (a->lower <= b->upper))
@@ -547,39 +601,79 @@ seg_overlap(SEG *a, SEG *b)
 
 /*	seg_overleft -- is the right edge of (a) located at or left of the right edge of (b)?
  */
-bool
-seg_over_left(SEG *a, SEG *b)
+Datum
+seg_over_left(PG_FUNCTION_ARGS)
+{
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_over_left_internal(a, b));
+}
+static inline bool
+seg_over_left_internal(SEG *a, SEG *b)
 {
 	return (a->upper <= b->upper);
 }
 
 /*	seg_left -- is (a) entirely on the left of (b)?
  */
-bool
-seg_left(SEG *a, SEG *b)
+Datum
+seg_left(PG_FUNCTION_ARGS)
+{
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_left_internal(a, b));
+}
+static inline bool
+seg_left_internal(SEG *a, SEG *b)
 {
 	return (a->upper < b->lower);
 }
 
 /*	seg_right -- is (a) entirely on the right of (b)?
  */
-bool
-seg_right(SEG *a, SEG *b)
+Datum
+seg_right(PG_FUNCTION_ARGS)
+{
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_right_internal(a, b));
+}
+static inline bool
+seg_right_internal(SEG *a, SEG *b)
 {
 	return (a->lower > b->upper);
 }
 
 /*	seg_overright -- is the left edge of (a) located at or right of the left edge of (b)?
  */
-bool
-seg_over_right(SEG *a, SEG *b)
+Datum
+seg_over_right(PG_FUNCTION_ARGS)
+{
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_over_right_internal(a, b));
+}
+static inline bool
+seg_over_right_internal(SEG *a, SEG *b)
 {
 	return (a->lower >= b->lower);
 }
 
 
-SEG *
-seg_union(SEG *a, SEG *b)
+Datum
+seg_union(PG_FUNCTION_ARGS)
+{
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_POINTER(seg_union_internal(a, b));
+}
+static inline SEG *
+seg_union_internal(SEG *a, SEG *b)
 {
 	SEG		   *n;
 
@@ -617,10 +711,12 @@ seg_union(SEG *a, SEG *b)
 }
 
 
-SEG *
-seg_inter(SEG *a, SEG *b)
+Datum
+seg_inter(PG_FUNCTION_ARGS)
 {
-	SEG		   *n;
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+	SEG		*n;
 
 	n = (SEG *) palloc(sizeof(*n));
 
@@ -652,7 +748,7 @@ seg_inter(SEG *a, SEG *b)
 		n->l_ext = b->l_ext;
 	}
 
-	return (n);
+	PG_RETURN_POINTER(n);
 }
 
 void
@@ -678,8 +774,17 @@ seg_size(PG_FUNCTION_ARGS)
 /*****************************************************************************
  *				   Miscellaneous operators
  *****************************************************************************/
-int32
-seg_cmp(SEG *a, SEG *b)
+Datum
+seg_cmp(PG_FUNCTION_ARGS)
+{
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_INT32(seg_cmp_internal(a, b));
+}
+
+static inline int32
+seg_cmp_internal(SEG *a, SEG *b)
 {
 	/*
 	 * First compare on lower boundary position
@@ -797,34 +902,49 @@ seg_cmp(SEG *a, SEG *b)
 	return 0;
 }
 
-bool
-seg_lt(SEG *a, SEG *b)
+Datum
+seg_lt(PG_FUNCTION_ARGS)
 {
-	return seg_cmp(a, b) < 0;
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_cmp_internal(a, b) < 0);
 }
 
-bool
-seg_le(SEG *a, SEG *b)
+Datum
+seg_le(PG_FUNCTION_ARGS)
 {
-	return seg_cmp(a, b) <= 0;
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_cmp_internal(a, b) <= 0);
 }
 
-bool
-seg_gt(SEG *a, SEG *b)
+Datum
+seg_gt(PG_FUNCTION_ARGS)
 {
-	return seg_cmp(a, b) > 0;
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_cmp_internal(a, b) > 0);
 }
 
-bool
-seg_ge(SEG *a, SEG *b)
+Datum
+seg_ge(PG_FUNCTION_ARGS)
 {
-	return seg_cmp(a, b) >= 0;
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_cmp_internal(a, b) >= 0);
 }
 
-bool
-seg_different(SEG *a, SEG *b)
+Datum
+seg_different(PG_FUNCTION_ARGS)
 {
-	return seg_cmp(a, b) != 0;
+	SEG		*a = (SEG *) PG_GETARG_POINTER(0);
+	SEG		*b = (SEG *) PG_GETARG_POINTER(1);
+
+	PG_RETURN_BOOL(seg_cmp_internal(a, b) != 0);
 }
 
 
#104Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Paquier (#103)
Re: VS 2015 support in src/tools/msvc

Michael Paquier <michael.paquier@gmail.com> writes:

On Fri, Apr 22, 2016 at 1:30 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

If we assume that oldstyle functions returning integer are still okay,
which the success of the regression test case involving oldstyle_length()
seems to prove, then indeed seg's bool-returning functions are the only
hazard.

Your assumption is right. With the patch attached for contrib/seg/
that converts all those functions to use the V1 declaration, I am able
to make the tests pass. As the internal shape of the functions is not
changed and that there are no functional changes, I guess that it
would be fine to backpatch down to where VS2015 is intended to be
supported. Is anybody here foreseeing any problems for back-branches
if there is such a change?

It should be fine, since converting a function to V1 makes no difference
at the SQL level --- we don't need an extension script modification.

How far back are we thinking of supporting VS2015, anyway? I can check
and push this as a separate patch.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#105Michael Paquier
michael.paquier@gmail.com
In reply to: Tom Lane (#104)
Re: VS 2015 support in src/tools/msvc

On Fri, Apr 22, 2016 at 10:49 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

How far back are we thinking of supporting VS2015, anyway? I can check
and push this as a separate patch.

My guess is 9.5: HEAD + last stable branch. That's what has been done
when support for VS2012 or VS2013 has been added.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#106Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#102)
Re: VS 2015 support in src/tools/msvc

On 04/22/2016 02:46 AM, Michael Paquier wrote:

Progress report:

1. My VS 2015 installations (I now have several) all generate solution file
with:
Microsoft Visual Studio Solution File, Format Version 12.00
so I propose to set that as the solution file version.

I am wondering why it happens this way for you..

It's not just me. See the reply at
<https://social.msdn.microsoft.com/Forums/sqlserver/en-US/ea671596-9e8d-4e80-bb1f-8c9bfb1738dc/2012-and-2015-solutions?forum=vcgeneral&gt;
and notice that in both cases the Solution file format is version 12.00.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#107Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Paquier (#105)
Re: VS 2015 support in src/tools/msvc

Michael Paquier <michael.paquier@gmail.com> writes:

On Fri, Apr 22, 2016 at 10:49 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

How far back are we thinking of supporting VS2015, anyway? I can check
and push this as a separate patch.

My guess is 9.5: HEAD + last stable branch. That's what has been done
when support for VS2012 or VS2013 has been added.

OK. Pushed with some adjustments --- mainly, I undid the conversion
of the non-bool-returning functions, since those aren't broken (yet)
and I think it's still valuable to test V0 as much as we can here.

Also, I static-ified some functions that weren't SQL-visible, and
thereby discovered that some of those were actually dead code ...

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#108Christian Ullrich
chris@chrullrich.net
In reply to: Andrew Dunstan (#106)
Re: VS 2015 support in src/tools/msvc

* Andrew Dunstan wrote:

On 04/22/2016 02:46 AM, Michael Paquier wrote:

Progress report:

1. My VS 2015 installations (I now have several) all generate
solution file
with:
Microsoft Visual Studio Solution File, Format Version 12.00
so I propose to set that as the solution file version.

I am wondering why it happens this way for you..

It's not just me. See the reply at
<https://social.msdn.microsoft.com/Forums/sqlserver/en-US/ea671596-9e8d-4e80-bb1f-8c9bfb1738dc/2012-and-2015-solutions?forum=vcgeneral&gt;
and notice that in both cases the Solution file format is version 12.00.

Try as I may, I cannot get my VS 2015 to write a version 14 .sln file.
It's always "12.00". If I change it to 14 by hand, it still opens and
appears to work fine.

I tried to find a real-world version 14 solution to see if I can spot a
difference between it and the version 12 files, but there appears to be
very little out there, and what there is, looks like it was either
autogenerated or edited manually. Examples:

-
<https://social.msdn.microsoft.com/Forums/sqlserver/en-US/2d08da92-f16a-4887-935a-e3159104ff2c/&gt;
- "converted to VS2015 in anticipation of the release"

-
<https://connect.microsoft.com/VisualStudio/feedback/details/1909707/getting-empty-folder-in-project-root-after-opening-sln-file-dtar-08e86330-4835-4b5c-9e5a-61f37ae1a077-dtar&gt;
- "but I changed the the contents of the .SLN to Microsoft Visual Studio
Solution File, Format Version 14.00"

-
<https://fossies.org/linux/ACE/examples/Logger/Acceptor-server/Acceptor_server_vc14.sln&gt;
- "# This file was generated by MPC."

Google returns not quite two pages of results for "Microsoft Visual
Studio Solution File, Format Version 14.00"; it *has* to be nonstandard.

My best guess at this point is that the solution format really did not
change between 2013 and 2015. Microsoft may just have added support for
.sln version 14 for compatibility with people who generate solutions by
other means and who are under the impression the .sln version has to be
in step with the VS version, when in fact the VisualStudioVersion line
in a version 12 .sln file controls which version of VS will open any
given file by default, and the MinimumVisualStudioVersion line indicates
which VS version supports the project types in the solution.

If my guess is wrong, and anyone knows a way to make VS 2015 write a
version 14 .sln file, please tell me.

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#109Christian Ullrich
chris@chrullrich.net
In reply to: Christian Ullrich (#108)
Re: VS 2015 support in src/tools/msvc

* Christian Ullrich wrote:

* Andrew Dunstan wrote:

On 04/22/2016 02:46 AM, Michael Paquier wrote:

Progress report:

1. My VS 2015 installations (I now have several) all generate
solution file
with:
Microsoft Visual Studio Solution File, Format Version 12.00
so I propose to set that as the solution file version.

I am wondering why it happens this way for you..

It's not just me. See the reply at
<https://social.msdn.microsoft.com/Forums/sqlserver/en-US/ea671596-9e8d-4e80-bb1f-8c9bfb1738dc/2012-and-2015-solutions?forum=vcgeneral&gt;

and notice that in both cases the Solution file format is version 12.00.

Try as I may, I cannot get my VS 2015 to write a version 14 .sln file.
It's always "12.00". If I change it to 14 by hand, it still opens and
appears to work fine.

I tried to find a real-world version 14 solution to see if I can spot a
difference between it and the version 12 files, but there appears to be
very little out there, and what there is, looks like it was either
autogenerated or edited manually. Examples:

OK, so searching on GitHub yielded a few more results, but I could not
identify a single one that was clearly not created or edited by anything
other than Visual Studio itself.

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#110Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#101)
Re: VS 2015 support in src/tools/msvc

On 04/22/2016 01:21 AM, Michael Paquier wrote:

5. It also complains about us casting a pid_t to a HANDLE in
pg_basebackup.c. Not sure what to do about that.

The thing that's being cast is not a PID, but a HANDLE to a process. pid_t is a typedef for int (in port/win32.h), therefore is always 32 bits, while HANDLE is actually void*. However, Microsoft guarantees that kernel32 HANDLEs (this includes those to threads and processes) fit into 32 bits on AMD64.

Source: https://msdn.microsoft.com/en-us/library/windows/desktop/ee872017(v=vs.85).aspx, third bullet point.

So we can simply silence the warning by casting explicitly.

Yes, when casting things this way I think that a comment would be fine
in the code. We could do that as separate patches actually.

We are already casting the pid_t to HANDLE and still getting a warning.
Apparently we need to do something on win64 like

(HANDLE) ((int64) bgchild)

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#111Christian Ullrich
chris@chrullrich.net
In reply to: Andrew Dunstan (#110)
Re: VS 2015 support in src/tools/msvc

* Andrew Dunstan wrote:

On 04/22/2016 01:21 AM, Michael Paquier wrote:

5. It also complains about us casting a pid_t to a HANDLE in
pg_basebackup.c. Not sure what to do about that.

The thing that's being cast is not a PID, but a HANDLE to a process.
pid_t is a typedef for int (in port/win32.h), therefore is always 32
bits, while HANDLE is actually void*. However, Microsoft guarantees
that kernel32 HANDLEs (this includes those to threads and processes)
fit into 32 bits on AMD64.

Yes, when casting things this way I think that a comment would be fine
in the code. We could do that as separate patches actually.

We are already casting the pid_t to HANDLE and still getting a warning.
Apparently we need to do something on win64 like

(HANDLE) ((int64) bgchild)

Ah, OK, it warns about a cast to a larger type because the value might
get sign extended. Not unreasonable.

In this case, I would prefer this:

diff --git a/src/include/port/win32.h b/src/include/port/win32.h
index ba8cf9d..b4086f1 100644
--- a/src/include/port/win32.h
+++ b/src/include/port/win32.h
@@ -256,7 +256,7 @@ typedef int gid_t;
  typedef long key_t;
  #ifdef WIN32_ONLY_COMPILER
-typedef int pid_t;
+typedef intptr_t pid_t;
  #endif

/*

With this change, pg_basebackup -X stream works the same when built for
64 and 32 bits.

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#112Andrew Dunstan
andrew@dunslane.net
In reply to: Christian Ullrich (#111)
Re: VS 2015 support in src/tools/msvc

On 04/23/2016 05:30 PM, Christian Ullrich wrote:

* Andrew Dunstan wrote:

On 04/22/2016 01:21 AM, Michael Paquier wrote:

5. It also complains about us casting a pid_t to a HANDLE in
pg_basebackup.c. Not sure what to do about that.

The thing that's being cast is not a PID, but a HANDLE to a process.
pid_t is a typedef for int (in port/win32.h), therefore is always 32
bits, while HANDLE is actually void*. However, Microsoft guarantees
that kernel32 HANDLEs (this includes those to threads and processes)
fit into 32 bits on AMD64.

Yes, when casting things this way I think that a comment would be fine
in the code. We could do that as separate patches actually.

We are already casting the pid_t to HANDLE and still getting a warning.
Apparently we need to do something on win64 like

(HANDLE) ((int64) bgchild)

Ah, OK, it warns about a cast to a larger type because the value might
get sign extended. Not unreasonable.

In this case, I would prefer this:

diff --git a/src/include/port/win32.h b/src/include/port/win32.h
index ba8cf9d..b4086f1 100644
--- a/src/include/port/win32.h
+++ b/src/include/port/win32.h
@@ -256,7 +256,7 @@ typedef int gid_t;
typedef long key_t;
#ifdef WIN32_ONLY_COMPILER
-typedef int pid_t;
+typedef intptr_t pid_t;
#endif

/*

With this change, pg_basebackup -X stream works the same when built
for 64 and 32 bits.

That's a change that will have a pretty wide effect. Everything up to
now has been pretty low risk, but this worries me rather more. Maybe
it's safe, but I'd like to hear others' comments.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#113Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#112)
Re: VS 2015 support in src/tools/msvc

Andrew Dunstan <andrew@dunslane.net> writes:

On 04/23/2016 05:30 PM, Christian Ullrich wrote:

In this case, I would prefer this:

#ifdef WIN32_ONLY_COMPILER
-typedef int pid_t;
+typedef intptr_t pid_t;
#endif

That's a change that will have a pretty wide effect. Everything up to
now has been pretty low risk, but this worries me rather more. Maybe
it's safe, but I'd like to hear others' comments.

Yeah, it makes me a bit nervous too. We know that most of the code is
agnostic as to the width of pid_t, because it works on Unixen where
pid_t is 64bit. But I'm less sure about whether the Windows-specific
parts are equally flexible.

On the other hand, wouldn't you expect to get compiler warnings for
any code that does get affected? The main hazard would be incorrect
printf format flags (cf 994f11257 for a recent example), and I'd
certainly expect any C compiler worth its salt to whine about
inconsistencies there.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#114Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#113)
Re: VS 2015 support in src/tools/msvc

I wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

On 04/23/2016 05:30 PM, Christian Ullrich wrote:

In this case, I would prefer this:

#ifdef WIN32_ONLY_COMPILER
-typedef int pid_t;
+typedef intptr_t pid_t;
#endif

That's a change that will have a pretty wide effect. Everything up to
now has been pretty low risk, but this worries me rather more. Maybe
it's safe, but I'd like to hear others' comments.

Yeah, it makes me a bit nervous too.

One other thought: even if this is safe for HEAD, I think we could
*not* back-patch it into 9.5, because it would amount to an ABI
break on Windows anywhere that pid_t is used in globally visible
structs or function signatures. (Maybe there are no such places,
but I doubt it.) So we'd need to go with the messy-cast solution
for 9.5.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#115Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#114)
Re: VS 2015 support in src/tools/msvc

On 04/23/2016 06:33 PM, Tom Lane wrote:

I wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

On 04/23/2016 05:30 PM, Christian Ullrich wrote:

In this case, I would prefer this:

#ifdef WIN32_ONLY_COMPILER
-typedef int pid_t;
+typedef intptr_t pid_t;
#endif

That's a change that will have a pretty wide effect. Everything up to
now has been pretty low risk, but this worries me rather more. Maybe
it's safe, but I'd like to hear others' comments.

Yeah, it makes me a bit nervous too.

One other thought: even if this is safe for HEAD, I think we could
*not* back-patch it into 9.5, because it would amount to an ABI
break on Windows anywhere that pid_t is used in globally visible
structs or function signatures. (Maybe there are no such places,
but I doubt it.) So we'd need to go with the messy-cast solution
for 9.5.

It's not that messy. I'm inclined just to make minimal changed to
pg_basebackup.c and be done with it. I don't think a compiler warning is
worth doing more for.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#116Petr Jelinek
petr@2ndquadrant.com
In reply to: Christian Ullrich (#109)
Re: VS 2015 support in src/tools/msvc

On 23/04/16 08:08, Christian Ullrich wrote:

* Christian Ullrich wrote:

* Andrew Dunstan wrote:

On 04/22/2016 02:46 AM, Michael Paquier wrote:

Progress report:

1. My VS 2015 installations (I now have several) all generate
solution file
with:
Microsoft Visual Studio Solution File, Format Version 12.00
so I propose to set that as the solution file version.

I am wondering why it happens this way for you..

It's not just me. See the reply at
<https://social.msdn.microsoft.com/Forums/sqlserver/en-US/ea671596-9e8d-4e80-bb1f-8c9bfb1738dc/2012-and-2015-solutions?forum=vcgeneral&gt;

and notice that in both cases the Solution file format is version 12.00.

Try as I may, I cannot get my VS 2015 to write a version 14 .sln file.
It's always "12.00". If I change it to 14 by hand, it still opens and
appears to work fine.

I tried to find a real-world version 14 solution to see if I can spot a
difference between it and the version 12 files, but there appears to be
very little out there, and what there is, looks like it was either
autogenerated or edited manually. Examples:

OK, so searching on GitHub yielded a few more results, but I could not
identify a single one that was clearly not created or edited by anything
other than Visual Studio itself.

I did some checking too, and yes it seems having version 12 .sln is fine
or maybe even desirable. We mainly need to make sure that the tools
version is 14 and platform toolset is v140 for MSVC15.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#117Andrew Dunstan
andrew@dunslane.net
In reply to: Andrew Dunstan (#115)
1 attachment(s)
Re: VS 2015 support in src/tools/msvc

On 04/23/2016 11:25 PM, Andrew Dunstan wrote:

On 04/23/2016 06:33 PM, Tom Lane wrote:

I wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

On 04/23/2016 05:30 PM, Christian Ullrich wrote:

In this case, I would prefer this:

#ifdef WIN32_ONLY_COMPILER
-typedef int pid_t;
+typedef intptr_t pid_t;
#endif

That's a change that will have a pretty wide effect. Everything up to
now has been pretty low risk, but this worries me rather more. Maybe
it's safe, but I'd like to hear others' comments.

Yeah, it makes me a bit nervous too.

One other thought: even if this is safe for HEAD, I think we could
*not* back-patch it into 9.5, because it would amount to an ABI
break on Windows anywhere that pid_t is used in globally visible
structs or function signatures. (Maybe there are no such places,
but I doubt it.) So we'd need to go with the messy-cast solution
for 9.5.

It's not that messy. I'm inclined just to make minimal changed to
pg_basebackup.c and be done with it. I don't think a compiler warning
is worth doing more for.

OK, here's my final version of the patch, which I will apply in 24 hours
or so unless there is an objection.

cheers

andrew

Attachments:

VS2015-support.patchbinary/octet-stream; name=VS2015-support.patchDownload
diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index 74265fc..57bc88b 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -19,10 +19,10 @@
  <para>
   There are several different ways of building PostgreSQL on
   <productname>Windows</productname>. The simplest way to build with
-  Microsoft tools is to install <productname>Visual Studio Express 2013
+  Microsoft tools is to install <productname>Visual Studio Express 2015
   for Windows Desktop</productname> and use the included
   compiler. It is also possible to build with the full
-  <productname>Microsoft Visual C++ 2005 to 2013</productname>.
+  <productname>Microsoft Visual C++ 2005 to 2015</productname>.
   In some cases that requires the installation of the
   <productname>Windows SDK</productname> in addition to the compiler.
  </para>
@@ -77,7 +77,7 @@
   <productname>Visual Studio Express</productname> or some versions of the
   <productname>Microsoft Windows SDK</productname>. If you do not already have a
   <productname>Visual Studio</productname> environment set up, the easiest
-  ways are to use the compilers from <productname>Visual Studio Express 2013
+  ways are to use the compilers from <productname>Visual Studio Express 2015
   for Windows Desktop</productname> or those in the <productname>Windows SDK
   7.1</productname>, which are both free downloads from Microsoft.
  </para>
@@ -85,11 +85,17 @@
  <para>
   PostgreSQL is known to support compilation using the compilers shipped with
   <productname>Visual Studio 2005</productname> to
-  <productname>Visual Studio 2013</productname> (including Express editions),
+  <productname>Visual Studio 2015</productname> (including Express editions),
   as well as standalone Windows SDK releases 6.0 to 7.1.
   64-bit PostgreSQL builds are only supported with
   <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
-  <productname>Visual Studio 2008</productname> and above.
+  <productname>Visual Studio 2008</productname> and above. Compilation
+  is supported down to <productname>Windows XP</productname> and
+  <productname>Windows Server 2003</> when building with
+  <productname>Visual Studio 2005</> to
+  <productname>Visual Studio 2013</productname>. Building with
+  <productname>Visual Studio 2015</productname> is supported down to
+  <productname>Windows Vista</> and <productname>Windows Server 2008</>.
  </para>
 
  <para>
diff --git a/src/backend/port/win32/crashdump.c b/src/backend/port/win32/crashdump.c
index ec7c325..7c61ccb 100644
--- a/src/backend/port/win32/crashdump.c
+++ b/src/backend/port/win32/crashdump.c
@@ -41,7 +41,15 @@
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <string.h>
+/*
+ * Some versions of the MS SDK contain "typedef enum { ... } ;" which the MS
+ * compiler quite sanely complains about. Well done, Microsoft.
+ * This pragma disables the warning just while we include the header.
+ */
+#pragma warning(push)
+#pragma warning(disable : 4091)
 #include <dbghelp.h>
+#pragma warning(pop)
 
 /*
  * Much of the following code is based on CodeProject and MSDN examples,
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 5676d50..2927b60 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -1830,6 +1830,11 @@ BaseBackup(void)
 		int			r;
 #else
 		DWORD		status;
+		/*
+		 * get a pointer sized version of bgchild to avoid warnings about
+		 * casting to a different size on WIN64.
+		 */
+		intptr_t	bgchild_handle = bgchild;
 		uint32		hi,
 					lo;
 #endif
@@ -1892,7 +1897,7 @@ BaseBackup(void)
 		InterlockedIncrement(&has_xlogendptr);
 
 		/* First wait for the thread to exit */
-		if (WaitForSingleObjectEx((HANDLE) bgchild, INFINITE, FALSE) !=
+		if (WaitForSingleObjectEx((HANDLE) bgchild_handle, INFINITE, FALSE) !=
 			WAIT_OBJECT_0)
 		{
 			_dosmaperr(GetLastError());
@@ -1900,7 +1905,7 @@ BaseBackup(void)
 					progname, strerror(errno));
 			disconnect_and_exit(1);
 		}
-		if (GetExitCodeThread((HANDLE) bgchild, &status) == 0)
+		if (GetExitCodeThread((HANDLE) bgchild_handle, &status) == 0)
 		{
 			_dosmaperr(GetLastError());
 			fprintf(stderr, _("%s: could not get child thread exit status: %s\n"),
diff --git a/src/include/port/win32.h b/src/include/port/win32.h
index bd2ad99..d83cd40 100644
--- a/src/include/port/win32.h
+++ b/src/include/port/win32.h
@@ -6,14 +6,28 @@
 
 /*
  * Make sure _WIN32_WINNT has the minimum required value.
- * Leave a higher value in place.
-*/
-#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0501
+ * Leave a higher value in place. When building with at least Visual
+ * Studio 2015 the minimum requirement is Windows Vista (0x0600) to
+ * get support for GetLocaleInfoEx() with locales. For everything else
+ * the minumum version os Windows XP (0x0501).
+ * Also  for VS2015, add a define that stops compiler complaints about
+ * using the old Winsock API.
+ */
+#if defined(_MSC_VER) && _MSC_VER >= 1900
+#define  _WINSOCK_DEPRECATED_NO_WARNINGS
+#define MIN_WINNT 0x0600
+#else
+#define MIN_WINNT 0x0501
+#endif
+
+#if defined(_WIN32_WINNT) && _WIN32_WINNT < MIN_WINNT
 #undef _WIN32_WINNT
 #endif
+
 #ifndef _WIN32_WINNT
-#define _WIN32_WINNT 0x0501
+#define _WIN32_WINNT MIN_WINNT
 #endif
+
 /*
  * Always build with SSPI support. Keep it as a #define in case
  * we want a switch to disable it sometime in the future.
diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..59a6415 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -19,6 +19,10 @@
 #include "postgres_fe.h"
 #endif
 
+#if defined(WIN32) && (_MSC_VER >= 1900)
+#include <windows.h>
+#endif
+
 #include <locale.h>
 #ifdef HAVE_LANGINFO_H
 #include <langinfo.h>
@@ -196,6 +200,16 @@ static const struct encoding_match encoding_match_list[] = {
  * locale machinery determine the code page.  See comments at IsoLocaleName().
  * For other compilers, follow the locale's predictable format.
  *
+ * Visual Studio 2015 should still be able to do the same, but the declaration
+ * of lc_codepage is missing in _locale_t, causing this code compilation to
+ * fail, hence this falls back instead on GetLocaleInfoEx. VS 2015 may be an
+ * exception and post-VS2015 versions should be able to handle properly the
+ * codepage number using _create_locale(). So, instead of the same logic as
+ * VS 2012 and VS 2013, this routine uses GetLocaleInfoEx to parse short
+ * locale names like "de-DE", "fr-FR", etc. If those cannot be parsed correctly
+ * process falls back to the pre-VS-2010 manual parsing done with
+ * using <Language>_<Country>.<CodePage> as a base.
+ *
  * Returns a malloc()'d string for the caller to free.
  */
 static char *
@@ -203,7 +217,7 @@ win32_langinfo(const char *ctype)
 {
 	char	   *r = NULL;
 
-#if (_MSC_VER >= 1700)
+#if (_MSC_VER >= 1700) && (_MSC_VER < 1900)
 	_locale_t	loct = NULL;
 
 	loct = _create_locale(LC_CTYPE, ctype);
@@ -217,6 +231,25 @@ win32_langinfo(const char *ctype)
 #else
 	char	   *codepage;
 
+#if (_MSC_VER >= 1900)
+	uint32		cp;
+	WCHAR		wctype[80];
+
+	memset(wctype, 0, 80 * sizeof(WCHAR));
+	MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, 80);
+
+	if (GetLocaleInfoEx(wctype,
+			LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
+			(LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0)
+	{
+		r = malloc(16);			/* excess */
+		if (r != NULL)
+			sprintf(r, "CP%u", cp);
+	}
+	else
+	{
+#endif
+
 	/*
 	 * Locale format on Win32 is <Language>_<Country>.<CodePage> . For
 	 * example, English_United States.1252.
@@ -232,6 +265,10 @@ win32_langinfo(const char *ctype)
 		if (r != NULL)
 			sprintf(r, "CP%s", codepage);
 	}
+
+#if (_MSC_VER >= 1900)
+	}
+#endif
 #endif
 
 	return r;
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 3d60b64..d7638b4 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -465,4 +465,27 @@ sub new
 	return $self;
 }
 
+package VC2015Project;
+
+#
+# Package that encapsulates a Visual C++ 2015 project file
+#
+
+use strict;
+use warnings;
+use base qw(VC2012Project);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{vcver}           = '14.00';
+	$self->{PlatformToolset} = 'v140';
+	$self->{ToolsVersion}    = '14.0';
+
+	return $self;
+}
+
 1;
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index ac1ba0a..43620c2 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -790,6 +790,32 @@ sub new
 	return $self;
 }
 
+package VS2015Solution;
+
+#
+# Package that encapsulates a Visual Studio 2015 solution file
+#
+
+use Carp;
+use strict;
+use warnings;
+use base qw(Solution);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{solutionFileVersion}        = '12.00';
+	$self->{vcver}                      = '14.00';
+	$self->{visualStudioName}           = 'Visual Studio 2015';
+	$self->{VisualStudioVersion}        = '14.0.24730.2';
+	$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
+
+	return $self;
+}
+
 sub GetAdditionalHeaders
 {
 	my ($self, $f) = @_;
diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm
index fee4684..4190ada 100644
--- a/src/tools/msvc/VSObjectFactory.pm
+++ b/src/tools/msvc/VSObjectFactory.pm
@@ -49,6 +49,10 @@ sub CreateSolution
 	{
 		return new VS2013Solution(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VS2015Solution(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -84,6 +88,10 @@ sub CreateProject
 	{
 		return new VC2013Project(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VC2015Project(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion
 sub _GetVisualStudioVersion
 {
 	my ($major, $minor) = @_;
-	if ($major > 12)
+	if ($major > 14)
 	{
 		carp
 "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
-		return '12.00';
+		return '14.00';
 	}
 	elsif ($major < 6)
 	{
#118Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#117)
Re: VS 2015 support in src/tools/msvc

Andrew Dunstan <andrew@dunslane.net> writes:

OK, here's my final version of the patch, which I will apply in 24 hours
or so unless there is an objection.

+#pragma warning(push)
+#pragma warning(disable : 4091)
#include <dbghelp.h>
+#pragma warning(pop)

Hmm ... does this pragma work on *every* compiler we're going to use
on Windows? I'm afraid that trying to suppress a warning in VS2015
is going to result in outright failure with other compilers.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#119Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#117)
Re: VS 2015 support in src/tools/msvc

Andrew Dunstan <andrew@dunslane.net> writes:

OK, here's my final version of the patch, which I will apply in 24 hours
or so unless there is an objection.

BTW, in view of 9f633b404, shouldn't there be a similar addition to
win32env.c in this patch?

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#120Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#118)
Re: VS 2015 support in src/tools/msvc

On 04/24/2016 11:58 AM, Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

OK, here's my final version of the patch, which I will apply in 24 hours
or so unless there is an objection.
+#pragma warning(push)
+#pragma warning(disable : 4091)
#include <dbghelp.h>
+#pragma warning(pop)

Hmm ... does this pragma work on *every* compiler we're going to use
on Windows? I'm afraid that trying to suppress a warning in VS2015
is going to result in outright failure with other compilers.

According to my research it works on all the MSVC versions we support. I
didn't research the others (i.e. gcc), but we already use the pragma in
float.c without ill effect. Isn't the way #pragma works that compilers
that don't understand the particular pragma are just supposed to ignore it?

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#121Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#120)
Re: VS 2015 support in src/tools/msvc

Andrew Dunstan <andrew@dunslane.net> writes:

On 04/24/2016 11:58 AM, Tom Lane wrote:

Hmm ... does this pragma work on *every* compiler we're going to use
on Windows?

According to my research it works on all the MSVC versions we support. I
didn't research the others (i.e. gcc), but we already use the pragma in
float.c without ill effect. Isn't the way #pragma works that compilers
that don't understand the particular pragma are just supposed to ignore it?

Well, the ones in float.c are guarded by "#if (_MSC_VER >= 1800)" and
will therefore not get compiled by any non-MSVC compiler. I don't see
any entirely-unprotected #pragma uses in our tree, indicating that
we've not depended on any such assumption up to now.

Given that the whole file is platform-specific, it may well be fine;
I'm just voicing some concern. I suppose the buildfarm will soon
tell us if it's not fine, though.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#122Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#119)
Re: VS 2015 support in src/tools/msvc

On 04/24/2016 12:14 PM, Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

OK, here's my final version of the patch, which I will apply in 24 hours
or so unless there is an objection.

BTW, in view of 9f633b404, shouldn't there be a similar addition to
win32env.c in this patch?

msvcr120.dll seems to be the highest numbered one on my system, and we
already cover that. If you like we can add to the comments in that file.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#123Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#122)
Re: VS 2015 support in src/tools/msvc

Andrew Dunstan <andrew@dunslane.net> writes:

On 04/24/2016 12:14 PM, Tom Lane wrote:

BTW, in view of 9f633b404, shouldn't there be a similar addition to
win32env.c in this patch?

msvcr120.dll seems to be the highest numbered one on my system, and we
already cover that. If you like we can add to the comments in that file.

Yeah, something like s/Visual Studio 2013/Visual Studio 2013 and 2105/
seems like it'd be appropriate. The main thing I'm concerned about is
that this patch touch that list somehow, so that if someone uses it as
a reference for what to consider when adding support for VS N+1, they
know to check there.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#124Christian Ullrich
chris@chrullrich.net
In reply to: Andrew Dunstan (#122)
Re: VS 2015 support in src/tools/msvc

* Andrew Dunstan wrote:

On 04/24/2016 12:14 PM, Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

OK, here's my final version of the patch, which I will apply in 24 hours
or so unless there is an objection.

BTW, in view of 9f633b404, shouldn't there be a similar addition to
win32env.c in this patch?

msvcr120.dll seems to be the highest numbered one on my system, and we
already cover that. If you like we can add to the comments in that file.

There won't be a higher one, with VS 2015, CRT became a system
component, namely, UCRT. However, ucrtbase.dll does export putenv, so it
might need to be added.

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#125Andrew Dunstan
andrew@dunslane.net
In reply to: Christian Ullrich (#124)
Re: VS 2015 support in src/tools/msvc

On 04/24/2016 03:16 PM, Christian Ullrich wrote:

* Andrew Dunstan wrote:

On 04/24/2016 12:14 PM, Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

OK, here's my final version of the patch, which I will apply in 24
hours
or so unless there is an objection.

BTW, in view of 9f633b404, shouldn't there be a similar addition to
win32env.c in this patch?

msvcr120.dll seems to be the highest numbered one on my system, and we
already cover that. If you like we can add to the comments in that file.

There won't be a higher one, with VS 2015, CRT became a system
component, namely, UCRT. However, ucrtbase.dll does export putenv, so
it might need to be added.

OK. Does that mean we won't have to add anything more for future VS
releases?

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#126Christian Ullrich
chris@chrullrich.net
In reply to: Andrew Dunstan (#125)
Re: VS 2015 support in src/tools/msvc

* Andrew Dunstan wrote:

On 04/24/2016 03:16 PM, Christian Ullrich wrote:

* Andrew Dunstan wrote:

msvcr120.dll seems to be the highest numbered one on my system, and we
already cover that. If you like we can add to the comments in that file.

There won't be a higher one, with VS 2015, CRT became a system
component, namely, UCRT. However, ucrtbase.dll does export putenv, so
it might need to be added.

OK. Does that mean we won't have to add anything more for future VS
releases?

Microsoft is swearing up one side and down the other that they will keep
binary compatibility forever, and ever, hallelujah, hallelujah, and
hence the name of the DLL is not expected to change again.

OTOH, the next manager of the development tools division might have
different ideas. You never know.

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#127Christian Ullrich
chris@chrullrich.net
In reply to: Andrew Dunstan (#117)
Re: VS 2015 support in src/tools/msvc

* Andrew Dunstan wrote:

OK, here's my final version of the patch, which I will apply in 24 hours
or so unless there is an objection.

+  <productname>Visual Studio 2008</productname> and above. Compilation
+  is supported down to <productname>Windows XP</productname> and
+  <productname>Windows Server 2003</> when building with
+  <productname>Visual Studio 2005</> to
+  <productname>Visual Studio 2013</productname>. Building with
+  <productname>Visual Studio 2015</productname> is supported down to
+  <productname>Windows Vista</> and <productname>Windows Server
    2008</>.

This paragraph contradicts itself; it first says 2008 is the minimum
version, right after that it supports 2005, too. The last version of
Visual Studio that will install on XP, 2003, Vista, and 2008 is VS 2010
anyway, anything released after that requires at least 7/2008R2.

I would actually just say "is supported with Visual Studio 2005 [or
possibly 2008] and higher" instead of listing versions. I don't think we
need to recapitulate the system requirements of individual VS releases
and anyone trying to install 2012+ on Vista will quickly find out it
doesn't work. It would be different if we actually excluded particular
VS versions or VS/OS combinations that are supported by VS itself, but
we don't.

+		/*
+		 * get a pointer sized version of bgchild to avoid
                 warnings about
+		 * casting to a different size on WIN64.
+		 */
+		intptr_t	bgchild_handle = bgchild;

If you're going to copy it anyway, why not just use a HANDLE rather than
cast it again later? It's only used in two places, cast to HANDLE in
both, and the special case of -1 does not matter in either.

+ * Leave a higher value in place. When building with at least Visual
+ * Studio 2015 the minimum requirement is Windows Vista (0x0600) to
+ * get support for GetLocaleInfoEx() with locales. For everything else
+ * the minumum version os Windows XP (0x0501).

s/os/is/ in the last line.

This one doesn't matter, but just for perfection's sake:

+#if (_MSC_VER >= 1900)
+	uint32		cp;
+	WCHAR		wctype[80];
+
+	memset(wctype, 0, 80 * sizeof(WCHAR));
+	MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, 80);

The maximum length is documented as 85 characters, also:

<https://msdn.microsoft.com/en-us/library/windows/desktop/dd373815(v=vs.85).aspx&gt;:
'Note Your application must use the constant [LOCALE_NAME_MAX_LENGTH]
for the maximum locale name length, instead of hard-coding the value "85".'

--
Christian

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#128Michael Paquier
michael.paquier@gmail.com
In reply to: Christian Ullrich (#127)
Re: VS 2015 support in src/tools/msvc

On Mon, Apr 25, 2016 at 4:29 AM, Christian Ullrich <chris@chrullrich.net> wrote:

Andrew wrote:

OK, here's my final version of the patch, which I will apply in 24 hours

or so unless there is an objection.

Thanks Andrew for the updated patch!

This one doesn't matter, but just for perfection's sake:

+#if (_MSC_VER >= 1900)
+       uint32          cp;
+       WCHAR           wctype[80];
+
+       memset(wctype, 0, 80 * sizeof(WCHAR));
+       MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, 80);

The maximum length is documented as 85 characters, also:

<https://msdn.microsoft.com/en-us/library/windows/desktop/dd373815(v=vs.85).aspx&gt;:
'Note Your application must use the constant [LOCALE_NAME_MAX_LENGTH] for
the maximum locale name length, instead of hard-coding the value "85".'

Just an addition on top of the comments of Christian..

+#pragma warning(push)
+#pragma warning(disable : 4091)
 #include <dbghelp.h>
+#pragma warning(pop)
It seems to me that we had better protect those pragmas with _MSC_VER

= 1900. The crash dump facility could be used by MinGW as well, no?

--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#129Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#128)
1 attachment(s)
Re: VS 2015 support in src/tools/msvc

On 04/25/2016 03:11 AM, Michael Paquier wrote:

On Mon, Apr 25, 2016 at 4:29 AM, Christian Ullrich <chris@chrullrich.net> wrote:

Andrew wrote:

OK, here's my final version of the patch, which I will apply in 24 hours

or so unless there is an objection.

Thanks Andrew for the updated patch!

This one doesn't matter, but just for perfection's sake:

+#if (_MSC_VER >= 1900)
+       uint32          cp;
+       WCHAR           wctype[80];
+
+       memset(wctype, 0, 80 * sizeof(WCHAR));
+       MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, 80);

The maximum length is documented as 85 characters, also:

<https://msdn.microsoft.com/en-us/library/windows/desktop/dd373815(v=vs.85).aspx&gt;:
'Note Your application must use the constant [LOCALE_NAME_MAX_LENGTH] for
the maximum locale name length, instead of hard-coding the value "85".'

Just an addition on top of the comments of Christian..

+#pragma warning(push)
+#pragma warning(disable : 4091)
#include <dbghelp.h>
+#pragma warning(pop)
It seems to me that we had better protect those pragmas with _MSC_VER

= 1900. The crash dump facility could be used by MinGW as well, no?

I think we're being overcautious here. But to keep people happy I have
protected it with "#ifdef _MSC_VER".

latest patch attached. I have also cleaned up the docs some, and removed
references to the now redundant msysGit.

cheers

andrew

Attachments:

VS2015-support2.patchtext/x-diff; name=VS2015-support2.patchDownload
diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index 74265fc..4e92cc9 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -19,10 +19,10 @@
  <para>
   There are several different ways of building PostgreSQL on
   <productname>Windows</productname>. The simplest way to build with
-  Microsoft tools is to install <productname>Visual Studio Express 2013
+  Microsoft tools is to install <productname>Visual Studio Express 2015
   for Windows Desktop</productname> and use the included
   compiler. It is also possible to build with the full
-  <productname>Microsoft Visual C++ 2005 to 2013</productname>.
+  <productname>Microsoft Visual C++ 2005 to 2015</productname>.
   In some cases that requires the installation of the
   <productname>Windows SDK</productname> in addition to the compiler.
  </para>
@@ -77,19 +77,26 @@
   <productname>Visual Studio Express</productname> or some versions of the
   <productname>Microsoft Windows SDK</productname>. If you do not already have a
   <productname>Visual Studio</productname> environment set up, the easiest
-  ways are to use the compilers from <productname>Visual Studio Express 2013
+  ways are to use the compilers from <productname>Visual Studio Express 2015
   for Windows Desktop</productname> or those in the <productname>Windows SDK
   7.1</productname>, which are both free downloads from Microsoft.
  </para>
 
  <para>
-  PostgreSQL is known to support compilation using the compilers shipped with
+  Both 32-bit and 64-bit builds are possible with the Microsoft Compiler suite.
+  32-bit PostgreSQL buils are possible with
   <productname>Visual Studio 2005</productname> to
-  <productname>Visual Studio 2013</productname> (including Express editions),
+  <productname>Visual Studio 2015</productname> (including Express editions),
   as well as standalone Windows SDK releases 6.0 to 7.1.
-  64-bit PostgreSQL builds are only supported with
+  64-bit PostgreSQL builds are supported with
   <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
-  <productname>Visual Studio 2008</productname> and above.
+  <productname>Visual Studio 2008</productname> and above. Compilation
+  is supported down to <productname>Windows XP</productname> and
+  <productname>Windows Server 2003</> when building with
+  <productname>Visual Studio 2005</> to
+  <productname>Visual Studio 2013</productname>. Building with
+  <productname>Visual Studio 2015</productname> is supported down to
+  <productname>Windows Vista</> and <productname>Windows Server 2008</>.
  </para>
 
  <para>
@@ -210,9 +217,7 @@ $ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
       Both <productname>Bison</productname> and <productname>Flex</productname>
       are included in the <productname>msys</productname> tool suite, available
       from <ulink url="http://www.mingw.org/wiki/MSYS"></> as part of the
-      <productname>MinGW</productname> compiler suite. You can also get
-      <productname>msys</productname> as part of
-      <productname>msysGit</productname> from <ulink url="http://git-scm.com/"></>.
+      <productname>MinGW</productname> compiler suite.
      </para>
 
      <para>
@@ -221,9 +226,7 @@ $ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
       PATH environment variable in <filename>buildenv.pl</filename> unless
       they are already in PATH. In the case of MinGW, the directory is the
       <filename>\msys\1.0\bin</filename> subdirectory of your MinGW
-      installation directory. For msysGit, it's the <filename>bin</filename>
-      directory in your Git install directory. Do not add the MinGW compiler
-      tools themselves to PATH.
+      installation directory.
      </para>
 
      <note>
diff --git a/src/backend/port/win32/crashdump.c b/src/backend/port/win32/crashdump.c
index ec7c325..92e23cb 100644
--- a/src/backend/port/win32/crashdump.c
+++ b/src/backend/port/win32/crashdump.c
@@ -41,7 +41,21 @@
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <string.h>
+/*
+ * Some versions of the MS SDK contain "typedef enum { ... } ;" which the MS
+ * compiler quite sanely complains about. Well done, Microsoft.
+ * This pragma disables the warning just while we include the header.
+ * The pragma is known to work with all (as at the time of writing) supported
+ * versions of MSVC.
+ */
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable : 4091)
+#endif
 #include <dbghelp.h>
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
 
 /*
  * Much of the following code is based on CodeProject and MSDN examples,
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 5676d50..2927b60 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -1830,6 +1830,11 @@ BaseBackup(void)
 		int			r;
 #else
 		DWORD		status;
+		/*
+		 * get a pointer sized version of bgchild to avoid warnings about
+		 * casting to a different size on WIN64.
+		 */
+		intptr_t	bgchild_handle = bgchild;
 		uint32		hi,
 					lo;
 #endif
@@ -1892,7 +1897,7 @@ BaseBackup(void)
 		InterlockedIncrement(&has_xlogendptr);
 
 		/* First wait for the thread to exit */
-		if (WaitForSingleObjectEx((HANDLE) bgchild, INFINITE, FALSE) !=
+		if (WaitForSingleObjectEx((HANDLE) bgchild_handle, INFINITE, FALSE) !=
 			WAIT_OBJECT_0)
 		{
 			_dosmaperr(GetLastError());
@@ -1900,7 +1905,7 @@ BaseBackup(void)
 					progname, strerror(errno));
 			disconnect_and_exit(1);
 		}
-		if (GetExitCodeThread((HANDLE) bgchild, &status) == 0)
+		if (GetExitCodeThread((HANDLE) bgchild_handle, &status) == 0)
 		{
 			_dosmaperr(GetLastError());
 			fprintf(stderr, _("%s: could not get child thread exit status: %s\n"),
diff --git a/src/include/port/win32.h b/src/include/port/win32.h
index bd2ad99..ddf8187 100644
--- a/src/include/port/win32.h
+++ b/src/include/port/win32.h
@@ -6,14 +6,28 @@
 
 /*
  * Make sure _WIN32_WINNT has the minimum required value.
- * Leave a higher value in place.
-*/
-#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0501
+ * Leave a higher value in place. When building with at least Visual
+ * Studio 2015 the minimum requirement is Windows Vista (0x0600) to
+ * get support for GetLocaleInfoEx() with locales. For everything else
+ * the minumum version is Windows XP (0x0501).
+ * Also  for VS2015, add a define that stops compiler complaints about
+ * using the old Winsock API.
+ */
+#if defined(_MSC_VER) && _MSC_VER >= 1900
+#define  _WINSOCK_DEPRECATED_NO_WARNINGS
+#define MIN_WINNT 0x0600
+#else
+#define MIN_WINNT 0x0501
+#endif
+
+#if defined(_WIN32_WINNT) && _WIN32_WINNT < MIN_WINNT
 #undef _WIN32_WINNT
 #endif
+
 #ifndef _WIN32_WINNT
-#define _WIN32_WINNT 0x0501
+#define _WIN32_WINNT MIN_WINNT
 #endif
+
 /*
  * Always build with SSPI support. Keep it as a #define in case
  * we want a switch to disable it sometime in the future.
diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index a551fdc..f6edf54 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -19,6 +19,10 @@
 #include "postgres_fe.h"
 #endif
 
+#if defined(WIN32) && (_MSC_VER >= 1900)
+#include <windows.h>
+#endif
+
 #include <locale.h>
 #ifdef HAVE_LANGINFO_H
 #include <langinfo.h>
@@ -196,6 +200,16 @@ static const struct encoding_match encoding_match_list[] = {
  * locale machinery determine the code page.  See comments at IsoLocaleName().
  * For other compilers, follow the locale's predictable format.
  *
+ * Visual Studio 2015 should still be able to do the same, but the declaration
+ * of lc_codepage is missing in _locale_t, causing this code compilation to
+ * fail, hence this falls back instead on GetLocaleInfoEx. VS 2015 may be an
+ * exception and post-VS2015 versions should be able to handle properly the
+ * codepage number using _create_locale(). So, instead of the same logic as
+ * VS 2012 and VS 2013, this routine uses GetLocaleInfoEx to parse short
+ * locale names like "de-DE", "fr-FR", etc. If those cannot be parsed correctly
+ * process falls back to the pre-VS-2010 manual parsing done with
+ * using <Language>_<Country>.<CodePage> as a base.
+ *
  * Returns a malloc()'d string for the caller to free.
  */
 static char *
@@ -203,7 +217,7 @@ win32_langinfo(const char *ctype)
 {
 	char	   *r = NULL;
 
-#if (_MSC_VER >= 1700)
+#if (_MSC_VER >= 1700) && (_MSC_VER < 1900)
 	_locale_t	loct = NULL;
 
 	loct = _create_locale(LC_CTYPE, ctype);
@@ -217,6 +231,25 @@ win32_langinfo(const char *ctype)
 #else
 	char	   *codepage;
 
+#if (_MSC_VER >= 1900)
+	uint32		cp;
+	WCHAR		wctype[LOCALE_NAME_MAX_LENGTH];
+
+	memset(wctype, 0, sizeof(wctype));
+	MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, LOCALE_NAME_MAX_LENGTH);
+
+	if (GetLocaleInfoEx(wctype,
+			LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
+			(LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0)
+	{
+		r = malloc(16);			/* excess */
+		if (r != NULL)
+			sprintf(r, "CP%u", cp);
+	}
+	else
+	{
+#endif
+
 	/*
 	 * Locale format on Win32 is <Language>_<Country>.<CodePage> . For
 	 * example, English_United States.1252.
@@ -232,6 +265,10 @@ win32_langinfo(const char *ctype)
 		if (r != NULL)
 			sprintf(r, "CP%s", codepage);
 	}
+
+#if (_MSC_VER >= 1900)
+	}
+#endif
 #endif
 
 	return r;
diff --git a/src/port/win32env.c b/src/port/win32env.c
index 7e4ff62..d6b0ebe 100644
--- a/src/port/win32env.c
+++ b/src/port/win32env.c
@@ -70,6 +70,9 @@ pgwin32_putenv(const char *envval)
 			"msvcr120", 0, NULL
 		},						/* Visual Studio 2013 */
 		{
+			"urctbase", 0, NULL
+		},						/* Visual Studio 2015 and later */
+		{
 			NULL, 0, NULL
 		}
 	};
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 3d60b64..d7638b4 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -465,4 +465,27 @@ sub new
 	return $self;
 }
 
+package VC2015Project;
+
+#
+# Package that encapsulates a Visual C++ 2015 project file
+#
+
+use strict;
+use warnings;
+use base qw(VC2012Project);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{vcver}           = '14.00';
+	$self->{PlatformToolset} = 'v140';
+	$self->{ToolsVersion}    = '14.0';
+
+	return $self;
+}
+
 1;
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index ac1ba0a..43620c2 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -790,6 +790,32 @@ sub new
 	return $self;
 }
 
+package VS2015Solution;
+
+#
+# Package that encapsulates a Visual Studio 2015 solution file
+#
+
+use Carp;
+use strict;
+use warnings;
+use base qw(Solution);
+
+sub new
+{
+	my $classname = shift;
+	my $self      = $classname->SUPER::_new(@_);
+	bless($self, $classname);
+
+	$self->{solutionFileVersion}        = '12.00';
+	$self->{vcver}                      = '14.00';
+	$self->{visualStudioName}           = 'Visual Studio 2015';
+	$self->{VisualStudioVersion}        = '14.0.24730.2';
+	$self->{MinimumVisualStudioVersion} = '10.0.40219.1';
+
+	return $self;
+}
+
 sub GetAdditionalHeaders
 {
 	my ($self, $f) = @_;
diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm
index fee4684..4190ada 100644
--- a/src/tools/msvc/VSObjectFactory.pm
+++ b/src/tools/msvc/VSObjectFactory.pm
@@ -49,6 +49,10 @@ sub CreateSolution
 	{
 		return new VS2013Solution(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VS2015Solution(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -84,6 +88,10 @@ sub CreateProject
 	{
 		return new VC2013Project(@_);
 	}
+	elsif ($visualStudioVersion eq '14.00')
+	{
+		return new VC2015Project(@_);
+	}
 	else
 	{
 		croak "The requested Visual Studio version is not supported.";
@@ -112,11 +120,11 @@ sub DetermineVisualStudioVersion
 sub _GetVisualStudioVersion
 {
 	my ($major, $minor) = @_;
-	if ($major > 12)
+	if ($major > 14)
 	{
 		carp
 "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
-		return '12.00';
+		return '14.00';
 	}
 	elsif ($major < 6)
 	{
#130Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#129)
Re: VS 2015 support in src/tools/msvc

Andrew Dunstan <andrew@dunslane.net> writes:

latest patch attached. I have also cleaned up the docs some, and removed
references to the now redundant msysGit.

Please don't do stuff like this:

@@ -232,6 +265,10 @@ win32_langinfo(const char *ctype)
 		if (r != NULL)
 			sprintf(r, "CP%s", codepage);
 	}
+
+#if (_MSC_VER >= 1900)
+	}
+#endif
 #endif

return r;

I'm not very sure what pgindent will do with conditionally-included
indentation, but it's unlikely to be pleasing.

In this particular case, you could probably fix it by making the
other end of that be

+	if (GetLocaleInfoEx(wctype,
+			LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
+			(LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0)
+	{
+		r = malloc(16);			/* excess */
+		if (r != NULL)
+			sprintf(r, "CP%u", cp);
+	}
+	else
+#endif
+	{
+

and omitting the #if/#endif around the trailing }.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#131Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#130)
Re: VS 2015 support in src/tools/msvc

On 04/29/2016 12:39 AM, Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

latest patch attached. I have also cleaned up the docs some, and removed
references to the now redundant msysGit.

Please don't do stuff like this:

@@ -232,6 +265,10 @@ win32_langinfo(const char *ctype)
if (r != NULL)
sprintf(r, "CP%s", codepage);
}
+
+#if (_MSC_VER >= 1900)
+	}
+#endif
#endif

return r;

I'm not very sure what pgindent will do with conditionally-included
indentation, but it's unlikely to be pleasing.

In this particular case, you could probably fix it by making the
other end of that be

+	if (GetLocaleInfoEx(wctype,
+			LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
+			(LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0)
+	{
+		r = malloc(16);			/* excess */
+		if (r != NULL)
+			sprintf(r, "CP%u", cp);
+	}
+	else
+#endif
+	{
+

and omitting the #if/#endif around the trailing }.

Yeah, I noticed the ugliness, should have fixed it. Applied your fix and
committed.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#132Michael Paquier
michael.paquier@gmail.com
In reply to: Andrew Dunstan (#131)
Re: VS 2015 support in src/tools/msvc

On Fri, Apr 29, 2016 at 9:13 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

Yeah, I noticed the ugliness, should have fixed it. Applied your fix and
committed.

Thanks for the commit!

Nitpick comment:
+ * Also  for VS2015, add a define that stops compiler complaints about
Two spaces instead of one between "Also" and "for" :)
-- 
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#133Petr Jelinek
petr@2ndquadrant.com
In reply to: Michael Paquier (#132)
Re: VS 2015 support in src/tools/msvc

On 29/04/16 16:02, Michael Paquier wrote:

On Fri, Apr 29, 2016 at 9:13 PM, Andrew Dunstan <andrew@dunslane.net> wrote:

Yeah, I noticed the ugliness, should have fixed it. Applied your fix and
committed.

Thanks for the commit!

+1

After bit of fighting with the system the "caecilian" reported first
successful build to the buildfarm.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#134Michael Paquier
michael.paquier@gmail.com
In reply to: Petr Jelinek (#133)
Re: VS 2015 support in src/tools/msvc

On Sat, Apr 30, 2016 at 12:22 AM, Petr Jelinek <petr@2ndquadrant.com> wrote:

After bit of fighting with the system the "caecilian" reported first
successful build to the buildfarm.

Thanks! The fight was there as well.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers