Re: tiny step toward threading: reduce dependence on setlocale()

Alexander Kukushkin <cyberdemn@gmail.com>

From: Alexander Kukushkin <cyberdemn@gmail.com>
To: Jeff Davis <pgsql@j-davis.com>
Cc: Andreas Karlsson <andreas@proxel.se>, Peter Eisentraut <peter@eisentraut.org>, pgsql-hackers@postgresql.org
Date: 2025-10-28T09:24:46Z
Lists: pgsql-hackers
Hi Jeff,

On Fri, 24 Oct 2025 at 04:37, Jeff Davis <pgsql@j-davis.com> wrote:

>
> Thank you, patch attached, intended for backport to 18.
>

I didn't check it with 18 because changes in regc_pg_locale.c heavily rely
on 5a38104.
However, I think changes to pg_locale.c should be enough to fix the problem
in 18.


> Are you aware of any way to encounter this bug without using an
> extension?
>

I don't think so, but it would be nice to have a test for it anyway.
Unfortunately this test will require a shared_preload_library module.

Regards,
--
Alexander Kukushkin

Commits

  1. Special case C_COLLATION_OID in pg_newlocale_from_collation().

  2. Remove separate locale_is_c arguments

  3. Simplify checks for deterministic collations.

  4. Remove redundant check for default collation.

  5. Remove lc_ctype_is_c().

  6. Be more careful with error paths in pg_set_regex_collation().

  7. Remove lc_collate_is_c().

  8. Remember last collation to speed up collation cache.

  9. Slightly refactor varstr_sortsupport() to improve readability.

  10. Remove unnecessary check for NULL locale, per Coverity.

  11. Remove dead code

  12. selfuncs.c: use pg_strxfrm() instead of strxfrm().

  13. Remove support for null pg_locale_t most places.

  14. Make collation not depend on setlocale().

  15. Do not return NULL from pg_newlocale_from_collation().

  16. Refactor: make default_locale internal to pg_locale.c.

  17. All supported systems have locale_t.