Re: Remaining dependency on setlocale() - Mailing list pgsql-hackers

From Jeff Davis
Subject Re: Remaining dependency on setlocale()
Date
Msg-id 26caf0ee08d9978eba107e2928c3dd164608afb8.camel@j-davis.com
Whole thread Raw
In response to Re: Remaining dependency on setlocale()  ("Daniel Verite" <daniel@manitou-mail.org>)
List pgsql-hackers
On Thu, 2025-10-30 at 21:41 +0100, Daniel Verite wrote:
> What about code in extensions? AFAIU a user can control the
> locale in effect by setting the LC_CTYPE argument of
> CREATE DATABASE, which ends up in the environment
> of backends serving that database.
> If it's forced to "C", how can an extension use locale-aware
> libc functions?

Extensions often need to be updated for a new major version.

The extension should call pg_database_locale(), and pass that to a
function exposed in pg_locale.h. A recent commit exposed pg_iswalpha(),
etc., so there's a reasonable set of functions that should be suitable
for most purposes.

If it's not available in pg_locale.h, or the extension really needs to
use a different LC_CTYPE for some reason, it can use an _l() variant of
the function.

Regards,
    Jeff Davis





pgsql-hackers by date:

Previous
From: "Daniel Verite"
Date:
Subject: Re: Remaining dependency on setlocale()
Next
From: Nathan Bossart
Date:
Subject: Re: another autovacuum scheduling thread