You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Stas Bekman <st...@stason.org> on 2002/01/11 21:07:28 UTC
the trick of using $SIG{__DIE__} with eval {} disregarding the $^S value
This is an interesting approach to using $SIG{__DIE__} together with
eval {} blocks, without relying on the value of $^S which sometimes goes
broken. I guess we should add this "trick" to the guide.
-------- Original Message --------
Subject: Re: [ID 20020107.001] $^S is sticky
Date: Mon, 7 Jan 2002 15:15:58 -0500
From: Michael G Schwern <sc...@pobox.com>
To: chris@netmonger.net
CC: perl5-porters@perl.org
References: <20...@lion-around.at.yiff.net>
On Mon, Jan 07, 2002 at 02:52:02PM -0500, Christopher Masto wrote:
> Is this supposed to happen?
$^S breaks a lot. I found both 5.6.1 and 5.005_03 to have broken $^S,
though for different reasons. I can't remember why 5.005_03's is
broken. If you peek inside Test::Builder you'll find this:
$SIG{__DIE__} = sub {
# We don't want to muck with death in an eval, but $^S isn't
# totally reliable. 5.005_03 and 5.6.1 both do the wrong thing
# with it. Instead, we use caller. This also means it runs under
# 5.004!
my $in_eval = 0;
for( my $stack = 1; my $sub = (CORE::caller($stack))[3]; $stack++ ) {
$in_eval = 1 if $sub =~ /^\(eval\)/;
}
$Test_Died = 1 unless $in_eval;
};
> chris@lion-around:~$ perl5.00503 -e '$SIG{__DIE__} = sub { die @_ if
$^S; die "caught die: @_"; }; print "start: $^S\n"; eval { die "death in
eval"; }; print "end: $^S\n"; die "death outside eval"'
> start: 0
> end: 0
> caught die: death outside eval at -e line 1.
>
> chris@lion-around:~$ perl5.6.1 -e '$SIG{__DIE__} = sub { die @_ if
$^S; die "caught die: @_"; }; print "start: $^S\n"; eval { die "death in
eval"; }; print "end: $^S\n"; die "death outside eval"'
> start:
> end: 1
> death outside eval at -e line 1.
>
> In 5.6.1, the value of $^S seems to get stuck once it's been set.
> This only happens if the $SIG{__DIE__} handler actually looks at it.
t/op/magic.t appears to be the only thing which tests $^S, and it
doesn't get $SIG{__DIE__} involved.
bleadperl is back to:
start: 0
end: 0
caught die: death outside eval at -e line 1.
if modified a little, it shows its the correct behavior:
$ bleadperl -e '$SIG{__DIE__} = sub { die @_ if $^S; die "caught die:
@_"; }; print "start: $^S\n"; eval { die "death in eval"; }; print $@;
print "end: $^S\n"; die "death outside eval"'
start: 0
death in eval at -e line 1.
end: 0
caught die: death outside eval at -e line 1.
--
Michael G. Schwern <sc...@pobox.com> http://www.pobox.com/~schwern/
Perl Quality Assurance <pe...@perl.org> Kwalitee Is Job One
And God created Cat to be a companion to Adam. And Cat would not obey
Adam. And when Adam gazed into Cat's eyes, he was reminded that he
was not the supreme being. And Adam learned humility.
-- http://www.catsarefrommars.com/creationist.htm
--
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/