Skip to content

Commit 1e58c50

Browse files
committed
PL/Perl portability fix: absorb relevant -D switches from Perl.
Back-patch of commit 3c163a7, which see for more info. Also throw in commit b4cc35f, so Coverity doesn't whine about the back branches. Ashutosh Sharma, some adjustments by me Discussion: https://postgr.es/m/CANFyU97OVQ3+Mzfmt3MhuUm5NwPU=-FtbNH5Eb7nZL9ua8=rcA@mail.gmail.com
1 parent 30a5c8b commit 1e58c50

File tree

8 files changed

+88
-15
lines changed

8 files changed

+88
-15
lines changed

config/perl.m4

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,31 @@ AC_DEFUN([PGAC_CHECK_PERL_CONFIGS],
4949
[m4_foreach([pgac_item], [$1], [PGAC_CHECK_PERL_CONFIG(pgac_item)])])
5050

5151

52+
# PGAC_CHECK_PERL_EMBED_CCFLAGS
53+
# -----------------------------
54+
# We selectively extract stuff from $Config{ccflags}. We don't really need
55+
# anything except -D switches, and other sorts of compiler switches can
56+
# actively break things if Perl was compiled with a different compiler.
57+
# Moreover, although Perl likes to put stuff like -D_LARGEFILE_SOURCE and
58+
# -D_FILE_OFFSET_BITS=64 here, it would be fatal to try to compile PL/Perl
59+
# to a different libc ABI than core Postgres uses. The available information
60+
# says that all the symbols that affect Perl's own ABI begin with letters,
61+
# so it should be sufficient to adopt -D switches for symbols not beginning
62+
# with underscore.
63+
# For debugging purposes, let's have the configure output report the raw
64+
# ccflags value as well as the set of flags we chose to adopt.
65+
AC_DEFUN([PGAC_CHECK_PERL_EMBED_CCFLAGS],
66+
[AC_REQUIRE([PGAC_PATH_PERL])
67+
AC_MSG_CHECKING([for CFLAGS recommended by Perl])
68+
perl_ccflags=`$PERL -MConfig -e ['print $Config{ccflags}']`
69+
AC_MSG_RESULT([$perl_ccflags])
70+
AC_MSG_CHECKING([for CFLAGS to compile embedded Perl])
71+
perl_embed_ccflags=`$PERL -MConfig -e ['foreach $f (split(" ",$Config{ccflags})) {print $f, " " if ($f =~ /^-D[^_]/)}']`
72+
AC_SUBST(perl_embed_ccflags)dnl
73+
AC_MSG_RESULT([$perl_embed_ccflags])
74+
])# PGAC_CHECK_PERL_EMBED_CCFLAGS
75+
76+
5277
# PGAC_CHECK_PERL_EMBED_LDFLAGS
5378
# -----------------------------
5479
# We are after Embed's ldopts, but without the subset mentioned in

configure

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ python_version
670670
python_majorversion
671671
PYTHON
672672
perl_embed_ldflags
673+
perl_embed_ccflags
673674
perl_useshrplib
674675
perl_privlibexp
675676
perl_archlibexp
@@ -7511,6 +7512,18 @@ documentation for details. Use --without-perl to disable building
75117512
PL/Perl." "$LINENO" 5
75127513
fi
75137514

7515+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFLAGS recommended by Perl" >&5
7516+
$as_echo_n "checking for CFLAGS recommended by Perl... " >&6; }
7517+
perl_ccflags=`$PERL -MConfig -e 'print $Config{ccflags}'`
7518+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $perl_ccflags" >&5
7519+
$as_echo "$perl_ccflags" >&6; }
7520+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFLAGS to compile embedded Perl" >&5
7521+
$as_echo_n "checking for CFLAGS to compile embedded Perl... " >&6; }
7522+
perl_embed_ccflags=`$PERL -MConfig -e 'foreach $f (split(" ",$Config{ccflags})) {print $f, " " if ($f =~ /^-D[^_]/)}'`
7523+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $perl_embed_ccflags" >&5
7524+
$as_echo "$perl_embed_ccflags" >&6; }
7525+
7526+
75147527
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for flags to link embedded Perl" >&5
75157528
$as_echo_n "checking for flags to link embedded Perl... " >&6; }
75167529
if test "$PORTNAME" = "win32" ; then

configure.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@ You might have to rebuild your Perl installation. Refer to the
928928
documentation for details. Use --without-perl to disable building
929929
PL/Perl.])
930930
fi
931+
PGAC_CHECK_PERL_EMBED_CCFLAGS
931932
PGAC_CHECK_PERL_EMBED_LDFLAGS
932933
fi
933934

contrib/hstore_plperl/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ endif
4343
# last, probably because it sometimes contains some header files with names
4444
# that clash with some of ours, or with some that we include, notably on
4545
# Windows.
46-
override CPPFLAGS := $(CPPFLAGS) -I$(perl_archlibexp)/CORE
46+
override CPPFLAGS := $(CPPFLAGS) $(perl_embed_ccflags) -I$(perl_archlibexp)/CORE

src/Makefile.global.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ else
298298
endif
299299
perl_archlibexp = @perl_archlibexp@
300300
perl_privlibexp = @perl_privlibexp@
301+
perl_embed_ccflags = @perl_embed_ccflags@
301302
perl_embed_ldflags = @perl_embed_ldflags@
302303

303304
# Miscellaneous

src/pl/plperl/GNUmakefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ override CPPFLAGS += -DPLPERL_HAVE_UID_GID
1212
override CPPFLAGS += -Wno-comment
1313
endif
1414

15-
override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS) -I$(perl_archlibexp)/CORE
15+
# Note: we need to make sure that the CORE directory is included last,
16+
# probably because it sometimes contains some header files with names
17+
# that clash with some of ours, or with some that we include, notably on
18+
# Windows.
19+
override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS) $(perl_embed_ccflags) -I$(perl_archlibexp)/CORE
1620

1721
rpathdir = $(perl_archlibexp)/CORE
1822

src/pl/plperl/plperl.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3248,12 +3248,18 @@ plperl_return_next_internal(SV *sv)
32483248

32493249
/*
32503250
* This is the first call to return_next in the current PL/Perl
3251-
* function call, so memoize some lookups
3251+
* function call, so identify the output tuple descriptor and create a
3252+
* tuplestore to hold the result rows.
32523253
*/
32533254
if (prodesc->fn_retistuple)
32543255
(void) get_call_result_type(fcinfo, NULL, &tupdesc);
32553256
else
3257+
{
32563258
tupdesc = rsi->expectedDesc;
3259+
/* Protect assumption below that we return exactly one column */
3260+
if (tupdesc == NULL || tupdesc->natts != 1)
3261+
elog(ERROR, "expected single-column result descriptor for non-composite SETOF result");
3262+
}
32573263

32583264
/*
32593265
* Make sure the tuple_store and ret_tdesc are sufficiently
@@ -3301,20 +3307,20 @@ plperl_return_next_internal(SV *sv)
33013307
}
33023308
else
33033309
{
3304-
Datum ret;
3305-
bool isNull;
3310+
Datum ret[1];
3311+
bool isNull[1];
33063312

3307-
ret = plperl_sv_to_datum(sv,
3308-
prodesc->result_oid,
3309-
-1,
3310-
fcinfo,
3311-
&prodesc->result_in_func,
3312-
prodesc->result_typioparam,
3313-
&isNull);
3313+
ret[0] = plperl_sv_to_datum(sv,
3314+
prodesc->result_oid,
3315+
-1,
3316+
fcinfo,
3317+
&prodesc->result_in_func,
3318+
prodesc->result_typioparam,
3319+
&isNull[0]);
33143320

33153321
tuplestore_putvalues(current_call_data->tuple_store,
33163322
current_call_data->ret_tdesc,
3317-
&ret, &isNull);
3323+
ret, isNull);
33183324
}
33193325

33203326
MemoryContextSwitchTo(old_cxt);

src/tools/msvc/Mkvcbuild.pm

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,26 @@ sub mkvcbuild
516516
my $plperl =
517517
$solution->AddProject('plperl', 'dll', 'PLs', 'src/pl/plperl');
518518
$plperl->AddIncludeDir($solution->{options}->{perl} . '/lib/CORE');
519-
$plperl->AddDefine('PLPERL_HAVE_UID_GID');
519+
520+
# Add defines from Perl's ccflags; see PGAC_CHECK_PERL_EMBED_CCFLAGS
521+
my @perl_embed_ccflags;
522+
foreach my $f (split(" ",$Config{ccflags}))
523+
{
524+
if ($f =~ /^-D[^_]/)
525+
{
526+
$f =~ s/\-D//;
527+
push(@perl_embed_ccflags, $f);
528+
}
529+
}
530+
531+
# XXX this probably is redundant now?
532+
push(@perl_embed_ccflags, 'PLPERL_HAVE_UID_GID');
533+
534+
foreach my $f (@perl_embed_ccflags)
535+
{
536+
$plperl->AddDefine($f);
537+
}
538+
520539
foreach my $xs ('SPI.xs', 'Util.xs')
521540
{
522541
(my $xsc = $xs) =~ s/\.xs/.c/;
@@ -599,7 +618,11 @@ sub mkvcbuild
599618
'hstore_plperl', 'contrib/hstore_plperl',
600619
'plperl', 'src/pl/plperl',
601620
'hstore', 'contrib/hstore');
602-
$hstore_plperl->AddDefine('PLPERL_HAVE_UID_GID');
621+
622+
foreach my $f (@perl_embed_ccflags)
623+
{
624+
$hstore_plperl->AddDefine($f);
625+
}
603626
}
604627

605628
$mf =

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy