diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2011-05-18 23:56:18 -0400 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2011-05-18 23:56:18 -0400 |
commit | 6b449d9051651d3accfdce73e21cfd5e3d0e09a3 (patch) | |
tree | 1bed394d1921154258d08a7a4ee263805893f416 /src/pl/plperl/plperl.c | |
parent | ea896da394cbb0fb32a4b41065ea04b81c4b03f6 (diff) | |
download | postgresql-6b449d9051651d3accfdce73e21cfd5e3d0e09a3.tar.gz postgresql-6b449d9051651d3accfdce73e21cfd5e3d0e09a3.zip |
Fix declaration of $_TD in "strict" trigger functions
This was broken in commit ef19dc6d39dd2490ff61489da55d95d6941140bf by
the Bunce/Hunsaker/Dunstan team, which moved the declaration from
plperl_create_sub to plperl_call_perl_trigger_func. This doesn't
actually work because the validator code would not find the variable
declared; and even if you manage to get past the validator, it still
doesn't work because get_sv("_TD", GV_ADD) doesn't have the expected
effect. The only reason this got beyond testing is that it only fails
in strict mode.
We need to declare it as a global just like %_SHARED; it is simpler than
trying to actually do what the patch initially intended, and is said to
have the same performance benefit.
As a more serious issue, fix $_TD not being properly local()ized,
meaning nested trigger functions would clobber $_TD.
Alex Hunsaker, per test report from Greg Mullane
Diffstat (limited to 'src/pl/plperl/plperl.c')
-rw-r--r-- | src/pl/plperl/plperl.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index b5418074aee..d69d2327bb0 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -1976,8 +1976,11 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, ENTER; SAVETMPS; - TDsv = get_sv("_TD", GV_ADD); - SAVESPTR(TDsv); /* local $_TD */ + TDsv = get_sv("_TD", 0); + if (!TDsv) + elog(ERROR, "couldn't fetch $_TD"); + + save_item(TDsv); /* local $_TD */ sv_setsv(TDsv, td); PUSHMARK(sp); |