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
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;
-- 
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