On Wed, May 4, 2011 at 16:20, Alex Hunsaker <bada...@gmail.com> wrote:
>
> This seems to be broken by
> http://git.postgresql.org/gitweb?p=postgresql.git;a=commit;h=ef19dc6d39dd2490ff61489da55d95d6941140bf
> (Set up PLPerl trigger data using C code instead of Perl code.)
>
> Im not sure what the right fix is. Copying what
> plperl_call_trigger_func() does for _TD ("get_sv("_TD", GV_ADD); ..."
> into plperl_create_sub() does not seem to work.

Just a small clarification, this only breaks when running under use strict;.

After playing with it a bit more I see 2 clear options:
1) make $_TD global like %_SHARED. This should not cause any problems
as we make $_TD private via local() before each trigger call. Also pre
9.1 non trigger functions could still access and check the definedness
of $_TD so if someone was relying on that (for whatever unknown
reason) that will work again.

2) revert the optimization

#1 is very small and I don't see any downsides (maybe we should local
$_TD before regular perl calls as well??). Find it attached.
*** a/src/pl/plperl/plc_perlboot.pl
--- b/src/pl/plperl/plc_perlboot.pl
***************
*** 1,7 ****
  #  src/pl/plperl/plc_perlboot.pl
  
  use 5.008001;
! use vars qw(%_SHARED);
  
  PostgreSQL::InServer::Util::bootstrap();
  
--- 1,7 ----
  #  src/pl/plperl/plc_perlboot.pl
  
  use 5.008001;
! use vars qw(%_SHARED $_TD);
  
  PostgreSQL::InServer::Util::bootstrap();
  
*** a/src/pl/plperl/plperl.c
--- b/src/pl/plperl/plperl.c
***************
*** 1976,1982 **** plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo,
  	ENTER;
  	SAVETMPS;
  
! 	TDsv = get_sv("_TD", GV_ADD);
  	SAVESPTR(TDsv);				/* local $_TD */
  	sv_setsv(TDsv, td);
  
--- 1976,1985 ----
  	ENTER;
  	SAVETMPS;
  
! 	TDsv = get_sv("_TD", 0);
! 	if (!TDsv)
! 		elog(ERROR, "couldn't fetch $_TD");
! 
  	SAVESPTR(TDsv);				/* local $_TD */
  	sv_setsv(TDsv, td);
  
-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to