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
From 6d1719de49b1c690e1fb7aeed8fc760f053a2a31 Mon Sep 17 00:00:00 2001
From: Anton Voloshin <a.volos...@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.pl
new file mode 100644
index 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 via email to