Thread: BUG #5571: global hash %_SHARED is not declared as global in the new version
The following bug has been logged online: Bug reference: 5571 Logged by: mile Email address: mile@avangardsolutions.com PostgreSQL version: v9.0beta3 Operating system: Linux Description: global hash %_SHARED is not declared as global in the new version Details: We are using strict pragma that's why we are geting the following error: ERROR: Global symbol %_SHARED requires explicit package name However we should not get that error message because the hash $_SHARED should be declared as global variable. To reproduce this use the following function: create or replace function perl_shared() returns void as $$ use strict; elog(INFO, $_SHARED{'stuff'}); $_SHARED{'stuff'} = '1'; for my $k (keys %_SHARED) { elog(INFO, $k); } $$ language plperl; CREATE LANGUAGE plperl;
Re: BUG #5571: global hash %_SHARED is not declared as global in the new version
From
Alex Hunsaker
Date:
On Mon, Jul 26, 2010 at 03:58, mile <mile@avangardsolutions.com> wrote: > To reproduce this use the following function: > > create or replace function perl_shared() returns void as $$ > use strict; > elog(INFO, $_SHARED{'stuff'}); > $_SHARED{'stuff'} = '1'; > for my $k (keys %_SHARED) > { > elog(INFO, $k); > } > $$ language plperl; Great, Thanks! The below patch fixes it for me. Basically we declared %_SHARED inside the PostgreSQL::InServer; package when it needed to be declared in main::. For the curious 8.4 and down don't have this issue as the "use vars qw(%_SHARED)" is in the PERL_BOOT define, which gets run at the interp start-up time (basically its perl -e PERL_BOOT). *** a/src/pl/plperl/plc_perlboot.pl --- b/src/pl/plperl/plc_perlboot.pl *************** *** 2,7 **** --- 2,8 ---- # $PostgreSQL: pgsql/src/pl/plperl/plc_perlboot.pl,v 1.5 2010/02/16 21:39:52 adunstan Exp $ use 5.008001; + use vars qw(%_SHARED); PostgreSQL::InServer::Util::bootstrap(); *************** *** 9,15 **** package PostgreSQL::InServer; use strict; use warnings; - use vars qw(%_SHARED); sub plperl_warn { (my $msg = shift) =~ s/\(eval \d+\) //g; --- 10,15 ----
Attachment
Re: BUG #5571: global hash %_SHARED is not declared as global in the new version
From
Alvaro Herrera
Date:
Excerpts from Alex Hunsaker's message of lun jul 26 12:55:34 -0400 2010: > On Mon, Jul 26, 2010 at 03:58, mile <mile@avangardsolutions.com> wrote: > > To reproduce this use the following function: > > > > create or replace function perl_shared() returns void as $$ > > use strict; > > elog(INFO, $_SHARED{'stuff'}); > > $_SHARED{'stuff'} = '1'; > > for my $k (keys %_SHARED) > > { > > Â Â elog(INFO, $k); > > } > > $$ language plperl; > > Great, Thanks! The below patch fixes it for me. Thanks, applied to 9.0 and HEAD. I added a simple regression test too.