On 08/07/2011 07:06 PM, Tim Bunce wrote:

After a little digging and some discussion on the #p5p channel [thanks
to ilmari++ leont++ and sorear++ for their help] it seems that local(%SIG)
doesn't do what you might expect. The %SIG does become empty but the OS
level handlers, even those installed by perl, *aren't changed*:

$ perl -wE '$SIG{INT} = sub { say "Foo"}; { local %SIG; kill "INT", $$; };'
Foo
And, even worse, they're not reset at scope exit:

$ perl -wE '$SIG{INT} = sub { say "Foo"}; { local %SIG; $SIG{INT} = sub {say "Bar" }} 
kill "INT", $$;'
Bar

That sure seems like a bug (I'll check with the perl5-porters list).

Yeah, that seems very bad. :-(

Localizing an individual element of %SIG works fine.
In C that's something like this (untested):

     hv = gv_fetchpv("SIG", 0, SVt_PVHV);
     keysv = ...SV containing "ALRM"...
     he = hv_fetch_ent(hv, keysv, 0, 0);
     if (he) {  /* arrange to restore existing elem */
         save_helem_flags(hv, keysv,&HeVAL(he), SAVEf_SETMAGIC);
     }
     else {     /* arrange to delete a new elem */
         SAVEHDELETE(hv, keysv);
     }



Hmm. I think we'll need to test how much it's going to cost to add that to every plperl (or maybe just every plperlu) function call for the six or so signals we use.

cheers

andrew

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to