aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-06-28 17:50:12 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-06-28 17:50:12 +0000
commit973e33dae72e701d0e1bb9ba1be32c500a130603 (patch)
tree7673208604b26c6918992427aa58c7ef5505893a
parentee9796e44809ec11316f9271ee2e5d604f7d1319 (diff)
downloadpostgresql-973e33dae72e701d0e1bb9ba1be32c500a130603.tar.gz
postgresql-973e33dae72e701d0e1bb9ba1be32c500a130603.zip
Fix incorrect tests for undef Perl values in some places in plperl.c.
The correct test for defined-ness is SvOK(sv), not anything involving SvTYPE. Per bug #3415 from Matt Taylor. Back-patch as far as 8.0; no apparent problem in 7.x.
-rw-r--r--src/pl/plperl/plperl.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index e0bbe8fbabf..b8e4d9e1790 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -1,7 +1,7 @@
/**********************************************************************
* plperl.c - perl as a procedural language for PostgreSQL
*
- * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.123 2006/11/21 16:59:02 adunstan Exp $
+ * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.123.2.1 2007/06/28 17:50:12 tgl Exp $
*
**********************************************************************/
@@ -549,7 +549,7 @@ plperl_build_tuple_result(HV *perlhash, AttInMetadata *attinmeta)
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("Perl hash contains nonexistent column \"%s\"",
key)));
- if (SvOK(val) && SvTYPE(val) != SVt_NULL)
+ if (SvOK(val))
values[attn - 1] = SvPV(val, PL_na);
}
hv_iterinit(perlhash);
@@ -745,7 +745,7 @@ plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup)
&typinput, &typioparam);
fmgr_info(typinput, &finfo);
atttypmod = tupdesc->attrs[attn - 1]->atttypmod;
- if (SvOK(val) && SvTYPE(val) != SVt_NULL)
+ if (SvOK(val))
{
modvalues[slotsused] = InputFunctionCall(&finfo,
SvPV(val, PL_na),
@@ -1199,9 +1199,10 @@ plperl_func_handler(PG_FUNCTION_ARGS)
* If the Perl function returned an arrayref, we pretend that it
* called return_next() for each element of the array, to handle old
* SRFs that didn't know about return_next(). Any other sort of return
- * value is an error.
+ * value is an error, except undef which means return an empty set.
*/
- if (SvTYPE(perlret) == SVt_RV &&
+ if (SvOK(perlret) &&
+ SvTYPE(perlret) == SVt_RV &&
SvTYPE(SvRV(perlret)) == SVt_PVAV)
{
int i = 0;
@@ -1214,7 +1215,7 @@ plperl_func_handler(PG_FUNCTION_ARGS)
i++;
}
}
- else if (SvTYPE(perlret) != SVt_NULL)
+ else if (SvOK(perlret))
{
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
@@ -1230,7 +1231,7 @@ plperl_func_handler(PG_FUNCTION_ARGS)
}
retval = (Datum) 0;
}
- else if (SvTYPE(perlret) == SVt_NULL)
+ else if (!SvOK(perlret))
{
/* Return NULL if Perl code returned undef */
if (rsi && IsA(rsi, ReturnSetInfo))
@@ -1337,7 +1338,7 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "SPI_finish() failed");
- if (!(perlret && SvOK(perlret) && SvTYPE(perlret) != SVt_NULL))
+ if (perlret == NULL || !SvOK(perlret))
{
/* undef result means go ahead with original tuple */
TriggerData *trigdata = ((TriggerData *) fcinfo->context);
@@ -1902,7 +1903,7 @@ plperl_return_next(SV *sv)
Datum ret;
bool isNull;
- if (SvOK(sv) && SvTYPE(sv) != SVt_NULL)
+ if (SvOK(sv))
{
char *val = SvPV(sv, PL_na);
@@ -2295,7 +2296,7 @@ plperl_spi_exec_prepared(char *query, HV *attr, int argc, SV **argv)
for (i = 0; i < argc; i++)
{
- if (SvTYPE(argv[i]) != SVt_NULL)
+ if (SvOK(argv[i]))
{
argvalues[i] = InputFunctionCall(&qdesc->arginfuncs[i],
SvPV(argv[i], PL_na),
@@ -2426,7 +2427,7 @@ plperl_spi_query_prepared(char *query, int argc, SV **argv)
for (i = 0; i < argc; i++)
{
- if (SvTYPE(argv[i]) != SVt_NULL)
+ if (SvOK(argv[i]))
{
argvalues[i] = InputFunctionCall(&qdesc->arginfuncs[i],
SvPV(argv[i], PL_na),