Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG

From: Joe Conway <mail(at)joeconway(dot)com>
To: Tristan Partin <tristan(at)neon(dot)tech>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, gdo(at)leader(dot)it
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG
Date: 2023-06-10 02:10:20
Message-ID: 5676b739-0854-f924-4b97-466e3504c692@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

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 ----------------
#include <locale.h>
#include <stdio.h>

#define off64_t __off64_t
#include <EXTERN.h>
#include <perl.h>

int
main(int argc, char *argv[])
{
struct lconv *extlconv;
#ifdef WITH_PERL
PerlInterpreter *plperl;
plperl = perl_alloc();
perl_construct(plperl);
#endif
setlocale(LC_MONETARY, "en_GB.UTF-8");
extlconv = localeconv();
printf("currency symbol = \"%s\"\n",
extlconv->currency_symbol);
return 0;
}
8<-------- test.c ----------------

Adjust the perl paths to suit:

8<------------------------
gcc -O0 -ggdb3 -o test \
-I /usr/lib64/perl5/CORE \
-lperl \
test.c

./test
currency symbol = "£"

gcc -O0 -ggdb3 -o test \
-I /usr/lib64/perl5/CORE \
-lperl -DWITH_PERL \
test.c

./test
currency symbol = "$"
8<------------------------

It happens because somehow loading libperl prevents localeconv() from
returning the correct values, even though libperl only seems to call
"setlocale(LC_ALL, NULL)" which ought not change anything.

8<------------------------
gdb ./test

Reading symbols from ./test...
(gdb) b setlocale
Breakpoint 1 at 0x10f0
(gdb) r
Starting program: /opt/src/pgsql-

Breakpoint 1, __GI_setlocale (category=6, locale=0x0) at
./locale/setlocale.c:218
218 ./locale/setlocale.c: No such file or directory.
(gdb) bt
#0 __GI_setlocale (category=6, locale=0x0) at ./locale/setlocale.c:218
#1 0x00007ffff7d96b97 in Perl_init_i18nl10n () from
/lib/x86_64-linux-gnu/libperl.so.5.34
#2 0x0000555555555225 in main (argc=1, argv=0x7fffffffe1d8) at test.c:18
(gdb) c
Continuing.

Breakpoint 1, __GI_setlocale (category=4, locale=0x55555555602e
"en_GB.UTF-8") at ./locale/setlocale.c:218
218 in ./locale/setlocale.c
(gdb) bt
#0 __GI_setlocale (category=4, locale=0x55555555602e "en_GB.UTF-8") at
./locale/setlocale.c:218
#1 0x0000555555555239 in main (argc=1, argv=0x7fffffffe1d8) at test.c:20

main (argc=1, argv=0x7fffffffe1d8) at test.c:21
21 extlconv = localeconv();
(gdb)
22 printf("currency symbol = \"%s\"\n",
(gdb)
currency symbol = "$"
24 return 0;
(gdb)
8<------------------------

Will continue to dig in the morning.

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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Joe Conway 2023-06-10 16:12:36 Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG
Previous Message Joe Conway 2023-06-09 19:05:40 Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2023-06-10 02:23:52 Cleaning up threading code
Previous Message Jeff Davis 2023-06-10 01:45:50 Re: Fix search_path for all maintenance commands