Skip to content

Commit 1c1f2f5

Browse files
committed
Remove ill-considered suppression of gcc warnings in plperl, and fix
some of the bugs exposed thereby. The remaining 'might be used uninitialized' warnings look like live bugs, but I am not familiar enough with Perl/C hacking to tell how to fix them.
1 parent edcaa8f commit 1c1f2f5

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

src/pl/plperl/GNUmakefile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Makefile for PL/Perl
2-
# $PostgreSQL: pgsql/src/pl/plperl/GNUmakefile,v 1.16 2004/10/07 19:01:09 momjian Exp $
2+
# $PostgreSQL: pgsql/src/pl/plperl/GNUmakefile,v 1.17 2004/11/17 21:23:36 tgl Exp $
33

44
subdir = src/pl/plperl
55
top_builddir = ../../..
@@ -16,11 +16,6 @@ endif
1616
# to work without, we have to skip it.
1717
ifneq (,$(findstring yes, $(shared_libperl)$(allow_nonpic_in_shlib)))
1818

19-
# The code isn't clean with regard to these warnings.
20-
ifeq ($(GCC),yes)
21-
override CFLAGS := $(filter-out -Wall -Wmissing-declarations -Wmissing-prototypes, $(CFLAGS))
22-
endif
23-
2419
ifeq ($(PORTNAME), win32)
2520
perl_archlibexp := $(subst \,/,$(perl_archlibexp))
2621
perl_privlibexp := $(subst \,/,$(perl_privlibexp))

src/pl/plperl/plperl.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* ENHANCEMENTS, OR MODIFICATIONS.
3434
*
3535
* IDENTIFICATION
36-
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.56 2004/11/16 22:05:22 tgl Exp $
36+
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.57 2004/11/17 21:23:36 tgl Exp $
3737
*
3838
**********************************************************************/
3939

@@ -116,6 +116,8 @@ static void plperl_init_interp(void);
116116
Datum plperl_call_handler(PG_FUNCTION_ARGS);
117117
void plperl_init(void);
118118

119+
HV *plperl_spi_exec(char *query, int limit);
120+
119121
static Datum plperl_func_handler(PG_FUNCTION_ARGS);
120122

121123
static Datum plperl_trigger_handler(PG_FUNCTION_ARGS);
@@ -685,7 +687,7 @@ plperl_create_sub(char *s, bool trusted)
685687

686688
if (SvTRUE(ERRSV))
687689
{
688-
POPs;
690+
(void) POPs;
689691
PUTBACK;
690692
FREETMPS;
691693
LEAVE;
@@ -821,7 +823,7 @@ plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo)
821823

