From ef19dc6d39dd2490ff61489da55d95d6941140bf Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Tue, 1 Feb 2011 09:43:25 -0500 Subject: [PATCH] Set up PLPerl trigger data using C code instead of Perl code. This is an efficiency change, and means we now no longer have to run "out $_TD; local $_TD = shift;", which was especially pointless in the case of non-trigger functions where the passed value was always undef anyway. A tiny open issue is whether we should get rid of the $prolog argument of mkfunc, and the corresponding pushed value, which is now just a constant "false". Tim Bunce, reviewed by Alex Hunsaker. --- src/pl/plperl/plperl.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index e105603303..ece3931982 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -1422,7 +1422,7 @@ plperl_create_sub(plperl_proc_desc *prodesc, char *s, Oid fn_oid) EXTEND(SP, 4); PUSHs(sv_2mortal(newSVstring(subname))); PUSHs(sv_2mortal(newRV_noinc((SV *) pragma_hv))); - PUSHs(sv_2mortal(newSVstring("our $_TD; local $_TD=shift;"))); + PUSHs(&PL_sv_no); /* XXX is $prolog in mkfunc needed any more? */ PUSHs(sv_2mortal(newSVstring(s))); PUTBACK; @@ -1494,9 +1494,7 @@ plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo) SAVETMPS; PUSHMARK(SP); - EXTEND(sp, 1 + desc->nargs); - - PUSHs(&PL_sv_undef); /* no trigger data */ + EXTEND(sp, desc->nargs); for (i = 0; i < desc->nargs; i++) { @@ -1576,21 +1574,22 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, SV *td) { dSP; - SV *retval; - Trigger *tg_trigger; - int i; - int count; + SV *retval, *TDsv; + int i, count; + Trigger *tg_trigger = ((TriggerData *) fcinfo->context)->tg_trigger; ENTER; SAVETMPS; + TDsv = get_sv("_TD", GV_ADD); + SAVESPTR(TDsv); /* local $_TD */ + sv_setsv(TDsv, td); + PUSHMARK(sp); + EXTEND(sp, tg_trigger->tgnargs); - XPUSHs(td); - - tg_trigger = ((TriggerData *) fcinfo->context)->tg_trigger; for (i = 0; i < tg_trigger->tgnargs; i++) - XPUSHs(sv_2mortal(newSVstring(tg_trigger->tgargs[i]))); + PUSHs(sv_2mortal(newSVstring(tg_trigger->tgargs[i]))); PUTBACK; /* Do NOT use G_KEEPERR here */