Re: pgsql: psql: add an optional execution-count limit to \watch. - Mailing list pgsql-hackers

From Anton Voloshin
Subject Re: pgsql: psql: add an optional execution-count limit to \watch.
Date
Msg-id 5ed7d3e2-ca7e-40ad-9de9-e7648576cc01@postgrespro.ru
Whole thread Raw
Responses Re: pgsql: psql: add an optional execution-count limit to \watch.
List pgsql-hackers
Hello, hackers.

On 18/04/2023 20:34, Tom Lane wrote (on pgsql-committers):
 > I shall now retire to a safe distance and watch the buildfarm.

Unfortunately, on fresh perl (5.38.2 verified) and on ru_RU.UTF-8 
locale, it breaks basic float comparison: 0 < 0.5 is no longer true.

This is the reproduction on REL_16_STABLE (but it affects master
as well), using fresh Ubuntu 24.04 container.

0. I've used lxc to get a fresh container:
$ lxc launch ubuntu-daily:noble u2404
But I don't think lxc or containerization in general matters in this 
case. Also, I think any environment with fresh enough Perl would work, 
Ubuntu 24.04 is just an easy example.

(obviously, install necessary dev packages)

1. Generate ru_RU.UTF-8 locale:
a. In /etc/locale.gen, uncomment the line:
# ru_RU.UTF-8 UTF-8

b. Run locale-gen as root. For me, it says:
$ sudo locale-gen
Generating locales (this might take a while)...
   en_US.UTF-8... done
   ru_RU.UTF-8... done
Generation complete.

2. Apply 0001-demo-of-weird-Perl-setlocale-effect-on-float-numbers.patch
(adding src/test/authentication/t/999_broken.pl)

3. Run the test
LANG=ru_RU.UTF-8 make check -C src/test/authentication 
PROVE_TESTS=t/999_broken.pl PROVE_FLAGS=--verbose

The test is, basically:
use PostgreSQL::Test::Utils;
use Test::More tests => 1;
ok(0 < 0.5, "0 < 0.5");

If I comment-out the "use PostgreSQL::Test::Utils" line, the test works. 
Otherwise it fails to notice that 0 is less than 0.5.

Alternatively, the test fails if I replace that "use" line with
BEGIN {
    use POSIX qw(locale_h);
    setlocale(LC_NUMERIC, "");
}

"BEGIN" part is essential: mere use/setlocale is fine.

Also, adding
use locale;
or even
use locale ':numeric';
fixes the test, but I doubt whether it's a good idea to add that to 
Utils.pm.

Obviously, one of the reasons is that according to ru_RU.UTF-8 locale 
for LC_NUMERIC, fractional part separator is ",", not ".". So one could, 
technically, parse "0.5" as "0" and then unparsed ".5" tail. I think it 
might even be a Perl bug, because, according to my quick browsing of man 
perlfunc (setlocale) and man perllocale, this should not affect the code 
outside "use locale", not in such a fundamental way. After all, we're 
talking not about strtod etc, but about floating-point numbers in the 
source code.

P.S. $ perl --version

This is perl 5, version 38, subversion 2 (v5.38.2) built for 
x86_64-linux-gnu-thread-multi
(with 44 registered patches, see perl -V for more detail)

P.P.S. I'm replying to pgsql-hackers, even though part of previous 
discussion have been on pgsql-committers. Hopefully, it's OK.

-- 
Anton Voloshin
Postgres Professional, The Russian Postgres Company
https://postgrespro.ru
Attachment

pgsql-hackers by date:

Previous
From: Jacob Champion
Date:
Subject: Re: Direct SSL connection with ALPN and HBA rules
Next
From: Robert Haas
Date:
Subject: Re: New GUC autovacuum_max_threshold ?