Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG - Mailing list pgsql-bugs

From Joe Conway
Subject Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG
Date
Msg-id 5676b739-0854-f924-4b97-466e3504c692@joeconway.com
Whole thread Raw
In response to Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG  (Joe Conway <mail@joeconway.com>)
Responses Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG  (Joe Conway <mail@joeconway.com>)
List pgsql-bugs
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




pgsql-bugs by date:

Previous
From: Joe Conway
Date:
Subject: Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG
Next
From: Joe Conway
Date:
Subject: Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG