Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1adeqO-0004Vb-1S for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Mar 2016 14:12:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1adeqN-0000wg-Fv for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Mar 2016 14:12:07 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1adep0-0006RR-Df for pgsql-hackers@postgresql.org; Wed, 09 Mar 2016 14:10:42 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1adeox-0005Rk-51 for pgsql-hackers@postgresql.org; Wed, 09 Mar 2016 14:10:41 +0000 Received: by mail-wm0-x22b.google.com with SMTP id n186so180172144wmn.1 for ; Wed, 09 Mar 2016 06:10:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to; bh=tl+Cf18K4cYts4cSl8qp7Bm6ctlP+DL9fINWEEj3oWc=; b=pMbB9wTcYzJHAcO01pc6BoZOaXwpujano+mCE4S0gduD38ZMxEqKdfOdkPfe7JYPSq E+AF+4dpJr06b726GRb0clOslkAiVQkB/bHqow0Bq1AVSvJAY4w0XRubDZHHXbUdC/aS yykMHnkR2YI6xdRdLtisQMo2a2FiNwP01ysyNyylg/DoMde3SncWvISdvkgvpbryVrVx Ch4Zmv1PpxdX+o+x85miq9UgdB3SNg7LIyjNMVl8U6wUQC/rVdqDrUFKZyE0IFdhO0km kz2ITgvaEurQh1Ve3okK+ERDIM3HN/38C9wlC5FixJSRYf5YXVdBmIo6Lhh4XvlUXERp C5og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to; bh=tl+Cf18K4cYts4cSl8qp7Bm6ctlP+DL9fINWEEj3oWc=; b=bcVd1R/CB+dCf5udBAKrO4jYt4UCOnLq5K9SyH+oAfyTEvvJztEXRGKn4ZnvumbFYi ErNziVpn65sI0qrwAeoqzZTcwQLRRWfqbD5w75g++/6hd7cBHjGGf0x6urrj/fDVifrK TiG6l+7kNi49HWLNDkUNJqO6/+Ay+tJ8RaPD0HOwhmOZChHJJjv2KkytM57wtdsoYYtP yX1Ytygy98351+sK7YVBzDEUv8kkCUH1PnwkINGucZwL33AWZiz7H1kwEawOzE0/vah5 Mlk3Gkp604E9chWjVW3GcrYErrOkXvo63vlsXwB07PUJS8cIay9fiD77iqDfP3dP7Bab UQlA== X-Gm-Message-State: AD7BkJJg+NNGf/zuUYTEOi7HNcvhlAco8aN7OowBEgdT0oBSAKMOZLBVrUSKpgNdPphk3otTv6Q0p2DmdR/PwCNFL9oVQbqvzEgg5FyuYv3VT/+Z1WxVnWvm8GFu+ZFKjDQw8+HTcI0reB3XAlkKtEJXkQtTrGwlmjnsBwzLKV5Z+ajPphbv9oREZ9C48fWwSw== X-Received: by 10.28.221.136 with SMTP id u130mr25323923wmg.40.1457532637468; Wed, 09 Mar 2016 06:10:37 -0800 (PST) Received: from [192.168.0.103] (150.123.broadband11.iol.cz. [90.178.123.150]) by smtp.gmail.com with ESMTPSA id pd1sm8095519wjb.19.2016.03.09.06.10.35 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 09 Mar 2016 06:10:36 -0800 (PST) Subject: Re: VS 2015 support in src/tools/msvc To: Noah Misch , Michael Paquier References: <56DA6394.9040404@2ndquadrant.com> <15559.1457156815@sss.pgh.pa.us> <56DAEE74.3010604@dunslane.net> <56DB47A5.7040502@dunslane.net> <20160309043137.GA933917@tornado.leadboat.com> Cc: Andrew Dunstan , Tom Lane , Magnus Hagander , PostgreSQL mailing lists From: Petr Jelinek Message-ID: <56E02ED9.1010308@2ndquadrant.com> Date: Wed, 9 Mar 2016 15:10:33 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <20160309043137.GA933917@tornado.leadboat.com> Content-Type: multipart/mixed; boundary="------------020403060209000109040001" X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------020403060209000109040001 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit 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 _. 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 --------------020403060209000109040001 Content-Type: text/x-patch; name="chklocale.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="chklocale.diff" 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 _. . 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; --------------020403060209000109040001 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------020403060209000109040001--