From: Anton Voloshin <a.voloshin@postgrespro.ru>
To: Pg Hackers <pgsql-hackers@postgresql.org>
Cc: Alexander Korotkov <aekorotkov@gmail.com>
Cc: Andrew Dunstan <andrew@dunslane.net>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Aleksander Alekseev <aleksander@timescale.com>
Subject: Re: pgsql: psql: add an optional execution-count limit to \watch.
Date: Thu, 25 Apr 2024 21:22:49 +0300
Message-ID: <5ed7d3e2-ca7e-40ad-9de9-e7648576cc01@postgrespro.ru> (raw)
In-Reply-To: <2748103.1681839252@sss.pgh.pa.us>
References: <E1pkTFl-001hzA-LR@gemulon.postgresql.org>
<CAPpHfdv+10Uk6FWjsh3+ju7kHYr76LaRXbYayXmrM7FBU-=Hgg@mail.gmail.com>
<2929174.1680876023@sss.pgh.pa.us>
<CAPpHfdtgQVRZOwov-Ei4Rh=gQtFE8Hb9uKkO1d_XYmQ2XEXt0g@mail.gmail.com>
<CAJ7c6TO9KpYYxoVVseWEQB5KtjWDkt8NfyAeKPcHoe2Jq+ykpw@mail.gmail.com>
<4032363.1681134882@sss.pgh.pa.us>
<CAJ7c6TOFPoHVSxaQXfbm38_QN1v4qaugZW0LBTB-Gkvk2UwBQw@mail.gmail.com>
<4076950.1681139381@sss.pgh.pa.us>
<CAJ7c6TOVFT0bOEunovQAmZJDiLJ7Dds4YSONi4yOS1GYLvNntA@mail.gmail.com>
<2748103.1681839252@sss.pgh.pa.us>
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.ruAttachments:0001-demo-of-weird-Perl-setlocale-effect-on-float-numbers.patch (text/x-patch, 760B) download
From 6d1719de49b1c690e1fb7aeed8fc760f053a2a31 Mon Sep 17 00:00:00 2001
From: Anton Voloshin <a.voloshin@postgrespro.ru>
Date: Thu, 25 Apr 2024 17:23:26 +0000
Subject: [PATCH] demo of weird Perl setlocale effect on float numbers
comparison
---
src/test/authentication/t/999_broken.pl | 8 ++++++++
1 file changed, 8 insertions(+)
create mode 100644 src/test/authentication/t/999_broken.pl
diff --git a/src/test/authentication/t/999_broken.pl b/src/test/authentication/t/999_broken.plnew file mode 100644index 00000000000..e65a272e1cb--- /dev/null+++ b/src/test/authentication/t/999_broken.pl@@ -0,0 +1,8 @@+use strict;+use warnings FATAL => 'all';++use PostgreSQL::Test::Utils;++use Test::More tests => 1;++ok(0 < 0.5, "0 < 0.5");--
2.43.0
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-committers@postgresql.org
Cc: a.voloshin@postgrespro.ru, pgsql-hackers@postgresql.org, aekorotkov@gmail.com, andrew@dunslane.net, tgl@sss.pgh.pa.us, aleksander@timescale.com
Subject: Re: pgsql: psql: add an optional execution-count limit to \watch.
In-Reply-To: <5ed7d3e2-ca7e-40ad-9de9-e7648576cc01@postgrespro.ru>
* 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