Re: VS 2015 support in src/tools/msvc

From: Petr Jelinek <petr(at)2ndquadrant(dot)com>
To: Christian Ullrich <chris(at)chrullrich(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Magnus Hagander <magnus(at)hagander(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: VS 2015 support in src/tools/msvc
Date: 2016-04-10 21:03:28
Message-ID: 570ABFA0.4090403@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-04-10 21:10:57 Weird irreproducible behaviors in plpython tests
Previous Message Amit Kapila 2016-04-10 18:58:48 Re: Move PinBuffer and UnpinBuffer to atomics