Postgresql Windows build and modern perl (>=5.28)
Collegues,
Postgresql embeded perl, plperl contain code long time ago copied
from POSIX.xs file in the perl distribution.
It is function setlocale_perl, which does some allocation of
perl-specific locale data using functions(or macros) new_ctype,
new_collate and new_numeric.
This is used only for WIN32, because as comment in the code said:
/*
* The perl library on startup does horrible things like call
* setlocale(LC_ALL,""). We have protected against that on most platforms
* by setting the environment appropriately. However, on Windows,
* setlocale() does not consult the environment, so we need to save the
* existing locale settings before perl has a chance to mangle them and
* restore them after its dirty deeds are done.
*
* MSDN ref:
* http://msdn.microsoft.com/library/en-us/vclib/html/_crt_locale.asp
*
* It appears that we only need to do this on interpreter startup, and
* subsequent calls to the interpreter don't mess with the locale
* settings.
*
* We restore them using setlocale_perl(), defined below, so that Perl
* doesn't have a different idea of the locale from Postgres.
*
*/
This worked up to perl 5.26. But in perl 5.28 these macros and
corresponding functions became strictly private. However public
function Perl_setlocale appeared in libperl, which from the quick
glance to the code does the same thing as setlocale_perl in plperl code.
Attached patch makes use of this function if PERL_VERSION >= 28.
It makes plperl compile with ActiveStatePerl 5.28 and StrawberryPerl
5.30.2.1.
However, I'm not sure that I've choose correct approach. May be perl
just no more does horrible things with locale at startup?
--
Attachments:
perl.5.30.patchtext/x-patchDownload
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index 2db13d30308..d2787b50beb 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -300,8 +300,12 @@ static OP *pp_require_safe(pTHX);
static void activate_interpreter(plperl_interp_desc *interp_desc);
#ifdef WIN32
+#if PERL_VERSION >= 28
+#define setlocale_perl(a,b) Perl_setlocale(a,b)
+#else
static char *setlocale_perl(int category, char *locale);
#endif
+#endif
/*
* Decrement the refcount of the given SV within the active Perl interpreter
@@ -4159,6 +4163,7 @@ plperl_inline_callback(void *arg)
* (needed because of the calls to new_*())
*/
#ifdef WIN32
+#if PERL_VERSION < 28
static char *
setlocale_perl(int category, char *locale)
{
@@ -4226,5 +4231,6 @@ setlocale_perl(int category, char *locale)
return RETVAL;
}
+#endif /* PERL_VERSION < 28 */
#endif /* WIN32 */
diff --git a/src/pl/plperl/plperl.h b/src/pl/plperl/plperl.h
index 3748158a86d..0044983ed1b 100644
--- a/src/pl/plperl/plperl.h
+++ b/src/pl/plperl/plperl.h
@@ -51,11 +51,11 @@
*/
#ifdef _MSC_VER
#define __inline__ inline
+#define __builtin_expect(a, b) (a == b)
#ifdef isnan
#undef isnan
#endif
#endif
-
/*
* Regarding bool, both PostgreSQL and Perl might use stdbool.h or not,
* depending on configuration. If both agree, things are relatively harmless.
Victor Wagner <vitus@wagner.pp.ru> writes:
Attached patch makes use of this function if PERL_VERSION >= 28.
It makes plperl compile with ActiveStatePerl 5.28 and StrawberryPerl
5.30.2.1.
I have no opinion on the substantive content of this patch, but please
don't just check against just PERL_VERSION. Now that Perl 6 has been
renamed to Raku, Perl may bump its major version (PERL_REVISION) to 7 at
some point in th future.
The correct thing to use is the PERL_VERSION_(GT|GE|LE|LT|EQ|NE) macros,
which are provided by newer versions of perl. We would need to update
the included copy of ppport.h to get them on older perls, but we should
do that anyway, it's not been updated since 2009. I'll start a separate
thread for that.
- ilmari
Hi,
On 2021-10-04 23:08:25 +0100, Dagfinn Ilmari Manns�ker wrote:
Victor Wagner <vitus@wagner.pp.ru> writes:
Attached patch makes use of this function if PERL_VERSION >= 28.
It makes plperl compile with ActiveStatePerl 5.28 and StrawberryPerl
5.30.2.1.I have no opinion on the substantive content of this patch, but please
don't just check against just PERL_VERSION. Now that Perl 6 has been
renamed to Raku, Perl may bump its major version (PERL_REVISION) to 7 at
some point in th future.
How about the attached? I've just spent more time looking at plperl than I
really ever want to, so I'd like to get plperl working and tested on 5.32 on
windows asap... And this is one of the two fixes necessary (see [1]/messages/by-id/20220130221659.tlyr2lbw3wk22owg@alap3.anarazel.de for the
second).
Greetings,
Andres Freund
[1]: /messages/by-id/20220130221659.tlyr2lbw3wk22owg@alap3.anarazel.de
Attachments:
v2-0001-plperl-windows-Use-Perl_setlocale-on-5.28-fixing-.patchtext/x-diff; charset=iso-8859-1Download
From 9397126f9e0ce13975ca00749039bd3f7b5b53fa Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Sun, 30 Jan 2022 14:29:04 -0800
Subject: [PATCH v2 1/4] plperl: windows: Use Perl_setlocale on 5.28+, fixing
compile failure.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
For older versions we need our own copy of perl's setlocale(), because it was
not exposed (why we need the setlocale in the first place is explained in
plperl_init_interp) . The copy stopped working in 5.28, as some of the used
macros are not public anymore. But Perl_setlocale is available in 5.28, so
use that.
Author: Victor Wagner <vitus@wagner.pp.ru>
Reviewed-By: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://postgr.es/m/20200501134711.08750c5f@antares.wagner.home
Backpatch: all versions
---
src/pl/plperl/plperl.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index 1ae8195e023..3f785b1e8d5 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -298,9 +298,11 @@ static char *strip_trailing_ws(const char *msg);
static OP *pp_require_safe(pTHX);
static void activate_interpreter(plperl_interp_desc *interp_desc);
-#ifdef WIN32
+#if defined(WIN32) && PERL_VERSION_LT(5, 28, 0)
static char *setlocale_perl(int category, char *locale);
-#endif
+#else
+#define setlocale_perl(a,b) Perl_setlocale(a,b)
+#endif /* defined(WIN32) && PERL_VERSION_LT(5, 28, 0) */
/*
* Decrement the refcount of the given SV within the active Perl interpreter
@@ -4130,8 +4132,10 @@ plperl_inline_callback(void *arg)
/*
* Perl's own setlocale(), copied from POSIX.xs
* (needed because of the calls to new_*())
+ *
+ * Starting in 5.28, perl exposes Perl_setlocale to do so.
*/
-#ifdef WIN32
+#if defined(WIN32) && PERL_VERSION_LT(5, 28, 0)
static char *
setlocale_perl(int category, char *locale)
{
@@ -4199,5 +4203,4 @@ setlocale_perl(int category, char *locale)
return RETVAL;
}
-
-#endif /* WIN32 */
+#endif /* defined(WIN32) && PERL_VERSION_LT(5, 28, 0) */
--
2.34.0