pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe Conway <mail@joeconway.com>
To: Tristan Partin <tristan@neon.tech>
To: Heikki Linnakangas <hlinnaka@iki.fi>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: gdo@leader.it
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG
Date: Sat, 10 Jun 2023 12:12:36 -0400
Message-ID: <f1856a5d-3703-66ff-e7c7-01d2489315c1@joeconway.com> (raw)
In-Reply-To: <5676b739-0854-f924-4b97-466e3504c692@joeconway.com>
References: <17946-3e84cb577e9551c3@postgresql.org>
	<1564676.1685043220@sss.pgh.pa.us>
	<555bb26e-c27c-ab65-028f-3fd5b82df9de@iki.fi>
	<CT887GSPI31W.BQCSW35JL67L@gonk>
	<ca35e375-be82-322d-8c81-78127d8fb33f@joeconway.com>
	<5676b739-0854-f924-4b97-466e3504c692@joeconway.com>

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:

20230610-plperl_locale_issue-000.patch (text/x-patch, 1.3K) download 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 (38+ messages)  latest in thread

Message-ID: <f1856a5d-3703-66ff-e7c7-01d2489315c1@joeconway.com>
Permalink:  ../f1856a5d-3703-66ff-e7c7-01d2489315c1@joeconway.com/
Also on:    postgresql.org/message-id/f1856a5d-3703-66ff-e7c7-01d2489315c1@joeconway.com

 ·  · 

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: pgsql-bugs@postgresql.org
  Cc: mail@joeconway.com, tristan@neon.tech, hlinnaka@iki.fi, tgl@sss.pgh.pa.us, gdo@leader.it, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG
  In-Reply-To: <f1856a5d-3703-66ff-e7c7-01d2489315c1@joeconway.com>

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

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