diff --git a/config/perl.m4 b/config/perl.m4 index bed2eae57f..9706c4de6a 100644 --- a/config/perl.m4 +++ b/config/perl.m4 @@ -49,6 +49,31 @@ AC_DEFUN([PGAC_CHECK_PERL_CONFIGS], [m4_foreach([pgac_item], [$1], [PGAC_CHECK_PERL_CONFIG(pgac_item)])]) +# PGAC_CHECK_PERL_EMBED_CCFLAGS +# ----------------------------- +# We selectively extract stuff from $Config{ccflags}. We don't really need +# anything except -D switches, and other sorts of compiler switches can +# actively break things if Perl was compiled with a different compiler. +# Moreover, although Perl likes to put stuff like -D_LARGEFILE_SOURCE and +# -D_FILE_OFFSET_BITS=64 here, it would be fatal to try to compile PL/Perl +# to a different libc ABI than core Postgres uses. The available information +# says that all the symbols that affect Perl's own ABI begin with letters, +# so it should be sufficient to adopt -D switches for symbols not beginning +# with underscore. +# For debugging purposes, let's have the configure output report the raw +# ccflags value as well as the set of flags we chose to adopt. +AC_DEFUN([PGAC_CHECK_PERL_EMBED_CCFLAGS], +[AC_REQUIRE([PGAC_PATH_PERL]) +AC_MSG_CHECKING([for CFLAGS recommended by Perl]) +perl_ccflags=`$PERL -MConfig -e ['print $Config{ccflags}']` +AC_MSG_RESULT([$perl_ccflags]) +AC_MSG_CHECKING([for CFLAGS to compile embedded Perl]) +perl_embed_ccflags=`$PERL -MConfig -e ['foreach $f (split(" ",$Config{ccflags})) {print $f, " " if ($f =~ /^-D[^_]/)}']` +AC_SUBST(perl_embed_ccflags)dnl +AC_MSG_RESULT([$perl_embed_ccflags]) +])# PGAC_CHECK_PERL_EMBED_CCFLAGS + + # PGAC_CHECK_PERL_EMBED_LDFLAGS # ----------------------------- # We are after Embed's ldopts, but without the subset mentioned in diff --git a/configure b/configure index 50461e2faa..190027bafb 100755 --- a/configure +++ b/configure @@ -670,6 +670,7 @@ python_version python_majorversion PYTHON perl_embed_ldflags +perl_embed_ccflags perl_useshrplib perl_privlibexp perl_archlibexp @@ -7511,6 +7512,18 @@ documentation for details. Use --without-perl to disable building PL/Perl." "$LINENO" 5 fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFLAGS recommended by Perl" >&5 +$as_echo_n "checking for CFLAGS recommended by Perl... " >&6; } +perl_ccflags=`$PERL -MConfig -e 'print $Config{ccflags}'` +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $perl_ccflags" >&5 +$as_echo "$perl_ccflags" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFLAGS to compile embedded Perl" >&5 +$as_echo_n "checking for CFLAGS to compile embedded Perl... " >&6; } +perl_embed_ccflags=`$PERL -MConfig -e 'foreach $f (split(" ",$Config{ccflags})) {print $f, " " if ($f =~ /^-D[^_]/)}'` +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $perl_embed_ccflags" >&5 +$as_echo "$perl_embed_ccflags" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for flags to link embedded Perl" >&5 $as_echo_n "checking for flags to link embedded Perl... " >&6; } if test "$PORTNAME" = "win32" ; then diff --git a/configure.in b/configure.in index 35f3a7d0c7..53c9674780 100644 --- a/configure.in +++ b/configure.in @@ -928,6 +928,7 @@ You might have to rebuild your Perl installation. Refer to the documentation for details. Use --without-perl to disable building PL/Perl.]) fi + PGAC_CHECK_PERL_EMBED_CCFLAGS PGAC_CHECK_PERL_EMBED_LDFLAGS fi diff --git a/contrib/hstore_plperl/Makefile b/contrib/hstore_plperl/Makefile index b3b8654bc8..8fdca04bfb 100644 --- a/contrib/hstore_plperl/Makefile +++ b/contrib/hstore_plperl/Makefile @@ -43,4 +43,4 @@ endif # last, probably because it sometimes contains some header files with names # that clash with some of ours, or with some that we include, notably on # Windows. -override CPPFLAGS := $(CPPFLAGS) -I$(perl_archlibexp)/CORE +override CPPFLAGS := $(CPPFLAGS) $(perl_embed_ccflags) -I$(perl_archlibexp)/CORE diff --git a/src/Makefile.global.in b/src/Makefile.global.in index 8ac7ca7d2b..cb939b5855 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -298,6 +298,7 @@ else endif perl_archlibexp = @perl_archlibexp@ perl_privlibexp = @perl_privlibexp@ +perl_embed_ccflags = @perl_embed_ccflags@ perl_embed_ldflags = @perl_embed_ldflags@ # Miscellaneous diff --git a/src/pl/plperl/GNUmakefile b/src/pl/plperl/GNUmakefile index b8e3585254..191f74067a 100644 --- a/src/pl/plperl/GNUmakefile +++ b/src/pl/plperl/GNUmakefile @@ -12,7 +12,11 @@ override CPPFLAGS += -DPLPERL_HAVE_UID_GID override CPPFLAGS += -Wno-comment endif -override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS) -I$(perl_archlibexp)/CORE +# Note: we need to make sure that the CORE directory is included last, +# probably because it sometimes contains some header files with names +# that clash with some of ours, or with some that we include, notably on +# Windows. +override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS) $(perl_embed_ccflags) -I$(perl_archlibexp)/CORE rpathdir = $(perl_archlibexp)/CORE diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index e58c85c7b4..f4180117a5 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -3248,12 +3248,18 @@ plperl_return_next_internal(SV *sv) /* * This is the first call to return_next in the current PL/Perl - * function call, so memoize some lookups + * function call, so identify the output tuple descriptor and create a + * tuplestore to hold the result rows. */ if (prodesc->fn_retistuple) (void) get_call_result_type(fcinfo, NULL, &tupdesc); else + { tupdesc = rsi->expectedDesc; + /* Protect assumption below that we return exactly one column */ + if (tupdesc == NULL || tupdesc->natts != 1) + elog(ERROR, "expected single-column result descriptor for non-composite SETOF result"); + } /* * Make sure the tuple_store and ret_tdesc are sufficiently @@ -3301,20 +3307,20 @@ plperl_return_next_internal(SV *sv) } else { - Datum ret; - bool isNull; + Datum ret[1]; + bool isNull[1]; - ret = plperl_sv_to_datum(sv, - prodesc->result_oid, - -1, - fcinfo, - &prodesc->result_in_func, - prodesc->result_typioparam, - &isNull); + ret[0] = plperl_sv_to_datum(sv, + prodesc->result_oid, + -1, + fcinfo, + &prodesc->result_in_func, + prodesc->result_typioparam, + &isNull[0]); tuplestore_putvalues(current_call_data->tuple_store, current_call_data->ret_tdesc, - &ret, &isNull); + ret, isNull); } MemoryContextSwitchTo(old_cxt); diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 6285aab2b6..f3bd30540a 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -516,7 +516,26 @@ sub mkvcbuild my $plperl = $solution->AddProject('plperl', 'dll', 'PLs', 'src/pl/plperl'); $plperl->AddIncludeDir($solution->{options}->{perl} . '/lib/CORE'); - $plperl->AddDefine('PLPERL_HAVE_UID_GID'); + + # Add defines from Perl's ccflags; see PGAC_CHECK_PERL_EMBED_CCFLAGS + my @perl_embed_ccflags; + foreach my $f (split(" ",$Config{ccflags})) + { + if ($f =~ /^-D[^_]/) + { + $f =~ s/\-D//; + push(@perl_embed_ccflags, $f); + } + } + + # XXX this probably is redundant now? + push(@perl_embed_ccflags, 'PLPERL_HAVE_UID_GID'); + + foreach my $f (@perl_embed_ccflags) + { + $plperl->AddDefine($f); + } + foreach my $xs ('SPI.xs', 'Util.xs') { (my $xsc = $xs) =~ s/\.xs/.c/; @@ -599,7 +618,11 @@ sub mkvcbuild 'hstore_plperl', 'contrib/hstore_plperl', 'plperl', 'src/pl/plperl', 'hstore', 'contrib/hstore'); - $hstore_plperl->AddDefine('PLPERL_HAVE_UID_GID'); + + foreach my $f (@perl_embed_ccflags) + { + $hstore_plperl->AddDefine($f); + } } $mf =