On Fri, Mar 4, 2016 at 3:54 PM, Michael Paquier
<michael.paqu...@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
"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\ascii_and_mic.vcxproj" (default target) (2) ->
"C:\Users\IEUser\git\postgres\postgres.vcxproj" (default target) (3) ->
(ClCompile target) ->
  src/backend/libpq/ip.c(476): warning C4996: 'WSASocketA': Use WSASocketW() 
instead or define _WINSOCK_DEPRECATED_NO_W
ARNINGS to disable deprecated API warnings 
[C:\Users\IEUser\git\postgres\postgres.vcxproj]
  C:\Program Files (x86)\Windows Kits\8.1\Include\um\dbghelp.h(1544): warning 
C4091: 'typedef ': ignored on left of ''
when no variable is declared (compiling source file 
src/backend/port/win32/crashdump.c) [C:\Users\IEUser\git\postgres\p
ostgres.vcxproj]
  C:\Program Files (x86)\Windows Kits\8.1\Include\um\dbghelp.h(3190): warning 
C4091: 'typedef ': ignored on left of ''
when no variable is declared (compiling source file 
src/backend/port/win32/crashdump.c) [C:\Users\IEUser\git\postgres\p
ostgres.vcxproj]
  src/backend/port/win32/socket.c(247): warning C4996: 'WSASocketA': Use 
WSASocketW() instead or define _WINSOCK_DEPREC
ATED_NO_WARNINGS to disable deprecated API warnings 
[C:\Users\IEUser\git\postgres\postgres.vcxproj]
  src/backend/postmaster/postmaster.c(5892): warning C4996: 
'WSADuplicateSocketA': Use WSADuplicateSocketW() instead or
 define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings 
[C:\Users\IEUser\git\postgres\postgres.vcxpr
oj]
  src/backend/postmaster/postmaster.c(5919): warning C4996: 'WSASocketA': Use 
WSASocketW() instead or define _WINSOCK_D
EPRECATED_NO_WARNINGS to disable deprecated API warnings 
[C:\Users\IEUser\git\postgres\postgres.vcxproj]
  src/port/getaddrinfo.c(199): warning C4996: 'gethostbyname': Use 
getaddrinfo() or GetAddrInfoW() instead or define _W
INSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings 
[C:\Users\IEUser\git\postgres\postgres.vcxproj]
  src/port/thread.c(134): warning C4996: 'gethostbyname': Use getaddrinfo() or 
GetAddrInfoW() instead or define _WINSOC
K_DEPRECATED_NO_WARNINGS to disable deprecated API warnings 
[C:\Users\IEUser\git\postgres\postgres.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\latin2_and_win1250.vcxproj" (default target) (9) 
->
(PrepareForBuild target) ->
  C:\Program Files 
(x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(392,5): 
warning MSB8028: The interm
ediate directory (.\Release\latin2_and_win1250\) contains files shared from 
another project (latin2_and_win1250.vcxproj
, latin2_and_win1250.vcxproj).  This can lead to incorrect clean and rebuild 
behavior. [C:\Users\IEUser\git\postgres\la
tin2_and_win1250.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\utf8_and_cyrillic.vcxproj" (default target) (13) 
->
  C:\Program Files 
(x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(392,5): 
warning MSB8028: The interm
ediate directory (.\Release\utf8_and_cyrillic\) contains files shared from 
another project (utf8_and_cyrillic.vcxproj,
utf8_and_cyrillic.vcxproj).  This can lead to incorrect clean and rebuild 
behavior. [C:\Users\IEUser\git\postgres\utf8_
and_cyrillic.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\utf8_and_iso8859_1.vcxproj" (default target) (21) 
->
  C:\Program Files 
(x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(392,5): 
warning MSB8028: The interm
ediate directory (.\Release\utf8_and_iso8859_1\) contains files shared from 
another project (utf8_and_iso8859_1.vcxproj
).  This can lead to incorrect clean and rebuild behavior. 
[C:\Users\IEUser\git\postgres\utf8_and_iso8859_1.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\utf8_and_sjis2004.vcxproj" (default target) (27) 
->
  C:\Program Files 
(x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(392,5): 
warning MSB8028: The interm
ediate directory (.\Release\utf8_and_sjis2004\) contains files shared from 
another project (utf8_and_sjis2004.vcxproj).
  This can lead to incorrect clean and rebuild behavior. 
[C:\Users\IEUser\git\postgres\utf8_and_sjis2004.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\dblink.vcxproj" (default target) (40) ->
"C:\Users\IEUser\git\postgres\libpq.vcxproj" (default target) (41) ->
(ClCompile target) ->
  src/backend/libpq/ip.c(476): warning C4996: 'WSASocketA': Use WSASocketW() 
instead or define _WINSOCK_DEPRECATED_NO_W
ARNINGS to disable deprecated API warnings 
[C:\Users\IEUser\git\postgres\libpq.vcxproj]
  src/port/thread.c(134): warning C4996: 'gethostbyname': Use getaddrinfo() or 
GetAddrInfoW() instead or define _WINSOC
K_DEPRECATED_NO_WARNINGS to disable deprecated API warnings 
[C:\Users\IEUser\git\postgres\libpq.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\pg_stat_statements.vcxproj" (default target) (61) 
->
(PrepareForBuild target) ->
  C:\Program Files 
(x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(392,5): 
warning MSB8028: The interm
ediate directory (.\Release\pg_stat_statements\) contains files shared from 
another project (pg_stat_statements.vcxproj
, pg_stat_statements.vcxproj).  This can lead to incorrect clean and rebuild 
behavior. [C:\Users\IEUser\git\postgres\pg
_stat_statements.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\pg_archivecleanup.vcxproj" (default target) (88) 
->
  C:\Program Files 
(x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(392,5): 
warning MSB8028: The interm
ediate directory (.\Release\pg_archivecleanup\) contains files shared from 
another project (pg_archivecleanup.vcxproj,
pg_archivecleanup.vcxproj).  This can lead to incorrect clean and rebuild 
behavior. [C:\Users\IEUser\git\postgres\pg_ar
chivecleanup.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\pg_basebackup.vcxproj" (default target) (97) ->
(ClCompile target) ->
  src/bin/pg_basebackup/pg_basebackup.c(1885): warning C4312: 'type cast': 
conversion from 'pid_t' to 'HANDLE' of great
er size [C:\Users\IEUser\git\postgres\pg_basebackup.vcxproj]
  src/bin/pg_basebackup/pg_basebackup.c(1893): warning C4312: 'type cast': 
conversion from 'pid_t' to 'HANDLE' of great
er size [C:\Users\IEUser\git\postgres\pg_basebackup.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\libecpg.vcxproj" (default target) (117) ->
  src/port/thread.c(134): warning C4996: 'gethostbyname': Use getaddrinfo() or 
GetAddrInfoW() instead or define _WINSOC
K_DEPRECATED_NO_WARNINGS to disable deprecated API warnings 
[C:\Users\IEUser\git\postgres\libecpg.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\pg_regress_ecpg.vcxproj" (default target) (121) ->
  src/test/regress/pg_regress.c(2396): warning C4311: 'type cast': pointer 
truncation from 'HANDLE' to 'unsigned long'
[C:\Users\IEUser\git\postgres\pg_regress_ecpg.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\pg_isolation_regress.vcxproj" (default target) 
(123) ->
(PrepareForBuild target) ->
  C:\Program Files 
(x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(392,5): 
warning MSB8028: The interm
ediate directory (.\Release\pg_isolation_regress\) contains files shared from 
another project (pg_isolation_regress.vcx
proj, pg_isolation_regress.vcxproj).  This can lead to incorrect clean and 
rebuild behavior. [C:\Users\IEUser\git\postg
res\pg_isolation_regress.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\pg_isolation_regress.vcxproj" (default target) 
(123) ->
(ClCompile target) ->
  src/test/regress/pg_regress.c(2396): warning C4311: 'type cast': pointer 
truncation from 'HANDLE' to 'unsigned long'
[C:\Users\IEUser\git\postgres\pg_isolation_regress.vcxproj]


"C:\Users\IEUser\git\postgres\pgsql.sln" (default target) (1) ->
"C:\Users\IEUser\git\postgres\pg_regress.vcxproj" (default target) (125) ->
  src/test/regress/pg_regress.c(2396): warning C4311: 'type cast': pointer 
truncation from 'HANDLE' to 'unsigned long'
[C:\Users\IEUser\git\postgres\pg_regress.vcxproj]
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

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

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

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

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

Reply via email to