public inbox for [email protected]  
help / color / mirror / Atom feed
From: Joe Conway <[email protected]>
To: Tristan Partin <[email protected]>
To: Heikki Linnakangas <[email protected]>
To: Tom Lane <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG
Date: Sat, 10 Jun 2023 12:12:36 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<[email protected]>
	<CT887GSPI31W.BQCSW35JL67L@gonk>
	<[email protected]>
	<[email protected]>

On 6/9/23 22:10, Joe Conway wrote:
> On 6/9/23 15:05, Joe Conway wrote:
>> I wonder if it isn't a behavior change in libperl itself. It seems
>> that merely doing "load 'plperl';" is enough to cause the issue
> I can reproduce with a simple test program by linking libperl:
> 
> 8<-------- test.c ----------------

A bit more spelunking leads me to the following observations and 
conclusions:

1/ On RHEL7 with perl v5.16.3 the problem does not occur

2/ On RHEL9 with perl v5.32.1 the problem does occur

3/ The difference in behavior is triggered by the newer perl doing a 
bunch of newlocale/uselocale calls not done by the older perl, combined 
with a glibc behavior which seems surprising at best.

 From localeinfo.h in glibc source tree:
8<------------------------
/* This fetches the thread-local locale_t pointer, either one set with
    uselocale or &_nl_global_locale.  */
#define _NL_CURRENT_LOCALE      (__libc_tsd_get (locale_t, LOCALE))
8<------------------------

4/ I successfully tested a fix in the simplified reproducer program sent 
earlier. It amounts to adding:

8<------------------------
   uselocale(LC_GLOBAL_LOCALE);
8<------------------------

prior to calling

8<------------------------
   extlconv = localeconv();
8<------------------------

5/ The attached fixes the issue for me on pg10 and passes check-world.

Comments?

-- 
Joe Conway
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Attachments:

  [text/x-patch] 20230610-plperl_locale_issue-000.patch (1.3K, ../[email protected]/2-20230610-plperl_locale_issue-000.patch)
  download | inline diff:
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index bbf100e..560a324 100644
*** a/src/backend/utils/adt/pg_locale.c
--- b/src/backend/utils/adt/pg_locale.c
*************** PGLC_localeconv(void)
*** 562,567 ****
--- 562,574 ----
  	setlocale(LC_CTYPE, locale_numeric);
  #endif
  
+         /*
+          * Ensure the global locale is being used. This is
+          * necessary, for example, if another loaded library
+          * such as libperl has done uselocale() underneath us.
+          * */
+         uselocale(LC_GLOBAL_LOCALE);
+ 
  	/* Get formatting information for numeric */
  	setlocale(LC_NUMERIC, locale_numeric);
  	extlconv = localeconv();
diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
index e7f31f2..03d6623 100644
*** a/src/fe_utils/print.c
--- b/src/fe_utils/print.c
*************** setDecimalLocale(void)
*** 3402,3407 ****
--- 3402,3413 ----
  {
  	struct lconv *extlconv;
  
+         /*
+          * Ensure the global locale is being used. This is
+          * necessary, for example, if another loaded library
+          * such as libperl has done uselocale() underneath us.
+          * */
+         uselocale(LC_GLOBAL_LOCALE);
  	extlconv = localeconv();
  
  	/* Don't accept an empty decimal_point string */


view thread (4+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox