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.
This commit is contained in:
Andrew Dunstan 2011-02-01 09:43:25 -05:00
parent 5273f21434
commit ef19dc6d39

View File

@ -1422,7 +1422,7 @@ plperl_create_sub(plperl_proc_desc *prodesc, char *s, Oid fn_oid)
EXTEND(SP, 4); EXTEND(SP, 4);
PUSHs(sv_2mortal(newSVstring(subname))); PUSHs(sv_2mortal(newSVstring(subname)));
PUSHs(sv_2mortal(newRV_noinc((SV *) pragma_hv))); 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))); PUSHs(sv_2mortal(newSVstring(s)));
PUTBACK; PUTBACK;
@ -1494,9 +1494,7 @@ plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo)
SAVETMPS; SAVETMPS;
PUSHMARK(SP); PUSHMARK(SP);
EXTEND(sp, 1 + desc->nargs); EXTEND(sp, desc->nargs);
PUSHs(&PL_sv_undef); /* no trigger data */
for (i = 0; i < desc->nargs; i++) for (i = 0; i < desc->nargs; i++)
{ {
@ -1576,21 +1574,22 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo,
SV *td) SV *td)
{ {
dSP; dSP;
SV *retval; SV *retval, *TDsv;
Trigger *tg_trigger; int i, count;
int i; Trigger *tg_trigger = ((TriggerData *) fcinfo->context)->tg_trigger;
int count;
ENTER; ENTER;
SAVETMPS; SAVETMPS;
TDsv = get_sv("_TD", GV_ADD);
SAVESPTR(TDsv); /* local $_TD */
sv_setsv(TDsv, td);
PUSHMARK(sp); PUSHMARK(sp);
EXTEND(sp, tg_trigger->tgnargs);
XPUSHs(td);
tg_trigger = ((TriggerData *) fcinfo->context)->tg_trigger;
for (i = 0; i < tg_trigger->tgnargs; i++) 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; PUTBACK;
/* Do NOT use G_KEEPERR here */ /* Do NOT use G_KEEPERR here */