822824
if (SvTRUE(ERRSV))
823825
{
824-
POPs;
826+
(void) POPs;
825827
PUTBACK;
826828
FREETMPS;
827829
LEAVE;
@@ -872,7 +874,7 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, S
872874

873875
if (SvTRUE(ERRSV))
874876
{
875-
POPs;
877+
(void) POPs;
876878
PUTBACK;
877879
FREETMPS;
878880
LEAVE;
@@ -935,7 +937,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
935937
if (!(perlret && SvOK(perlret) && SvTYPE(perlret) != SVt_NULL))
936938
{
937939
/* return NULL if Perl code returned undef */
938-
retval = (Datum) 0;
939940
fcinfo->isnull = true;
940941
}
941942

@@ -945,29 +946,25 @@ plperl_func_handler(PG_FUNCTION_ARGS)
945946
if (prodesc->fn_retistuple && perlret && SvTYPE(perlret) != SVt_RV)
946947
elog(ERROR, "plperl: composite-returning function must return a reference");
947948

949+
if (prodesc->fn_retisset && !fcinfo->resultinfo)
950+
ereport(ERROR,
951+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
952+
errmsg("set-valued function called in context that cannot accept a set")));
953+
948954
if (prodesc->fn_retistuple && fcinfo->resultinfo) /* set of tuples */
949955
{
950956
/* SRF support */
951957
HV *ret_hv;
952958
AV *ret_av;
953-
954959
FuncCallContext *funcctx;
955960
int call_cntr;
956961
int max_calls;
957962
TupleDesc tupdesc;
958-
TupleTableSlot *slot;
959963
AttInMetadata *attinmeta;
960-
bool isset = 0;
964+
bool isset;
961965
char **values = NULL;
962966
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
963967

964-
if (prodesc->fn_retisset && !rsinfo)
965-
ereport(ERROR,
966-
(errcode(ERRCODE_SYNTAX_ERROR),
967-
errmsg("returning a composite type is not allowed in this context"),
968-
errhint("This function is intended for use in the FROM clause.")));
969-
970-
971968
isset = plperl_is_set(perlret);
972969

973970
if (SvTYPE(SvRV(perlret)) == SVt_PVHV)
@@ -1007,8 +1004,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
10071004
av_store(g_column_keys, i + 1,
10081005
newSVpv(SPI_fname(tupdesc, i+1), 0));
10091006

1010-
slot = TupleDescGetSlot(tupdesc);
1011-
funcctx->slot = slot;
10121007
attinmeta = TupleDescGetAttInMetadata(tupdesc);
10131008
funcctx->attinmeta = attinmeta;
10141009
MemoryContextSwitchTo(oldcontext);
@@ -1017,8 +1012,8 @@ plperl_func_handler(PG_FUNCTION_ARGS)
10171012
funcctx = SRF_PERCALL_SETUP();
10181013
call_cntr = funcctx->call_cntr;
10191014
max_calls = funcctx->max_calls;
1020-
slot = funcctx->slot;
10211015
attinmeta = funcctx->attinmeta;
1016+
tupdesc = attinmeta->tupdesc;
10221017

10231018
if (call_cntr < max_calls)
10241019
{
@@ -1065,7 +1060,7 @@ plperl_func_handler(PG_FUNCTION_ARGS)
10651060
}
10661061
}
10671062
tuple = BuildTupleFromCStrings(attinmeta, values);
1068-
result = TupleGetDatum(slot, tuple);
1063+
result = HeapTupleGetDatum(tuple);
10691064
SRF_RETURN_NEXT(funcctx, result);
10701065
}
10711066
else
@@ -1100,17 +1095,19 @@ plperl_func_handler(PG_FUNCTION_ARGS)
11001095
svp = av_fetch(array, funcctx->call_cntr, FALSE);
11011096

11021097
if (SvTYPE(*svp) != SVt_NULL)
1098+
{
1099+
fcinfo->isnull = false;
11031100
result = FunctionCall3(&prodesc->result_in_func,
11041101
PointerGetDatum(SvPV(*svp, PL_na)),
11051102
ObjectIdGetDatum(prodesc->result_typioparam),
11061103
Int32GetDatum(-1));
1104+
}
11071105
else
11081106
{
11091107
fcinfo->isnull = true;
11101108
result = (Datum) 0;
11111109
}
11121110
SRF_RETURN_NEXT(funcctx, result);
1113-
fcinfo->isnull = false;
11141111
}
11151112
else
11161113
{
@@ -1121,8 +1118,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
11211118
}
11221119
else if (!fcinfo->isnull) /* non-null singleton */
11231120
{
1124-
1125-
11261121
if (prodesc->fn_retistuple) /* singleton perl hash to Datum */
11271122
{
11281123
TupleDesc td = lookup_rowtype_tupdesc(prodesc->ret_oid, (int32) -1);
@@ -1153,16 +1148,16 @@ plperl_func_handler(PG_FUNCTION_ARGS)
11531148
attinmeta = TupleDescGetAttInMetadata(td);
11541149
tup = BuildTupleFromCStrings(attinmeta, values);
11551150
retval = HeapTupleGetDatum(tup);
1156-
11571151
}
11581152
else
11591153
/* perl string to Datum */
11601154
retval = FunctionCall3(&prodesc->result_in_func,
11611155
PointerGetDatum(SvPV(perlret, PL_na)),
11621156
ObjectIdGetDatum(prodesc->result_typioparam),
11631157
Int32GetDatum(-1));
1164-
11651158
}
1159+
else /* null singleton */
1160+
retval = (Datum) 0;
11661161

11671162
SvREFCNT_dec(perlret);
11681163
return retval;
@@ -1220,6 +1215,8 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
12201215
retval = (Datum) trigdata->tg_newtuple;
12211216
else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
12221217
retval = (Datum) trigdata->tg_trigtuple;
1218+
else
1219+
retval = (Datum) 0; /* can this happen? */
12231220
}
12241221
else
12251222
{
@@ -1256,6 +1253,8 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
12561253
}
12571254
retval = PointerGetDatum(trv);
12581255
}
1256+
else
1257+
retval = (Datum) 0;
12591258
}
12601259

12611260
SvREFCNT_dec(perlret);

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