Re: tiny step toward threading: reduce dependence on setlocale() - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: tiny step toward threading: reduce dependence on setlocale()
Date
Msg-id 4f562d84-87f4-44dc-8946-01d6c437936f@eisentraut.org
Whole thread Raw
In response to Re: tiny step toward threading: reduce dependence on setlocale()  (Jeff Davis <pgsql@j-davis.com>)
Responses Re: tiny step toward threading: reduce dependence on setlocale()
Re: tiny step toward threading: reduce dependence on setlocale()
List pgsql-hackers
On 06.08.24 23:40, Jeff Davis wrote:
> With these changes, collations are no longer dependent on the
> environment locale (setlocale()) at all for either collation behavior
> (ORDER BY) or ctype behavior (LOWER(), etc.).
> 
> Additionally, unless I missed something, nothing in the server is
> dependent on LC_COLLATE at all.
> 
> There are still some things that depend on setlocale() in one way or
> another:
> 
>    - char2wchar() & wchar2char()
>    - ts_locale.c
>    - various places that depend on LC_CTYPE unrelated to the collation
> infrastructure
>    - things that depend on other locale settings, like LC_NUMERIC
> 
> We can address those as part of a separate thread. I'll count this as
> committed.

I have a couple of small follow-up patches for this.

First, in like.c, SB_lower_char() now reads:

static char
SB_lower_char(unsigned char c, pg_locale_t locale, bool locale_is_c)
{
     if (locale_is_c)
         return pg_ascii_tolower(c);
     else if (locale)
         return tolower_l(c, locale->info.lt);
     else
         return pg_tolower(c);
}

But after this patch set, locale cannot be NULL anymore, so the third 
branch is obsolete.

(Now that I look at it, pg_tolower() has some short-circuiting for ASCII 
letters, so it would not handle Turkish-i correctly if that had been the 
global locale.  By removing the use of pg_tolower(), we fix that issue 
in passing.)

Second, there are a number of functions in like.c like the above that 
take separate arguments like pg_locale_t locale, bool locale_is_c. 
Because pg_locale_t now contains the locale_is_c information, these can 
be combined.
Attachment

pgsql-hackers by date:

Previous
From: Jelte Fennema-Nio
Date:
Subject: Re: Add trim_trailing_whitespace to editorconfig file
Next
From: Thomas Munro
Date:
Subject: Re: Remaining dependency on setlocale()